Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 11
0
 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)
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 24
0
Arquivo: cli.py Projeto: obfusk/jiten
 def save_hist():
     newlen = readline.get_current_history_length() - origlen
     if newlen:
         pathlib.Path(HISTFILE).touch()
         readline.append_history_file(newlen, HISTFILE)
Exemplo n.º 25
0
def _save_history() -> None:
    """
	Saves the current terminal history to the history file.
	"""
    readline.append_history_file(HISTORY_LENGTH, HISTORY_FILE)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 29
0
 def saveHistory(prevHistoryLen, histfile):
     newHistoryLen = readline.get_current_history_length()
     readline.set_history_length(1000)
     readline.append_history_file(newHistoryLen - prevHistoryLen,
                                  histfile)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)