Skip to content

Commit

Permalink
Merge pull request #368 from aude/sidebar-vi-keys
Browse files Browse the repository at this point in the history
Add vi keys for sidebar
  • Loading branch information
inducer authored Jan 8, 2020
2 parents 5a94326 + 86443c7 commit ebfeb34
Showing 1 changed file with 83 additions and 66 deletions.
149 changes: 83 additions & 66 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
o - show console/output screen
m - open module
j/k - up/down
Ctrl-u/d - page up/down
h/l - scroll left/right
g/G - start/end
j/k - down/up
l/h - right/left
Ctrl-f/b - page down/up
Ctrl-d/u - page down/up
G/g - end/home
L - show (file/line) location / go to line
/ - search
,/. - search next/previous
Expand All @@ -80,7 +82,7 @@
B - focus breakpoint list
C - focus code
f1/?/H - show this help screen
F1/? - show this help screen
q - quit
Ctrl-c - when in continue mode, break back to PuDB
Expand All @@ -107,7 +109,7 @@
Keys in variables list:
\/enter/space - expand/collapse
t/r/s/c - show type/repr/str/custom for this variable
h - toggle highlighting
H - toggle highlighting
@ - toggle repetition at top
* - cycle attribute visibility: public/_private/__dunder__
m - toggle method visibility
Expand All @@ -123,6 +125,23 @@
b - toggle breakpoint
d - delete breakpoint
e - edit breakpoint
Other keys:
j/k - down/up
l/h - right/left
Ctrl-f/b - page down/up
Ctrl-d/u - page down/up
G/g - end/home
V - focus variables
S - focus stack
B - focus breakpoint list
C - focus code
F1/? - show this help screen
q - quit
Ctrl-l - redraw screen
"""

HELP_LICENSE = r"""
Expand Down Expand Up @@ -663,6 +682,50 @@ def __init__(self, dbg, stdin, stdout, term_size):

# {{{ build ui

# {{{ key bindings

def move_up(w, size, key):
w.keypress(size, "up")

def move_down(w, size, key):
w.keypress(size, "down")

def move_left(w, size, key):
w.keypress(size, "left")

def move_right(w, size, key):
w.keypress(size, "right")

def page_up(w, size, key):
w.keypress(size, "page up")

def page_down(w, size, key):
w.keypress(size, "page down")

def move_home(w, size, key):
w.keypress(size, "home")

def move_end(w, size, key):
w.keypress(size, "end")

def add_vi_nav_keys(widget):
widget.listen("k", move_up)
widget.listen("j", move_down)
widget.listen("h", move_left)
widget.listen("l", move_right)
widget.listen("ctrl b", page_up)
widget.listen("ctrl f", page_down)
widget.listen("ctrl u", page_up)
widget.listen("ctrl d", page_down)
widget.listen("g", move_home)
widget.listen("G", move_end)

def add_help_keys(widget):
widget.listen("f1", helpside)
widget.listen("?", helpside)

# }}}

# {{{ left/source column

self.source = urwid.SimpleListWalker([])
Expand Down Expand Up @@ -741,6 +804,12 @@ def clear_cmdline_history(btn):
])
self.rhs_col_sigwrap = SignalWrap(self.rhs_col)

def helpside(w, size, key):
help(HELP_HEADER + HELP_SIDE + HELP_MAIN + HELP_LICENSE)

add_vi_nav_keys(self.rhs_col_sigwrap)
add_help_keys(self.rhs_col_sigwrap)

# }}}

