Match the position of the reverse-search match in the prompt
This commit is contained in:
@@ -234,7 +234,11 @@ class DeferredRunner:
|
||||
def _get_wch(self):
|
||||
while not isinstance(self._ops[self._i], KeyPress):
|
||||
self._i += 1
|
||||
self._ops[self._i - 1](self.screen)
|
||||
try:
|
||||
self._ops[self._i - 1](self.screen)
|
||||
except AssertionError: # pragma: no cover (only on failures)
|
||||
self.screen.screenshot()
|
||||
raise
|
||||
self._i += 1
|
||||
print(f'KEY: {self._ops[self._i - 1].wch!r}')
|
||||
return self._ops[self._i - 1].wch
|
||||
@@ -344,21 +348,11 @@ class DeferredRunner:
|
||||
raise AssertionError(self.ops[i:])
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def screenshot_on_assert(h):
|
||||
try:
|
||||
yield h
|
||||
except AssertionError: # pragma: no cover
|
||||
h.screenshot()
|
||||
raise
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def run_fake(*cmd, **kwargs):
|
||||
h = DeferredRunner(cmd, **kwargs)
|
||||
with screenshot_on_assert(h):
|
||||
h.await_text(babi.VERSION_STR)
|
||||
yield h
|
||||
h.await_text(babi.VERSION_STR)
|
||||
yield h
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@@ -367,7 +361,7 @@ def run_tmux(*args, colors=256, **kwargs):
|
||||
quoted = ' '.join(shlex.quote(p) for p in cmd)
|
||||
term = 'screen-256color' if colors == 256 else 'screen'
|
||||
cmd = ('bash', '-c', f'export TERM={term}; exec {quoted}')
|
||||
with PrintsErrorRunner(*cmd, **kwargs) as h, screenshot_on_assert(h):
|
||||
with PrintsErrorRunner(*cmd, **kwargs) as h, h.on_error():
|
||||
# startup with coverage can be slow
|
||||
h.await_text(babi.VERSION_STR, timeout=2)
|
||||
yield h
|
||||
|
||||
@@ -239,6 +239,19 @@ def test_search_reverse_search_history(run, xdg_data_home, ten_lines):
|
||||
h.await_cursor_position(x=0, y=4)
|
||||
|
||||
|
||||
def test_search_reverse_search_pos_during(run, xdg_data_home, ten_lines):
|
||||
xdg_data_home.join('babi/history/search').ensure().write(
|
||||
'line_3\n',
|
||||
)
|
||||
with run(str(ten_lines)) as h, and_exit(h):
|
||||
h.press('^W')
|
||||
h.press('^R')
|
||||
h.press('ne')
|
||||
h.await_text('search(reverse-search)`ne`: line_3')
|
||||
h.await_cursor_position(y=23, x=30)
|
||||
h.press('^C')
|
||||
|
||||
|
||||
def test_search_reverse_search_pos_after(run, xdg_data_home, ten_lines):
|
||||
xdg_data_home.join('babi/history/search').ensure().write(
|
||||
'line_3\n',
|
||||
|
||||
Reference in New Issue
Block a user