command mode (can now be quit with :q)
Co-authored-by: Hayden Young <hayden@haydennyyy.com>
This commit is contained in:
@@ -183,6 +183,17 @@ def and_exit(h):
|
||||
h.await_exit()
|
||||
|
||||
|
||||
def trigger_command_mode(h):
|
||||
# in order to enter a steady state, trigger an unknown key first and then
|
||||
# press escape to open the command mode. this is necessary as `Escape` is
|
||||
# the start of "escape sequences" and sending characters too quickly will
|
||||
# be interpreted as a single keypress
|
||||
h.press('^J')
|
||||
h.await_text('unknown key')
|
||||
h.press('Escape')
|
||||
h.await_text_missing('unknown key')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('color', (True, False))
|
||||
def test_color_test(color):
|
||||
with run('--color-test', color=color) as h, and_exit(h):
|
||||
@@ -243,13 +254,6 @@ def test_status_clearing_behaviour():
|
||||
h.await_text_missing('unknown key')
|
||||
|
||||
|
||||
def test_escape_key_behaviour():
|
||||
# TODO: eventually escape will have a command utility, for now: unknown
|
||||
with run() as h, and_exit(h):
|
||||
h.press('Escape')
|
||||
h.await_text('unknown key')
|
||||
|
||||
|
||||
def test_reacts_to_resize():
|
||||
with run() as h, and_exit(h):
|
||||
first_line = h.get_screen_line(0)
|
||||
@@ -865,3 +869,83 @@ def test_save_file_when_it_did_not_exist(tmpdir):
|
||||
h.await_text_missing('*')
|
||||
|
||||
assert f.read() == 'hello world\n'
|
||||
|
||||
|
||||
def test_quit_via_colon_q():
|
||||
with run() as h:
|
||||
trigger_command_mode(h)
|
||||
h.press_and_enter(':q')
|
||||
h.await_exit()
|
||||
|
||||
|
||||
def test_key_navigation_in_command_mode():
|
||||
with run() as h, and_exit(h):
|
||||
trigger_command_mode(h)
|
||||
h.press('hello world')
|
||||
h.await_cursor_position(x=11, y=23)
|
||||
h.press('Left')
|
||||
h.await_cursor_position(x=10, y=23)
|
||||
h.press('Right')
|
||||
h.await_cursor_position(x=11, y=23)
|
||||
h.press('Home')
|
||||
h.await_cursor_position(x=0, y=23)
|
||||
h.press('End')
|
||||
h.await_cursor_position(x=11, y=23)
|
||||
h.press('^A')
|
||||
h.await_cursor_position(x=0, y=23)
|
||||
h.press('^E')
|
||||
h.await_cursor_position(x=11, y=23)
|
||||
|
||||
h.press('DC') # does nothing at end
|
||||
h.await_cursor_position(x=11, y=23)
|
||||
h.await_text('\nhello world\n')
|
||||
|
||||
h.press('Bspace')
|
||||
h.await_cursor_position(x=10, y=23)
|
||||
h.await_text('\nhello worl\n')
|
||||
|
||||
h.press('Home')
|
||||
|
||||
h.press('Bspace') # does nothing at beginning
|
||||
h.await_cursor_position(x=0, y=23)
|
||||
h.await_text('\nhello worl\n')
|
||||
|
||||
h.press('DC')
|
||||
h.await_cursor_position(x=0, y=23)
|
||||
h.await_text('\nello worl\n')
|
||||
|
||||
# unknown keys don't do anything
|
||||
h.press('^J')
|
||||
h.await_text('\nello worl\n')
|
||||
|
||||
h.press('Enter')
|
||||
|
||||
|
||||
def test_save_via_command_mode(tmpdir):
|
||||
f = tmpdir.join('f')
|
||||
|
||||
with run(str(f)) as h, and_exit(h):
|
||||
h.press('hello world')
|
||||
trigger_command_mode(h)
|
||||
h.press_and_enter(':w')
|
||||
|
||||
assert f.read() == 'hello world\n'
|
||||
|
||||
|
||||
def test_resizing_and_scrolling_in_command_mode():
|
||||
with run(width=20) as h, and_exit(h):
|
||||
h.press('a' * 15)
|
||||
h.await_text(f'\n{"a" * 15}\n')
|
||||
trigger_command_mode(h)
|
||||
h.press('b' * 15)
|
||||
h.await_text(f'\n{"b" * 15}\n')
|
||||
|
||||
with h.resize(width=16, height=24):
|
||||
h.await_text('\n«aaaaaa\n') # the text contents
|
||||
h.await_text('\n«bbbbbb\n') # the text contents
|
||||
h.await_cursor_position(x=7, y=23)
|
||||
h.press('Left')
|
||||
h.await_cursor_position(x=14, y=23)
|
||||
h.await_text(f'\n{"b" * 15}\n')
|
||||
|
||||
h.press('Enter')
|
||||
|
||||
Reference in New Issue
Block a user