summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/defaults/keys.py3
-rw-r--r--ranger/gui/widgets/console.py202
2 files changed, 107 insertions, 98 deletions
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 19870069..f2e941c1 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -70,6 +70,7 @@ def initialize_commands(command_list):
 	bind(curses.KEY_MOUSE, do('handle_mouse'))
 	bind(':', do('open_console', ':'))
 	bind('/', do('open_console', '/'))
+	bind('?', do('open_console', '?'))
 	bind('!', do('open_console', '!'))
 	bind('r', do('open_console', '@'))
 
@@ -102,7 +103,7 @@ def initialize_console_commands(command_list):
 	bind(ctrl('u'), do('delete_rest', -1))
 
 	# system functions
-	bind(ctrl('c'), do('close'))
+	bind(ctrl('c'), ESC, do('close'))
 	bind(ctrl('j'), curses.KEY_ENTER, do('execute'))
 	bind(ctrl('l'), do_fm('redraw'))
 	bind(curses.KEY_RESIZE, do_fm('resize'))
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index cf0cc717..e9356613 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -4,9 +4,6 @@ from . import Widget
 import curses
 from ranger import log
 
-CONSOLE_MODES = tuple(':@/?>!')
-CONSOLE_PROMPTS = { '@': 'open with: ' }
-
 class Console(Widget):
 	mode = None
 	visible = False
@@ -17,15 +14,12 @@ class Console(Widget):
 	def __init__(self, win):
 		from ranger.container import CommandList
 		Widget.__init__(self, win)
-		self.mode = None
-		self.visible = False
 		self.commandlist = CommandList()
 		self.settings.keys.initialize_console_commands(self.commandlist)
-		self.last_cursor_mode = 1
 		self.clear()
-
-	def feed_env(self, env):
-		self.cf = env.cf
+	
+	def init(self):
+		pass
 
 	def draw(self):
 		if self.mode is None:
@@ -39,14 +33,13 @@ class Console(Widget):
 			pass
 
 	def open(self, mode):
-		if mode not in CONSOLE_MODES:
+		if mode not in self.mode_classes:
 			return False
 
 		self.last_cursor_mode = curses.curs_set(1)
 		self.mode = mode
-		log(self.__class__)
 		self.__class__ = self.mode_classes[mode]
-		log(self.__class__)
+		self.init()
 		self.focused = True
 		self.visible = True
 		return True
@@ -129,12 +122,15 @@ class Console(Widget):
 		self.pos = 0
 		self.close()
 
+
 class CommandConsole(Console):
 	prompt = ':'
 
+
 class QuickCommandConsole(Console):
 	prompt = '>'
 
+
 class SearchConsole(Console):
 	prompt = '/'
 	def execute(self):
@@ -147,97 +143,119 @@ class SearchConsole(Console):
 				self.fm.env.cf = self.fm.env.pwd.pointed_file
 		Console.execute(self)
 
+
 class OpenConsole(Console):
 	prompt = '!'
-	def execute(self):
-		line = self.line
-		if line[0] == '!':
-			self.fm.execute_file(tuple(line[1:].split()) + (self.fm.env.cf.path, ))
-		else:
-			self.fm.execute_file(tuple(line.split()) + (self.fm.env.cf.path, ), background = True)
-		Console.execute(self)
+#	def execute(self):
+#		line = self.line
+#		if line[0] == '!':
+#			self.fm.execute_file(tuple(line[1:].split()) + (self.fm.env.cf.path, ))
+#		else:
+#			self.fm.execute_file(tuple(line.split()) + (self.fm.env.cf.path, ), flags='d')
+#		Console.execute(self)
+
 
 class QuickOpenConsole(Console):
+	"""The QuickOpenConsole allows you to open files with
+pre-defined programs and modes very quickly. By adding flags
+to the command, you can specify precisely how the program is run,
+ie. the d-flag will run it detached from the filemanager.
+"""
+
 	prompt = 'open with: '
+
 	def execute(self):
 		split = self.line.split()
-		app, flags, mode = get_app_flags_mode(self.line, self.fm)
+		app, flags, mode = self._get_app_flags_mode()
 		self.fm.execute_file(
-				files = [self.cf],
+				files = [self.env.cf],
 				app = app,
 				flags = flags,
 				mode = mode )
 		Console.execute(self)
 
