本文整理汇总了Python中ranger.container.history.History.search方法的典型用法代码示例。如果您正苦于以下问题:Python History.search方法的具体用法?Python History.search怎么用?Python History.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ranger.container.history.History
的用法示例。
在下文中一共展示了History.search方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Console
# 需要导入模块: from ranger.container.history import History [as 别名]
# 或者: from ranger.container.history.History import search [as 别名]
class Console(Widget):
visible = False
last_cursor_mode = None
history_search_pattern = None
prompt = ':'
copy = ''
tab_deque = None
original_line = None
history = None
history_backup = None
override = None
allow_close = False
historypath = None
wait_for_command_input = False
unicode_buffer = ""
def __init__(self, win):
Widget.__init__(self, win)
self.clear()
self.history = History(self.settings.max_console_history_size)
# load history from files
if not ranger.arg.clean:
self.historypath = self.fm.confpath('history')
try:
f = open(self.historypath, 'r')
except:
pass
else:
for line in f:
self.history.add(line[:-1])
f.close()
self.line = ""
self.history_backup = History(self.history)
# NOTE: the console is considered in the "question mode" when the
# question_queue is non-empty. In that case, the console will draw the
# question instead of the regular console, and the input you give is
# used to answer the question instead of typing in commands.
#
# A question is a tuple of (question_string, callback_func,
# tuple_of_choices). callback_func is a function that is called when
# the question is answered which gets the answer as an argument.
# tuple_of_choices looks like ('y', 'n'). Only one-letter-answers are
# currently supported. Pressing enter uses the first choice whereas
# pressing ESC uses the second choice.
self.question_queue = []
def destroy(self):
# save history to files
if ranger.arg.clean or not self.settings.save_console_history:
return
if self.historypath:
try:
f = open(self.historypath, 'w')
except:
pass
else:
for entry in self.history_backup:
try:
f.write(entry + '\n')
except UnicodeEncodeError:
pass
f.close()
def draw(self):
self.win.erase()
if self.question_queue:
assert isinstance(self.question_queue[0], tuple)
assert len(self.question_queue[0]) == 3
self.addstr(0, 0, self.question_queue[0][0])
return
self.addstr(0, 0, self.prompt)
line = WideString(self.line)
overflow = -self.wid + len(self.prompt) + len(line) + 1
if overflow > 0:
self.addstr(0, len(self.prompt), str(line[overflow:]))
else:
self.addstr(0, len(self.prompt), self.line)
def finalize(self):
move = self.fm.ui.win.move
if self.question_queue:
try:
move(self.y, len(self.question_queue[0][0]))
except:
pass
else:
try:
pos = uwid(self.line[0:self.pos]) + len(self.prompt)
move(self.y, self.x + min(self.wid-1, pos))
except:
pass
def open(self, string='', prompt=None, position=None):
if prompt is not None:
assert isinstance(prompt, str)
self.prompt = prompt
elif 'prompt' in self.__dict__:
del self.prompt
#.........这里部分代码省略.........
示例2: Console
# 需要导入模块: from ranger.container.history import History [as 别名]
# 或者: from ranger.container.history.History import search [as 别名]
class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many-public-methods
visible = False
last_cursor_mode = None
history_search_pattern = None
prompt = ':'
copy = ''
tab_deque = None
original_line = None
history = None
history_backup = None
override = None
allow_close = False
historypath = None
wait_for_command_input = False
unicode_buffer = ""
def __init__(self, win):
Widget.__init__(self, win)
self.pos = 0
self.line = ''
self.history = History(self.settings.max_console_history_size)
# load history from files
if not ranger.args.clean:
self.historypath = self.fm.datapath('history')
if os.path.exists(self.historypath):
try:
fobj = open(self.historypath, 'r')
except OSError as ex:
self.fm.notify('Failed to read history file', bad=True, exception=ex)
else:
try:
for line in fobj:
self.history.add(line[:-1])
except UnicodeDecodeError as ex:
self.fm.notify('Failed to parse corrupt history file',
bad=True, exception=ex)
fobj.close()
self.history_backup = History(self.history)
# NOTE: the console is considered in the "question mode" when the
# question_queue is non-empty. In that case, the console will draw the
# question instead of the regular console, and the input you give is
# used to answer the question instead of typing in commands.
#
# A question is a tuple of (question_string, callback_func,
# tuple_of_choices). callback_func is a function that is called when
# the question is answered which gets the answer as an argument.
# tuple_of_choices looks like ('y', 'n'). Only one-letter-answers are
# currently supported. Pressing enter uses the first choice whereas
# pressing ESC uses the second choice.
self.question_queue = []
def destroy(self):
# save history to files
if ranger.args.clean or not self.settings.save_console_history:
return
if self.historypath:
try:
fobj = open(self.historypath, 'w')
except OSError as ex:
self.fm.notify('Failed to write history file', bad=True, exception=ex)
else:
for entry in self.history_backup:
try:
fobj.write(entry + '\n')
except UnicodeEncodeError:
pass
fobj.close()
Widget.destroy(self)
def draw(self):
self.win.erase()
if self.question_queue:
assert isinstance(self.question_queue[0], tuple)
assert len(self.question_queue[0]) == 3
self.addstr(0, 0, self.question_queue[0][0][self.pos:])
return
self.addstr(0, 0, self.prompt)
line = WideString(self.line)
overflow = -self.wid + len(self.prompt) + len(line) + 1
if overflow > 0:
self.addstr(0, len(self.prompt), str(line[overflow:]))
else:
self.addstr(0, len(self.prompt), self.line)
def finalize(self):
move = self.fm.ui.win.move
if self.question_queue:
try:
move(self.y, len(self.question_queue[0][0]))
except curses.error:
pass
else:
try:
pos = uwid(self.line[0:self.pos]) + len(self.prompt)
move(self.y, self.x + min(self.wid - 1, pos))
except curses.error:
pass
#.........这里部分代码省略.........
示例3: Console
# 需要导入模块: from ranger.container.history import History [as 别名]
# 或者: from ranger.container.history.History import search [as 别名]
class Console(Widget):
visible = False
last_cursor_mode = None
history_search_pattern = None
prompt = ':'
copy = ''
tab_deque = None
original_line = None
history = None
history_backup = None
override = None
allow_close = False
historypath = None
def __init__(self, win):
Widget.__init__(self, win)
self.clear()
self.history = History(self.settings.max_console_history_size)
# load history from files
if not ranger.arg.clean:
self.historypath = self.fm.confpath('history')
try:
f = open(self.historypath, 'r')
except:
pass
else:
for line in f:
self.history.add(line[:-1])
f.close()
self.history_backup = History(self.history)
def destroy(self):
# save history to files
if ranger.arg.clean or not self.settings.save_console_history:
return
if self.historypath:
try:
f = open(self.historypath, 'w')
except:
pass
else:
for entry in self.history_backup:
f.write(entry + '\n')
f.close()
def draw(self):
self.win.erase()
self.addstr(0, 0, self.prompt)
line = WideString(self.line)
overflow = -self.wid + len(self.prompt) + len(line) + 1
if overflow > 0:
self.addstr(str(line[overflow:]))
else:
self.addstr(self.line)
def finalize(self):
try:
pos = uwid(self.line[0:self.pos]) + len(self.prompt)
self.fm.ui.win.move(self.y, self.x + min(self.wid-1, pos))
except:
pass
def open(self, string='', prompt=None, position=None):
if prompt is not None:
assert isinstance(prompt, str)
self.prompt = prompt
elif 'prompt' in self.__dict__:
del self.prompt
if self.last_cursor_mode is None:
try:
self.last_cursor_mode = curses.curs_set(1)
except:
pass
self.allow_close = False
self.tab_deque = None
self.focused = True
self.visible = True
self.unicode_buffer = ""
self.line = string
self.history_search_pattern = self.line
self.pos = len(string)
if position is not None:
self.pos = min(self.pos, position)
self.history_backup.fast_forward()
self.history = History(self.history_backup)
self.history.add('')
return True
def close(self, trigger_cancel_function=True):
if trigger_cancel_function:
cmd = self._get_cmd(quiet=True)
if cmd:
try:
cmd.cancel()
except Exception as error:
self.fm.notify(error)
if self.last_cursor_mode is not None:
try:
curses.curs_set(self.last_cursor_mode)
#.........这里部分代码省略.........