fix: prefer vim over nano for $EDITOR fallback (CLI + TUI)
prompt_toolkit's default editor list is: $VISUAL, $EDITOR, /usr/bin/editor, /usr/bin/nano, /usr/bin/pico, /usr/bin/vi, /usr/bin/emacs — so when neither env var is set, the base CLI launched nano. The TUI fell back to a literal 'vi'. Same Ctrl+G keystroke, two different editors. Pick the same chain on both surfaces: $VISUAL → $EDITOR → vim → vi → nano CLI: override input_area.buffer._open_file_in_editor on the TextArea once at app build time. Local to that buffer; doesn't touch os.environ or affect other subprocesses. TUI: extract resolveEditor() into ui-tui/src/lib/editor.ts. PATH walk with accessSync(X_OK), no shelling out. Six-line unit test verifies the priority order and the multi-entry PATH walk.
This commit is contained in:
22
cli.py
22
cli.py
@@ -9790,6 +9790,28 @@ class HermesCLI:
|
||||
# complex-tempfile path takes care of cleanup via shutil.rmtree.
|
||||
input_area.buffer.tempfile = 'prompt.md'
|
||||
|
||||
# prompt_toolkit's default fallback chain prefers /usr/bin/nano over
|
||||
# /usr/bin/vi when neither $VISUAL nor $EDITOR is set. The TUI's
|
||||
# resolveEditor() prefers vim → vi → nano. Override this single
|
||||
# buffer's resolver so both surfaces pick the same editor.
|
||||
import shlex
|
||||
import subprocess
|
||||
def _hermes_pick_editor(filename: str) -> bool:
|
||||
chosen = (
|
||||
os.environ.get('VISUAL')
|
||||
or os.environ.get('EDITOR')
|
||||
or shutil.which('vim')
|
||||
or shutil.which('vi')
|
||||
or shutil.which('nano')
|
||||
)
|
||||
if not chosen:
|
||||
return False
|
||||
try:
|
||||
return subprocess.call(shlex.split(chosen) + [filename]) == 0
|
||||
except OSError:
|
||||
return False
|
||||
input_area.buffer._open_file_in_editor = _hermes_pick_editor
|
||||
|
||||
# Dynamic height: accounts for both explicit newlines AND visual
|
||||
# wrapping of long lines so the input area always fits its content.
|
||||
def _input_height():
|
||||
|
||||
Reference in New Issue
Block a user