scripts: enable readline in prompt REPL (read -e)
Supports C-a, C-e, C-u, C-k, M-b, M-f, arrow keys, etc. Sent prompts and slash commands are added to readline history so up-arrow recalls previous inputs.
This commit is contained in:
parent
62cfc06a88
commit
8f09aa2060
|
|
@ -171,16 +171,18 @@ cmd_prompt() {
|
|||
echo "Slash commands: /stop /compact /kill /clear /model /backend /cwd /help"
|
||||
echo ""
|
||||
|
||||
local buf=""
|
||||
local buf="" line
|
||||
while true; do
|
||||
local prompt_str
|
||||
if [[ -z "$buf" ]]; then
|
||||
printf "\033[1m>\033[0m "
|
||||
prompt_str=$'\033[1m>\033[0m '
|
||||
else
|
||||
printf " "
|
||||
prompt_str=" "
|
||||
fi
|
||||
if ! IFS= read -r line; then
|
||||
if ! IFS= read -e -r -p "$prompt_str" line; then
|
||||
# EOF — send remaining buffer if any
|
||||
if [[ -n "$buf" ]]; then
|
||||
history -s "$buf"
|
||||
printf '%s\n' "$buf" | ollie-9p write "$path/prompt"
|
||||
fi
|
||||
printf "\n"
|
||||
|
|
@ -188,6 +190,7 @@ cmd_prompt() {
|
|||
fi
|
||||
# Slash commands (only when buffer is empty — first line)
|
||||
if [[ -z "$buf" && "$line" == /* ]]; then
|
||||
history -s "$line"
|
||||
local cmd="${line#/}"
|
||||
case "$cmd" in
|
||||
stop) echo "stop" | ollie-9p write "$path/ctl"; echo "[stopped]" ;;
|
||||
|
|
@ -212,6 +215,7 @@ cmd_prompt() {
|
|||
fi
|
||||
if [[ -z "$line" && -n "$buf" ]]; then
|
||||
# Blank line sends accumulated buffer
|
||||
history -s "$buf"
|
||||
printf '%s\n' "$buf" | ollie-9p write "$path/prompt"
|
||||
buf=""
|
||||
elif [[ -z "$line" ]]; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue