Exemple #1
0
 def _init_history_file(self):
     if hasattr(readline, "read_history_file"):
         try:
             readline.read_history_file(self.history_file)
         except FileNotFoundError:
             pass
         atexit.register(self.save_history)
Exemple #2
0
 def _init_history_file(self):
     if hasattr(readline, "read_history_file"):
         try:
             readline.read_history_file(self.history_file)
         except FileNotFoundError:
             pass
         atexit.register(self.save_history)
Exemple #3
0
 def preloop(self):
     ''' Keep persistent command history. '''
     if not self.already_prelooped:
         self.already_prelooped = True
         open('.psiturk_history', 'a').close()  # create file if it doesn't exist
         readline.read_history_file('.psiturk_history')
         for i in range(readline.get_current_history_length()):
             if readline.get_history_item(i) is not None:
                 self.history.append(readline.get_history_item(i))
Exemple #4
0
 def init_history(self, histfile):
     import gnureadline as readline
     #        readline.parse_and_bind("tab: complete")
     if hasattr(readline, "read_history_file"):
         try:
             readline.read_history_file(histfile)
         except IOError:
             pass
         atexit.register(self.save_history, histfile)
Exemple #5
0
 def preloop(self):
     ''' Keep persistent command history. '''
     if not self.already_prelooped:
         self.already_prelooped = True
         open('.psiturk_history', 'a').close()  # create file if it doesn't exist
         readline.read_history_file('.psiturk_history')
         for i in range(readline.get_current_history_length()):
             if readline.get_history_item(i) is not None:
                 self.history.append(readline.get_history_item(i))
Exemple #6
0
def enable_history():
    # tab completion
    readline.parse_and_bind('tab: complete')
    # history file
    histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass
    atexit.register(readline.write_history_file, histfile)
    del os, histfile, readline, rlcompleter
    def _load_history(self):
        """Load history file and register dump on exit."""

        # Create a file without truncating it in case it exists.
        open(config.history_path, 'a').close()

        readline.set_history_length(100)
        try:
            readline.read_history_file(config.history_path)
        except IOError:
            pass
        atexit.register(readline.write_history_file, config.history_path)
Exemple #8
0
    def preloop(self):
        delims = set(readline.get_completer_delims())
        for d in "%*-/":
            try:
                delims.remove(d)
            except KeyError:
                pass
        readline.set_completer_delims(''.join(delims))

        try:
            readline.read_history_file(self.HISTORY_FILE)
        except (OSError, IOError) as e:
            warn("Can't read history file")
