Add ^C to show current position

This commit is contained in:
Anthony Sottile
2019-11-27 19:49:36 -08:00
parent d4bd2abb45
commit e543b11dbb
2 changed files with 34 additions and 8 deletions

View File

@@ -780,6 +780,13 @@ class File:
for i in range(to_display, margin.body_lines):
stdscr.insstr(i + margin.header, 0, blankline)
def current_position(self, status: Status) -> None:
line = f'line {self.cursor_y + 1}'
col = f'col {self.x + 1}'
line_count = max(len(self.lines) - 1, 1)
lines_word = 'line' if line_count == 1 else 'lines'
status.update(f'{line}, {col} (of {line_count} {lines_word})')
class Screen:
def __init__(
@@ -962,6 +969,8 @@ def _edit(screen: Screen) -> EditResult:
screen.status.update(f'invalid regex: {response!r}')
else:
screen.file.search(regex, screen.status, screen.margin)
elif key.keyname == b'^C':
screen.file.current_position(screen.status)
elif key.keyname == b'^[': # escape
response = screen.status.prompt(screen, '')
if response == ':q':

View File

@@ -619,6 +619,14 @@ def test_go_to_line_cancel(ten_lines, key):
h.await_text('cancelled')
def test_go_to_line_not_an_integer():
with run() as h, and_exit(h):
h.press('^_')
h.await_text('enter line number:')
h.press_and_enter('asdf')
h.await_text("not an integer: 'asdf'")
def test_search_wraps(ten_lines):
with run(str(ten_lines)) as h, and_exit(h):
h.press('Down')
@@ -690,14 +698,6 @@ def test_search_cancel(ten_lines, key):
h.await_text('cancelled')
def test_go_to_line_not_an_integer():
with run() as h, and_exit(h):
h.press('^_')
h.await_text('enter line number:')
h.press_and_enter('asdf')
h.await_text("not an integer: 'asdf'")
def test_scrolling_arrow_key_movement(ten_lines):
with run(str(ten_lines), height=10) as h, and_exit(h):
h.await_text('line_7')
@@ -1368,6 +1368,23 @@ def test_cancel_command_mode():
h.await_text_missing('invalid command')
def test_current_position(ten_lines):
with run(str(ten_lines)) as h, and_exit(h):
h.press('^C')
h.await_text('line 1, col 1 (of 10 lines)')
h.press('Right')
h.press('^C')
h.await_text('line 1, col 2 (of 10 lines)')
h.press('Down')
h.press('^C')
h.await_text('line 2, col 2 (of 10 lines)')
h.press('Up')
for i in range(10):
h.press('^K')
h.press('^C')
h.await_text('line 1, col 1 (of 1 line)')
def test_cut_and_uncut(ten_lines):
with run(str(ten_lines)) as h, and_exit(h):
h.press('^K')