self.columns = urwid.Columns(
Expand Down Expand Up @@ -797,7 +866,7 @@ def change_var_state(w, size, key):
iinfo.display_type = "str"
elif key == "c":
iinfo.display_type = CONFIG["custom_stringifier"]
elif key == "h":
elif key == "H":
iinfo.highlighted = not iinfo.highlighted
elif key == "@":
iinfo.repeated_at_top = not iinfo.repeated_at_top
Expand Down Expand Up @@ -938,16 +1007,13 @@ def insert_watch(w, size, key):
fvi.watches.append(we)
self.update_var_view()

def helpside(w, size, key):
help(HELP_HEADER + HELP_SIDE + HELP_MAIN + HELP_LICENSE)

self.var_list.listen("\\", change_var_state)
self.var_list.listen(" ", change_var_state)
self.var_list.listen("t", change_var_state)
self.var_list.listen("r", change_var_state)
self.var_list.listen("s", change_var_state)
self.var_list.listen("c", change_var_state)
self.var_list.listen("h", change_var_state)
self.var_list.listen("H", change_var_state)
self.var_list.listen("@", change_var_state)
self.var_list.listen("*", change_var_state)
self.var_list.listen("w", change_var_state)
Expand All @@ -960,14 +1026,10 @@ def helpside(w, size, key):
self.var_list.listen("[", partial(change_rhs_box, 'variables', 0, -1))
self.var_list.listen("]", partial(change_rhs_box, 'variables', 0, 1))

self.var_list.listen("j", self.rhs_scroll_down)
self.var_list.listen("k", self.rhs_scroll_up)
self.var_list.listen("f1", helpside)
self.var_list.listen("?", helpside)

# }}}

# {{{ stack listeners

def examine_frame(w, size, key):
_, pos = self.stack_list._w.get_focus()
self.debugger.set_frame_index(self.translate_ui_stack_index(pos))
Expand All @@ -990,14 +1052,10 @@ def move_stack_down(w, size, key):
self.stack_list.listen("[", partial(change_rhs_box, 'stack', 1, -1))
self.stack_list.listen("]", partial(change_rhs_box, 'stack', 1, 1))

self.stack_list.listen("j", self.rhs_scroll_down)
self.stack_list.listen("k", self.rhs_scroll_up)
self.stack_list.listen("f1", helpside)
self.stack_list.listen("?", helpside)

# }}}

# {{{ breakpoint listeners

def save_breakpoints(w, size, key):
self.debugger.save_breakpoints()

Expand Down Expand Up @@ -1127,10 +1185,6 @@ def show_breakpoint(w, size, key):
self.bp_list.listen("[", partial(change_rhs_box, 'breakpoints', 2, -1))
self.bp_list.listen("]", partial(change_rhs_box, 'breakpoints', 2, 1))

self.bp_list.listen("j", self.rhs_scroll_down)
self.bp_list.listen("k", self.rhs_scroll_up)
self.bp_list.listen("f1", helpside)
self.bp_list.listen("?", helpside)
# }}}

# {{{ source listeners
Expand Down Expand Up @@ -1201,12 +1255,6 @@ def run_to_cursor(w, size, key):
self.debugger.set_continue()
end()

def move_home(w, size, key):
self.source.set_focus(0)

def move_end(w, size, key):
self.source.set_focus(len(self.source)-1)

def go_to_line(w, size, key):
_, line = self.source.get_focus()

Expand All @@ -1228,18 +1276,6 @@ def go_to_line(w, size, key):
lineno = min(max(0, int(lineno_edit.value())-1), len(self.source)-1)
self.source.set_focus(lineno)

def move_down(w, size, key):
w.keypress(size, "down")

def move_up(w, size, key):
w.keypress(size, "up")

def page_down(w, size, key):
w.keypress(size, "page down")

def page_up(w, size, key):
w.keypress(size, "page up")

def scroll_left(w, size, key):
self.source_hscroll_start = max(
0,
Expand Down Expand Up @@ -1465,33 +1501,20 @@ def helpmain(w, size, key):
self.source_sigwrap.listen("c", cont)
self.source_sigwrap.listen("t", run_to_cursor)

self.source_sigwrap.listen("j", move_down)
self.source_sigwrap.listen("k", move_up)
self.source_sigwrap.listen("ctrl d", page_down)
self.source_sigwrap.listen("ctrl u", page_up)
self.source_sigwrap.listen("ctrl f", page_down)
self.source_sigwrap.listen("ctrl b", page_up)
self.source_sigwrap.listen("h", scroll_left)
self.source_sigwrap.listen("l", scroll_right)

self.source_sigwrap.listen("L", go_to_line)
self.source_sigwrap.listen("/", search)
self.source_sigwrap.listen(",", search_previous)
self.source_sigwrap.listen(".", search_next)

self.source_sigwrap.listen("home", move_home)
self.source_sigwrap.listen("end", move_end)
self.source_sigwrap.listen("g", move_home)
self.source_sigwrap.listen("G", move_end)
self.source_sigwrap.listen("L", go_to_line)

self.source_sigwrap.listen("b", toggle_breakpoint)
self.source_sigwrap.listen("m", pick_module)

self.source_sigwrap.listen("H", move_stack_top)
self.source_sigwrap.listen("u", move_stack_up)
self.source_sigwrap.listen("d", move_stack_down)
self.source_sigwrap.listen("f1", helpmain)
self.source_sigwrap.listen("?", helpmain)

add_vi_nav_keys(self.source_sigwrap)
add_help_keys(self.source_sigwrap)

# }}}

Expand Down Expand Up @@ -2007,12 +2030,6 @@ def set_cmdline_state(self, state_on):
self.cmdline_on = state_on
self.set_cmdline_size(None if state_on else 0)

def rhs_scroll_down(self, w, size, key):
w.keypress(size, "down")

def rhs_scroll_up(self, w, size, key):
w.keypress(size, "up")

def translate_ui_stack_index(self, index):
# note: self-inverse

Expand Down

0 comments on commit ebfeb34

Please sign in to comment.