Skip to content

Commit

Permalink
added jump to line functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Jan 29, 2024
1 parent d29c30b commit de57f71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cat_win/util/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,42 @@ def _action_save(self, write_func) -> bool:
print(self.error_bar, file=sys.stderr)
return True

def _action_jump(self, _) -> bool:
def _render_scr(l_jmp: str) -> None:
max_y, max_x = self.getxymax()
try:
if self.error_bar:
self.curse_window.addstr(max_y + self.status_bar_size - 2, 0,
self.error_bar[:max_x].ljust(max_x),
self._get_color(2))
jump_message = f"Confirm: [y]es, [n]o - Jump to line: {l_jmp}_"[:max_x].ljust(max_x)
self.curse_window.addstr(max_y + self.status_bar_size - 1, 0, jump_message,
self._get_color(5))
except curses.error:
pass
self.curse_window.refresh()
curses.curs_set(0)

wchar, l_jmp = '', ''
while str(wchar).upper() not in ['\x1b', 'N']:
_render_scr(l_jmp)
wchar, key = self._get_new_char()
if key in ACTION_HOTKEYS:
if key in [b'_action_quit', b'_action_interrupt']:
break
if key == b'_action_resize':
getattr(self, key.decode(), lambda *_: False)(None)
self._render_scr()
curses.curs_set(0)
if key == b'_key_string' and wchar.isdigit():
l_jmp += wchar
elif (key == b'_key_string' and wchar.upper() in ['Y', 'J']) or \
key == b'_key_enter':
if l_jmp:
self.cpos.row = min(int(l_jmp), len(self.window_content)-1)
break
return True

def _action_quit(self, write_func) -> bool:
"""
handles the quit editor action.
Expand Down
1 change: 1 addition & 0 deletions cat_win/util/editorhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
b'^Y' : b'_key_redo',
# actions
b'^S' : b'_action_save',
b'^E' : b'_action_jump',
b'^Q' : b'_action_quit',
b'^C' : b'_action_interrupt',
b'KEY_RESIZE' : b'_action_resize',
Expand Down

0 comments on commit de57f71

Please sign in to comment.