Exemple #9
0
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Max history file length:', readline.get_history_length())
    print('Startup history:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" to quit): ')
            if line == 'stop':
                break
            if line:
                print('Adding {!r} to the history'.format(line))
    finally:
        print('Final history:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Lunghezza max file storico:',
          readline.get_history_length())
    print('Storico di partenza:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" per uscire): ')
            if line == 'stop':
                break
            if line:
                print('Aggiunta di {!r} allo storico'.format(line))
    finally:
        print('Storico finale:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
def input_loop():
    if os.path.exists(HISTORY_FILENAME):
        readline.read_history_file(HISTORY_FILENAME)
    print('Max history file length:',
          readline.get_history_length())
    print('Startup history:', get_history_items())
    try:
        while True:
            line = input('Prompt ("stop" to quit): ')
            if line == 'stop':
                break
            if line:
                print('Adding {!r} to the history'.format(line))
    finally:
        print('Final history:', get_history_items())
        readline.write_history_file(HISTORY_FILENAME)
Exemple #12
0
    def setup(self):
        """ Initialization of third-party libraries

        Setting interpreter history.
        Setting appropriate completer function.

        :return:
        """
        if not os.path.exists(self.history_file):
            open(self.history_file, 'a+').close()

        readline.read_history_file(self.history_file)
        readline.set_history_length(self.history_length)
        atexit.register(readline.write_history_file, self.history_file)

        readline.parse_and_bind('set enable-keypad on')

        readline.set_completer(self.complete)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
Exemple #13
0
        def __init__(self):
            if HAVE_READLINE:
                readline.parse_and_bind("tab: complete")
                # force completor to run on first tab press
                readline.parse_and_bind("set show-all-if-unmodified on")
                readline.parse_and_bind("set show-all-if-ambiguous on")
                # Set our custom completer
                readline.set_completer(self.completer)

                try:
                    readline.read_history_file(HIST_FILE)
                except IOError:
                    pass

            self._idle = threading.Event()
            self._cond = threading.Condition()
            self._response = None
            self._completor_locals = []

            super(REPLApplication, self).__init__(self._process_input)
Exemple #14
0
    def setup(self):
        """ Initialization of third-party libraries

        Setting interpreter history.
        Setting appropriate completer function.

        :return:
        """
        if not os.path.exists(self.history_file):
            open(self.history_file, 'a+').close()

        readline.read_history_file(self.history_file)
        readline.set_history_length(self.history_length)
        atexit.register(readline.write_history_file, self.history_file)

        readline.parse_and_bind('set enable-keypad on')

        readline.set_completer(self.complete)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
Exemple #15
0
        def __init__(self):
            if HAVE_READLINE:
                readline.parse_and_bind("tab: complete")
                # force completor to run on first tab press
                readline.parse_and_bind("set show-all-if-unmodified on")
                readline.parse_and_bind("set show-all-if-ambiguous on")
                # Set our custom completer
                readline.set_completer(self._completer)

                try:
                    readline.read_history_file(HIST_FILE)
                except IOError:
                    pass

            self._script = None
            self._seqno = 0
            self._ready = threading.Event()
            self._response_cond = threading.Condition()
            self._response_data = None
            self._completor_locals = []

            super(REPLApplication, self).__init__(self._process_input)
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it:  "export PYTHONSTARTUP=/home/user/.pystartup" in bash.
#
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.

import atexit
import os
import gnureadline
import rlcompleter

historyPath = os.path.expanduser("~/.dotfiles/data/pyhistory")

def save_history(historyPath=historyPath):
    import gnureadline
    gnureadline.write_history_file(historyPath)

if os.path.exists(historyPath):
    gnureadline.read_history_file(historyPath)

atexit.register(save_history)

# To use tab instead of ESC
# gnureadline.parse_and_bind('tab:complete')

# del os, atexit, gnureadline, rlcompleter, save_history, historyPath
Exemple #17
0
 def init_readline(self):
     readline.parse_and_bind('tab: complete')
     readline.set_completer(complete)
     readline.set_completer_delims(' \t')
     self.init_history_file()
     readline.read_history_file(self.history)
Exemple #18
0
import sys

try:
    import gnureadline as readline
except ImportError:
    import readline

## ===== Interactive shell history ====================== ##

if 1:
    # History file located in ~/.config dir
    _HISTFILE = os.path.join(os.getenv('HOME'), '.config/.python_history')

    # Read history file
    if os.path.exists(_HISTFILE):
        readline.read_history_file(_HISTFILE)

    # Set history file location
    def save_hist():
        readline.write_history_file(_HISTFILE)

    readline.set_history_length(1000)
    atexit.register(save_hist)
    del save_hist

## ===== Prompt ========================================= ##


def ascii_escape(body):
    return '\001\033[%sm\002' % body
Exemple #19
0
import atexit
import os
import sys
import gnureadline as readline

# Enable Tab Completion
# OSX's bind should only be applied with legacy readline.
if sys.platform == 'darwin' and 'libedit' in readline.__doc__:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")

# Enable History File
history_file = os.environ.get(
    "PYTHON_HISTORY_FILE", os.path.join(os.environ['HOME'], '.pythonhistory')
)

if os.path.isfile(history_file):
    readline.read_history_file(history_file)
else:
    open(history_file, 'a').close()

atexit.register(readline.write_history_file, history_file)
print("Initialized python REPL using {}".format(__file__))
Exemple #20
0
        res = matches[state]
    except:
        res = None

    return res


readline.set_completer(complete)
readline.parse_and_bind("tab: complete")
readline.set_history_length(-1)
hfn = os.path.expanduser("~/.dnash_history")

if not os.path.isfile(hfn):
    os.mknod(hfn)

readline.read_history_file(hfn)


def save_history():
    readline.write_history_file(hfn)


atexit.register(save_history)

print("Try 'help' to get started")

running = True
while running:
    try:
        lines = input("> ")
    except:
Exemple #21
0
import subprocess
import sys

try:
    import gnureadline as readline
except ImportError:
    import readline

## ===== Interactive shell history ====================== ##

# History file located in ~/.config dir
_HISTFILE = os.path.join(os.getenv('HOME'), '.config/.python_history')

# Read history file
if os.path.exists(_HISTFILE):
    readline.read_history_file(_HISTFILE)

# Set history file location
def save_hist():
    readline.write_history_file(_HISTFILE)
readline.set_history_length(1000)
atexit.register(save_hist)
del save_hist


## ===== Prompt ========================================= ##

def ascii_escape(body):
    return '\001\033[%sm\002' % body
class Prompt(object):
    cCyan = ascii_escape('0;36')
import collections
import time
import os
import os.path
import platform
if platform.system() in ["Darwin"]:
    # Mac OS is dumb and uses netbsd's readline, so we need to import a
    # different lib
    import gnureadline as readline
else:
    import readline

readline.parse_and_bind("tab: complete")
history_path = os.path.expanduser("~/.vision_history")
try:
    readline.read_history_file(history_path)
except IOError as ioe:
    if ioe.errno == 2:
        # The file wasn't there, make it and try again
        open(history_path, 'w+').write('')
        readline.read_history_file(history_path)

# MIE libraries
import visionparser
import visionexceptions

"""
Vision Scanner

This defines the keywords, seperators, scope indicators, etc of the
Vision language.  It takes a filish input which iterates over its input
from query.parser import DatabaseREPL
from query import davisbase_constants as dc
import gnureadline as readline
import pathlib, sys

hist_file = str(pathlib.Path.home()) + '/.davisdb_history'
open(hist_file, 'a+').close()

readline.read_history_file(hist_file)

if __name__ == '__main__':
    if not sys.stdin.isatty():
        dc.PROMPT_NAME = ''
        dc.PROMPT_MORE = ''

    prompt = DatabaseREPL()
    prompt.cmdloop_with_keyboard_interrupt()
    readline.write_history_file(hist_file)