1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
def initialize_commands(cl):
from ranger.fm import FM
from curses.ascii import ctrl
from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
import curses
# syntax for binding keys: cl.bind(fnc, *keys)
# fnc is a function which is called with the FM instance,
# keys are one or more key-combinations which are either:
# * a string
# * an integer which represents an ascii code
# * a tuple of integers
def curry(fnc, *args, **keywords):
return lambda fm: fnc(fm, *args, **keywords)
c=curry
def move(**keywords):
return lambda fm: fm.move_pointer(**keywords)
def move_pages(n):
return lambda fm: fm.move_pointer_by_pages(n)
cl.bind(FM.move_left, 'h', curses.KEY_BACKSPACE, 127)
cl.bind(FM.move_right, 'l')
cl.bind(c(FM.move_right, mode=1), curses.KEY_ENTER, ctrl('j'))
cl.bind(c(FM.history_go, -1), 'H')
cl.bind(c(FM.history_go, 1), 'L')
cl.bind(move( relative = 1 ), 'j')
cl.bind(move_pages( 0.5 ), 'J')
cl.bind(move( relative = -1 ), 'k')
cl.bind(move_pages( -0.5 ), 'K')
cl.bind(move( absolute = 0 ), 'gg')
cl.bind(move( absolute = -1 ), 'G')
cl.bind(FM.edit_file, 'E')
# toggle options
def toggle_option(string):
return lambda fm: fm.toggle_boolean_option(string)
cl.bind(toggle_option('show_hidden'), 'th')
cl.bind(toggle_option('preview_files'), 'tp')
cl.bind(toggle_option('directories_first'), 'td')
# key combinations which change the current directory
def cd(path):
return lambda fm: fm.enter_dir(path)
cl.bind(cd("~"), 'gh')
cl.bind(cd("/etc"), 'ge')
cl.bind(cd("/usr"), 'gu')
cl.bind(cd("/"), 'gr')
cl.bind(cd("/media"), 'gm')
cl.bind(cd("/mnt"), 'gn')
cl.bind(cd("~/.trash"), 'gt')
cl.bind(cd("/srv"), 'gs')
cl.bind(FM.search_forward, 'n')
cl.bind(FM.search_backward, 'N')
# bookmarks
for key in ALLOWED_BOOKMARK_KEYS:
cl.bind(c(FM.enter_bookmark, key), "`" + key, "'" + key)
cl.bind(c(FM.set_bookmark, key), "m" + key)
cl.bind(c(FM.unset_bookmark, key), "um" + key)
# system functions
cl.bind(FM.exit, ctrl('D'), 'q', 'ZZ')
cl.bind(FM.reset, ctrl('R'))
cl.bind(FM.redraw, ctrl('L'))
cl.bind(FM.interrupt, ctrl('C'))
cl.bind(FM.resize, curses.KEY_RESIZE)
cl.bind(FM.handle_mouse, curses.KEY_MOUSE)
cl.bind(curry(FM.open_console, ':'), ':')
cl.bind(curry(FM.open_console, '/'), '/')
cl.bind(curry(FM.open_console, '!'), '!')
cl.bind(curry(FM.open_console, '@'), 'r')
def test(fm):
from ranger.helper import log
log(fm.bookmarks.dct)
cl.bind(test, 'x')
cl.rebuild_paths()
def initialize_console_commands(cl):
from ranger.fm import FM
from ranger.gui.wconsole import WConsole
from curses.ascii import ctrl, ESC
import curses
def type_key(key):
return lambda con, fm: con.type_key(key)
def curry(fnc, *args, **keywords):
return lambda con, fm: fnc(con, *args, **keywords)
def curry_fm(fnc, *args, **keywords):
return lambda con, fm: fnc(fm, *args, **keywords)
c_fm = curry_fm
c = curry
# movement
cl.bind(c(WConsole.move, relative = -1), curses.KEY_LEFT, ctrl('b'))
cl.bind(c(WConsole.move, relative = 1), curses.KEY_RIGHT, ctrl('f'))
cl.bind(c(WConsole.move, absolute = 0), curses.KEY_HOME, ctrl('a'))
cl.bind(c(WConsole.move, absolute = -1), curses.KEY_END, ctrl('e'))
cl.bind(c(WConsole.delete, 0), curses.KEY_DC, ctrl('d'))
cl.bind(c(WConsole.delete, -1), curses.KEY_BACKSPACE, 127, ctrl('h'))
cl.bind(c(WConsole.delete_rest, -1), ctrl('U'))
cl.bind(c(WConsole.delete_rest, 1), ctrl('K'))
# system functions
cl.bind(c(WConsole.close), ESC, ctrl('C'))
cl.bind(WConsole.execute, curses.KEY_ENTER, ctrl('j'))
cl.bind(c_fm(FM.redraw), ctrl('L'))
cl.bind(c_fm(FM.resize), curses.KEY_RESIZE)
for i in range(ord(' '), ord('~')):
cl.bind(type_key(i), i)
|