Beispiel #1
0
 def save():
     newhlen = readline.get_current_history_length()
     l = newhlen - hlen
     if hasattr(readline, "append_history_file"):
         readline.append_history_file(l, history)
     else:
         readline.write_history_file(history)
Beispiel #2
0
def save(prev_h_len, hfile):
    '''
    append to histfile
    '''
    new_h_len = readline.get_current_history_length()
    readline.set_history_length(1000)
    readline.append_history_file(new_h_len - prev_h_len, hfile)
Beispiel #3
0
def main():
    args = parse_args()
    builtins.verbose = args.verbose
    if builtins.verbose:
        print(f'Verbose mode {builtins.verbose} enabled')

    if args.filename:
        with open(args.filename, 'r') as file:
            for line in file:
                parser.parse(line)
        return

    historypath = os.path.expanduser('~/.mythhistory')

    if not os.path.exists(historypath):
        open(historypath, 'a').close()

    readline.read_history_file(historypath)

    while True:
        try:
            s = input('myth> ')
            if s:
                readline.append_history_file(1, historypath)
                parser.parse(s)
        except EOFError:
            break
        except Exception as e:
            if builtins.verbose > 1:
                raise e
            print(e)
            print()
Beispiel #4
0
    def run(self):
        exit = False
        cmd = ""

        while exit != True:
            cmd = input("> ")
            exit = self.handler(cmd + "\n")

        readline.append_history_file(self.history_length, self.history_name)
Beispiel #5
0
def save(prev_h_len, histfile):
    """Save the history file on exit."""
    readline.set_history_length(1000)

    if hasattr(readline, 'append_history_file'):
        new_h_len = readline.get_history_length()
        # py 3.5+
        readline.append_history_file(new_h_len - prev_h_len, histfile)
    else:
        readline.write_history_file(histfile)
Beispiel #6
0
def save(prev_h_len, histfile):
    """Save the history file on exit."""
    readline.set_history_length(1000)

    if hasattr(readline, 'append_history_file'):
        new_h_len = readline.get_history_length()
        # py 3.5+
        readline.append_history_file(new_h_len - prev_h_len, histfile)
    else:
        readline.write_history_file(histfile)
Beispiel #7
0
    def _update_history(entry):
        try:
            readline.add_history(entry)

            es_history = Shell._get_history_file()
            log.d(f"Updating history at: '{es_history}' - adding '{entry}'")
            try:
                readline.append_history_file(1, es_history)
            except:
                pass
        except OSError as e:
            log.w(f"Failed to write to history file: {e}")
def save(prev_h_len, histfile):
    """Save history."""
    new_h_len = readline.get_current_history_length()
    # default history len is -1 (infinite), which may grow unruly
    readline.set_history_length(1000)
    if sys.version_info.major >= 3:
        # python3
        readline.append_history_file(new_h_len - prev_h_len, histfile)
    elif sys.version_info.major == 2:
        # python2
        readline.write_history_file(histfile)
    else:
        pass
Beispiel #9
0
def save(prev_h_len, f):
    import readline

    new_h_len = readline.get_current_history_length()
    readline.set_history_length(1000)

    try:
        readline.append_history_file(new_h_len - prev_h_len, f)
    except:
        # Python2 doesn't support append_history_file
        readline.write_history_file(f)

    del readline
Beispiel #10
0
 def _input(self, prompt):
     response = input(prompt)
     try:
         cls_, method = response[:response.index("(")].split(".")
         cls_ = getattr(self, cls_)
         method = getattr(cls_, method)
         if hasattr(method, "_private"):
             readline.replace_history_item(
                 readline.get_current_history_length() - 1,
                 response[:response.index("(")] + "()"
             )
     except (ValueError, AttributeError):
         pass
     readline.append_history_file(1, "build/.history")
     return response
 def wrap_history(self):
     '''Loads history at startup and saves history on exit.'''
     readline.set_auto_history(False)
     try:
         if self.history_file:
             readline.read_history_file(self.history_file)
         h_len = readline.get_current_history_length()
     except FileNotFoundError:
         h_len = 0
     try:
         yield
     finally:
         new_items = readline.get_current_history_length() - h_len
         if new_items > 0 and self.history_file:
             open(self.history_file, 'a').close()
             readline.append_history_file(new_items, self.history_file)
Beispiel #12
0
 def try_to_write_history(self, history_dir: Optional[str] = None) -> None:
     history_file = self._prep_history_file(history_dir)
     try:
         import readline
     except ImportError:
         # Windows doesn't have readline, so gracefully ignore.
         pass
     else:
         current_history_length = readline.get_current_history_length()
         new_history_length = current_history_length - self._initial_history_length
         if new_history_length < 0:
             raise Exception(
                 f"Unable to write new history. Length is less than 0. ({current_history_length} - {self._initial_history_length})"
             )
         else:
             # append will fail if the file does not exist.
             readline.append_history_file(new_history_length, history_file)
Beispiel #13
0
def main(database_path):
    """
    The interactive prompt loop for GameDB

    Parameters
    ----------
    database_path : str
        the path to pass to `sqlite.connect()`
    """
    gamedb = GameDB(database_path, parser_cls=GameDBCommandParser)

    # Load command history from file or create it if it doesn't exist
    try:
        readline.read_history_file(histfile)
    except FileNotFoundError:
        open(histfile, "wb").close()

    # Set maximum command history length
    readline.set_history_length(1000)

    # Suppress the fancy prompt if not being run interactively
    prompt = "gamedb> " if sys.stdin.isatty() else ""

    while True:
        try:
            line = input(prompt).lstrip()
        except EOFError:
            break
        finally:
            readline.append_history_file(1, histfile)

        if line:
            try:
                gamedb.parser.parse(line)
            except pp.ParseBaseException as e:
                print_err("Invalid input:\n" + pretty_print_parser_error(e))
