Ejemplo n.º 1
0
    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 = []
Ejemplo n.º 2
0
    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 = []
Ejemplo n.º 3
0
    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 = []
Ejemplo n.º 4
0
    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 Exception:
                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 = []
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def destroy(self):
     # save history to files
     if ranger.args.clean or not self.settings.save_console_history:
         return
     if self.historypath:
         try:
             with open(self.historypath, 'w') as fobj:
                 for entry in self.history_backup:
                     try:
                         fobj.write(entry + '\n')
                     except UnicodeEncodeError:
                         pass
         except (OSError, IOError) as ex:
             self.fm.notify("Failed to write history file",
                            bad=True,
                            exception=ex)
     Widget.destroy(self)
Ejemplo n.º 7
0
 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()
     Widget.destroy(self)
Ejemplo n.º 8
0
 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 Exception:
             pass
         else:
             for entry in self.history_backup:
                 try:
                     f.write(entry + '\n')
                 except UnicodeEncodeError:
                     pass
             f.close()
     Widget.destroy(self)