fish-shell/tests/pexpects/status.py
Johannes Altmanninger 610338cc70 On undo after execute, restore the cursor position
Ever since 149594f974 (Initial revision, 2005-09-20), we move the
cursor to the end of the commandline just before executing it.

This is so we can move the cursor to the line below the command line,
so moving the cursor is relevant if one presses enter on say, the
first line of a multi-line commandline.

As mentioned in #10838 and others, it can be useful to restore the
cursor position when recalling commandline from history. Make undo
restore the position where enter was pressed, instead of implicitly
moving the cursor to the end. This allows to quickly correct small
mistakes in large commandlines that failed recently.

This requires a new way of moving the cursor below the command line.
Test changes include unrelated cleanup of history.py.
2024-12-21 13:10:34 +01:00

41 lines
1.1 KiB
Python

#!/usr/bin/env python3
from pexpect_helper import SpawnedProc, TO_END
sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
sp.send,
sp.sendline,
sp.sleep,
sp.expect_prompt,
sp.expect_re,
sp.expect_str,
)
expect_prompt()
# Fish should start in default-mode (i.e., emacs) bindings. The default escape
# timeout is 30ms.
#
# Because common CI systems are awful, we have to increase this:
sendline("set -g fish_escape_delay_ms 120")
expect_prompt("")
# Validate standalone behavior
sendline("status current-commandline")
expect_prompt(TO_END + "status current-commandline\r\n")
# Validate behavior as part of a command chain
sendline("true 7 && status current-commandline")
expect_prompt(TO_END + "true 7 && status current-commandline\r\n")
# Validate behavior when used in a function
sendline("function report; set -g last_cmdline (status current-commandline); end")
expect_prompt("")
sendline("report 27")
expect_prompt("")
sendline("echo $last_cmdline")
expect_prompt(TO_END + "report 27\r\n")
# Exit
send("\x04") # <c-d>
expect_str("")