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 __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 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 curses.error: pass self.allow_close = False self.tab_deque = None 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('') self.wait_for_command_input = True return True
def __init__(self, path): self.thisdir = None # Current Working Directory self._thisfile = None # Current File self.history = History(self.settings.max_history_size, unique=False) self.last_search = None self.pointer = 0 self.path = abspath(expanduser(path)) self.pathway = () # NOTE: in the line below, weak=True works only in python3. In python2, # weak references are not equal to the original object when tested with # "==", and this breaks _set_thisfile_from_signal and _on_tab_change. self.fm.signal_bind('move', self._set_thisfile_from_signal, priority=0.1, weak=(sys.version > '3')) self.fm.signal_bind('tab.change', self._on_tab_change, weak=(sys.version > '3'))
def add_to_history(self): self.history_backup.fast_forward() self.history_backup.add(self.line) self.history = History(self.history_backup)