Clear status when switching / exiting multiple files

Resolves #26
This commit is contained in:
Anthony Sottile
2019-11-20 21:02:22 -08:00
parent c3df00db4a
commit cfae01b065
2 changed files with 22 additions and 2 deletions

10
babi.py
View File

@@ -208,6 +208,9 @@ class Status:
self._status = status self._status = status
self._action_counter = 25 self._action_counter = 25
def clear(self) -> None:
self._status = ''
def draw(self, stdscr: 'curses._CursesWindow', margin: Margin) -> None: def draw(self, stdscr: 'curses._CursesWindow', margin: Margin) -> None:
if margin.footer or self._status: if margin.footer or self._status:
stdscr.insstr(curses.LINES - 1, 0, ' ' * curses.COLS) stdscr.insstr(curses.LINES - 1, 0, ' ' * curses.COLS)
@@ -226,10 +229,10 @@ class Status:
else: else:
self._action_counter -= 24 self._action_counter -= 24
if self._action_counter < 0: if self._action_counter < 0:
self._status = '' self.clear()
def prompt(self, screen: 'Screen', prompt: str) -> str: def prompt(self, screen: 'Screen', prompt: str) -> str:
self.update('') self.clear()
pos = 0 pos = 0
buf = '' buf = ''
while True: while True:
@@ -953,10 +956,13 @@ def c_main(stdscr: 'curses._CursesWindow', args: argparse.Namespace) -> None:
res = _edit(screen) res = _edit(screen)
if res == EditResult.EXIT: if res == EditResult.EXIT:
del screen.files[screen.i] del screen.files[screen.i]
screen.status.clear()
elif res == EditResult.NEXT: elif res == EditResult.NEXT:
screen.i += 1 screen.i += 1
screen.status.clear()
elif res == EditResult.PREV: elif res == EditResult.PREV:
screen.i -= 1 screen.i -= 1
screen.status.clear()
else: else:
raise AssertionError(f'unreachable {res}') raise AssertionError(f'unreachable {res}')

View File

@@ -1078,8 +1078,22 @@ def test_multiple_files(tmpdir):
h.await_text('[3/3]') h.await_text('[3/3]')
h.await_text('c text') h.await_text('c text')
# make sure to clear statuses when switching files
h.press('^J')
h.await_text('unknown key')
h.press('M-Right')
h.await_text_missing('unknown key')
h.press('^J')
h.await_text('unknown key')
h.press('M-Left')
h.await_text_missing('unknown key')
# also make sure to clear statuses when exiting files
h.press('^J')
h.await_text('unknown key')
h.press('^X') h.press('^X')
h.await_text('file_a') h.await_text('file_a')
h.await_text_missing('unknown key')
h.press('^X') h.press('^X')
h.await_text('file_b') h.await_text('file_b')
h.press('^X') h.press('^X')