-def get_app_flags_mode(line, fm):
-	""" extracts the application, flags and mode from a string entered into the "openwith_quick" console. """
-	# examples:
-	# "mplayer d 1" => ("mplayer", "d", 1)
-	# "aunpack 4" => ("aunpack", "", 4)
-	# "p" => ("", "p", 0)
-	# "" => None
+	def _get_app_flags_mode(self):
+		"""extracts the application, flags and mode from
+a string entered into the "openwith_quick" console.
+"""
+		# examples:
+		# "mplayer d 1" => ("mplayer", "d", 1)
+		# "aunpack 4" => ("aunpack", "", 4)
+		# "p" => ("", "p", 0)
+		# "" => None
+
+		app = ''
+		flags = ''
+		mode = 0
+		split = self.line.split()
 
-	app = ''
-	flags = ''
-	mode = 0
-	split = line.split()
+		if len(split) == 0:
+			pass
 
-	if len(split) == 0:
-		pass
+		elif len(split) == 1:
+			part = split[0]
+			if self._is_app(part):
+				app = part
+			elif self._is_flags(part):
+				flags = part
+			elif self._is_mode(part):
+				mode = part
+
+		elif len(split) == 2:
+			part0 = split[0]
+			part1 = split[1]
+
+			if self._is_app(part0):
+				app = part0
+				if self._is_flags(part1):
+					flags = part1
+				elif self._is_mode(part1):
+					mode = part1
+			elif self._is_flags(part0):
+				flags = part0
+				if self._is_mode(part1):
+					mode = part1
+			elif self._is_mode(part0):
+				mode = part0
+				if self._is_flags(part1):
+					flags = part1
+
+		elif len(split) >= 3:
+			part0 = split[0]
+			part1 = split[1]
+			part2 = split[2]
+
+			if self._is_app(part0):
+				app = part0
+				if self._is_flags(part1):
+					flags = part1
+					if self._is_mode(part2):
+						mode = part2
+				elif self._is_mode(part1):
+					mode = part1
+					if self._is_flags(part2):
+						flags = part2
+			elif self._is_flags(part0):
+				flags = part0
+				if self._is_mode(part1):
+					mode = part1
+			elif self._is_mode(part0):
+				mode = part0
+				if self._is_flags(part1):
+					flags = part1
+
+		return app, flags, int(mode)
+
+	def _is_app(self, arg):
+		return self.fm.apps.has(arg)
+
+	def _is_flags(self, arg):
+		from ranger.applications import ALLOWED_FLAGS
+		return all(x in ALLOWED_FLAGS for x in arg)
+
+	def _is_mode(self, arg):
+		return all(x in '0123456789' for x in arg)
 
-	elif len(split) == 1:
-		part = split[0]
-		if is_app(part, fm):
-			app = part
-		elif is_flags(part):
-			flags = part
-		elif is_mode(part):
-			mode = part
-
-	elif len(split) == 2:
-		part0 = split[0]
-		part1 = split[1]
-
-		if is_app(part0, fm):
-			app = part0
-			if is_flags(part1):
-				flags = part1
-			elif is_mode(part1):
-				mode = part1
-		elif is_flags(part0):
-			flags = part0
-			if is_mode(part1):
-				mode = part1
-		elif is_mode(part0):
-			mode = part0
-			if is_flags(part1):
-				flags = part1
-
-	elif len(split) >= 3:
-		part0 = split[0]
-		part1 = split[1]
-		part2 = split[2]
-
-		if is_app(part0, fm):
-			app = part0
-			if is_flags(part1):
-				flags = part1
-				if is_mode(part2):
-					mode = part2
-			elif is_mode(part1):
-				mode = part1
-				if is_flags(part2):
-					flags = part2
-		elif is_flags(part0):
-			flags = part0
-			if is_mode(part1):
-				mode = part1
-		elif is_mode(part0):
-			mode = part0
-			if is_flags(part1):
-				flags = part1
-
-	return app, flags, int(mode)
 
 Console.mode_classes = {
 		':': CommandConsole,
@@ -247,13 +265,3 @@ Console.mode_classes = {
 		'/': SearchConsole,
 		'?': SearchConsole,
 }
-
-def is_app(arg, fm):
-	return fm.apps.has(arg)
-
-def is_flags(arg):
-	from ranger.applications import ALLOWED_FLAGS
-	return all(x in ALLOWED_FLAGS for x in arg)
-
-def is_mode(arg):
-	return all(x in '0123456789' for x in arg)
ter hut <hut@lavabit.com> 2010-01-14 02:59:14 +0100 1.0.2!' href='/akspecs/ranger/commit/doc/pydoc/ranger.actions.html?h=v1.9.0b5&id=4e9450f955e763a4d301645ab11201834d8a0ccc'>4e9450f9 ^
f07bb12f ^


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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191