Beispiel #14
0
def save(previous_length, history):
    new_length = readline.get_current_history_length()
    readline.set_history_length(history_size)
    readline.append_history_file(new_length - previous_length, history)
Beispiel #15
0
 def append_history(n, f):
     newlines = readline.get_current_history_length()
     readline.set_history_length(1000)
     readline.append_history_file(newlines - n, f)
Beispiel #16
0
def save_history(previous_length, hist_file):
    current_length = readline.get_current_history_length()
    length = current_length - previous_length
    readline.append_history_file(
        length, hist_file)  # only append new history of this session
Beispiel #17
0
def save(prev_len, file):
    """Save history file."""
    new_h_len = readline.get_current_history_length()
    readline.set_history_length(1000)
    readline.append_history_file(new_h_len - prev_len, file)
Beispiel #18
0
def save_hist(prev_hist_len, hist_file):
    new_hist_len = readline.get_current_history_length()
    readline.set_history_length(1000)
    readline.append_history_file(new_hist_len - prev_hist_len, hist_file)
Beispiel #19
0
def save(prev_h_len, histfile):
    new_h_len = readline.get_current_history_length()
    # default history len is -1 (infinite), which may grow unruly
    readline.set_history_length(1000)
    readline.append_history_file(new_h_len - prev_h_len, histfile)
Beispiel #20
0
 def append_history(len_at_start):
     current_len = readline.get_current_history_length()
     readline.append_history_file(current_len - len_at_start,
                                  config.HISTFILE)
Beispiel #21
0
def save(prev_h_len, histfile):
    new_h_len = readline.get_current_history_length()
    # Make the history file much bigger for relative suggestions
    readline.set_history_length(int(os.getenv("HISTSIZE", 1000000)))
    readline.append_history_file(new_h_len - prev_h_len, histfile)
Beispiel #22
0
def save(previous_length, history):
    new_length = readline.get_current_history_length()
    readline.set_history_length(history_size)
    readline.append_history_file(new_length - previous_length, history)
Beispiel #23
0
def save_history(start_index: int, length: int, histfile: Path) -> None:
    end_index = readline.get_current_history_length()
    readline.set_history_length(length)
    readline.append_history_file(end_index - start_index, histfile)
Beispiel #24
0
 def save_hist():
     newlen = readline.get_current_history_length() - origlen
     if newlen:
         pathlib.Path(HISTFILE).touch()
         readline.append_history_file(newlen, HISTFILE)
Beispiel #25
0
def _save_history() -> None:
    """
	Saves the current terminal history to the history file.
	"""
    readline.append_history_file(HISTORY_LENGTH, HISTORY_FILE)
Beispiel #26
0
        if ex.parser is not None:
            ex.parser.print_usage()
        print(ex.message)


if __name__ == "__main__":
    args = parser.parse_args()
    wib = WIB(args.wib_server)
    if args.command is None:
        import readline
        hist_file = os.path.expanduser('~/.wib_client_hist')
        if os.path.exists(hist_file):
            readline.read_history_file(hist_file)
        else:
            open(hist_file, 'w').close()
        hist_start = readline.get_current_history_length()
        while True:
            try:
                line = input('[%s] >> ' % args.wib_server).strip()
                handle_args(shlex.split(line))
            except KeyboardInterrupt:
                print()
                continue
            except EOFError:
                print()
                break
        hist_end = readline.get_current_history_length()
        readline.append_history_file(hist_end - hist_start, hist_file)
    else:
        handle_args([args.command] + args.args)
Beispiel #27
0
 def save(prev_h_len, histfile):
     new_h_len = readline.get_history_length()
     readline.set_history_length(1000)
     readline.append_history_file(new_h_len - prev_h_len, histfile)
Beispiel #28
0
def save_hist(prev_h_len, histfile):
    new_hlen = rl.get_current_history_length()
    rl.set_history_length(1000)
    rl.append_history_file(new_hlen - prev_h_len, histfile)
Beispiel #29
0
 def saveHistory(prevHistoryLen, histfile):
     newHistoryLen = readline.get_current_history_length()
     readline.set_history_length(1000)
     readline.append_history_file(newHistoryLen - prevHistoryLen,
                                  histfile)
Beispiel #30
0
def saveHistory(prevHistoryLen, filePath):
    logger.debug('Entering saveHistory')
    newHistoryLen = readline.get_history_length()
    logger.debug('{} {}'.format(newHistoryLen, prevHistoryLen))
    readline.set_history_length(1000)
    readline.append_history_file(newHistoryLen - prevHistoryLen, filePath)
Beispiel #31
0
 def save_history(prev_history_length, historyfile):
     new_history_length = readline.get_current_history_length()
     readline.set_history_length(1000)
     readline.append_history_file(
         new_history_length - prev_history_length, historyfile)
Beispiel #32
0
def save(prev_h_len, histfile):
    new_h_len = readline.get_current_history_length()
    readline.set_history_length(1000)
    readline.append_history_file(new_h_len - prev_h_len, histfile)