コード例 #1
0
def set_completer(options=None):
    if options:
        completer = InputCompleter(options)
        readline.set_completer_delims('')
        readline.set_completer(completer.complete)
    else:
        readline.set_completer(None)
コード例 #2
0
ファイル: icmd.py プロジェクト: vitaliirat/mcplayeredit
	def __init__(self, rootclass, prompt='> ', histfile=os.path.join(os.environ.get('HOME', ''), '.icmd_hist'), welcometext='Type \'help\' for help.', helptext_prefix='The following commands are available:\n', helptext_suffix='\n(type \'help <command>\' for details)\n', batch=False):
		"""
		Create a new interactive commandline interface to rootclass by creating
		an instance of rootclass (your class must derive from ICmdBase). Use
		ICmd.run() or run_once() to start the commandline client. `batch`
		indicates wether to run in batch mode. If so, ICmd is silent (except
		for errors) and non-interactive; instead reading from stdin and
		executing each line as a command. It will exit after no more lines are
		available.
		"""
		self.rootclass = rootclass
		self.prompt = prompt
		self.welcometext = welcometext
		self.batch = batch
		self.histfile = histfile
		self.instclass = self.rootclass(helptext_prefix, helptext_suffix, self.batch)

		# Initialize readline, but only if we we're able to load the module.
		if 'readline' in sys.modules or 'pyreadline' in sys.modules:
			logging.info("Using readline")
			try:
				readline.read_history_file(self.histfile)
			except IOError:
				pass
			logging.info("Setting readline completer")
			readline.set_completer(self._completer)
			readline.parse_and_bind("tab: complete")

		if not self.batch:
			sys.stdout.write(welcometext + '\n')
コード例 #3
0
ファイル: tools.py プロジェクト: k0lter/pwman3
 def defaulter():
     """define default behavior startup"""
     if _readline_available:
         readline.insert_text(default)
     readline.set_startup_hook(defaulter)
     oldcompleter = readline.get_completer()
     readline.set_completer(completer)
コード例 #4
0
ファイル: keykit_console.py プロジェクト: YggdrasiI/Pyconsole
 def __init__(self, completer=None, shell=None, bBind=True):
     self.prefix = None
     self.shell = shell
     self.completer = \
         self.complete_advanced if completer is None else completer
     if bBind:
         readline.parse_and_bind('tab: complete')
         readline.set_completer(self.complete)
コード例 #5
0
ファイル: tools.py プロジェクト: k0lter/pwman3
def getinput(question, default="", completer=None, width=_defaultwidth):
    if not _readline_available:
        return raw_input(question.ljust(width))
    else:
        def defaulter():
            """define default behavior startup"""
            if _readline_available:
                readline.insert_text(default)
            readline.set_startup_hook(defaulter)
            oldcompleter = readline.get_completer()
            readline.set_completer(completer)

        x = raw_input(question.ljust(width))
        readline.set_completer(completer)
        readline.set_startup_hook()
        return x
コード例 #6
0
    def __read_input(self):

        readline.set_completer(rlcompleter.Completer(self.__vars).complete)
        readline.parse_and_bind("tab: complete")

        if os.path.exists(self.HistoryFile.value):
            readline.read_history_file(self.HistoryFile.value)

        while (True):
            try:
                line = raw_input('\001' + print_green + '\002' +
                                 self.Prompt.value + '\001' + print_reset +
                                 '\002')
                self.__input_queue.put(line)
            except:
                print "Exiting GuaVe, press Ctrl-C to kill guacamole..."
                #sys.exit(0)
                break
コード例 #7
0
    def __read_input(self):

        readline.set_completer(rlcompleter.Completer(self.__vars).complete)
        readline.parse_and_bind("tab: complete")

        if os.path.exists(self.HistoryFile.value):
            readline.read_history_file(self.HistoryFile.value)

        while True:
            try:
                line = input("\001" + print_green + "\002" + self.Prompt.value + "\001" + print_reset + "\002")
                self.__input_queue.put(line)
            except EOFError:
                print("Bye")  # , press Ctrl-C to kill guacamole...")
                os._exit(0)
            except IOError as err:
                print("I/O error: {0}".format(err))
                os._exit(1)
            except:
                print("Unexpected error:", sys.exc_info()[0])
                os._exit(1)
コード例 #8
0
    def __read_input(self):

        readline.set_completer(rlcompleter.Completer(self.__vars).complete)
        readline.parse_and_bind("tab: complete")

        if os.path.exists(self.HistoryFile.value):
            readline.read_history_file(self.HistoryFile.value)

        while (True):
            try:
                line = input('\001' + print_green + '\002' +
                             self.Prompt.value + '\001' + print_reset + '\002')
                self.__input_queue.put(line)
            except EOFError:
                print("Bye")  #, press Ctrl-C to kill guacamole...")
                os._exit(0)
            except IOError as err:
                print("I/O error: {0}".format(err))
                os._exit(1)
            except:
                print("Unexpected error:", sys.exc_info()[0])
                os._exit(1)
コード例 #9
0
ファイル: simul.py プロジェクト: TheBB/simul
                             'mcopy','detailcopy','perf']
        supported = {'all': ['save','load','compute','out','exit','change',\
                             'copy'],
                     match.Match: ['set','unset','list','image'],\
                     mslgroup.MSLGroup: composite_commands,\
                     sebracket.SEBracket: composite_commands,\
                     debracket.DEBracket: composite_commands,\
                     rrgroup.RRGroup: composite_commands,\
                     combination.Combination: composite_commands,\
                     ipl5.IPL5Bracket: composite_commands}

        words = supported['all'] + supported[type(obj)] + ['name','race','elo']
        completer = Completer(words)
        completer.add_words([p.name for p in obj.get_players()])
        readline.parse_and_bind("tab: complete")
        readline.set_completer(completer.complete)

        while True:
            s = better_input('> ').lower().split(' ')
            s = filter(lambda p: p != '', s)
            s = list(map(lambda p: p.strip(), s))
            if len(s) < 1:
                continue

            if s[0] not in supported['all'] and s[0] not in supported[type(obj)]:
                print('Invalid command for type \'' + str(type(obj)) + '\'')
                continue

            if s[0] == 'exit':
                break
コード例 #10
0
def link_prompt(links):
    readline.set_completer(make_completer(links))
    return raw_input('Enter link to follow (tab autocompletes): ')
コード例 #11
0
        else:
                os.environ['HOME'] = "C:\\"

histfile = os.path.join(os.environ["HOME"], ".mterm")

automatic_reload=False
if not pipedinput:
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass
    import atexit
    atexit.register(readline.write_history_file, histfile)
    
    automatic_reload=True
    readline.set_completer(mcomplete)
    readline.parse_and_bind("tab: complete")
    readline.set_completer_delims(' \t\n`!@#$^&*()=+[{]}|;:\'",<>?')

separator = "|"
allquote = False
beeping = False
db = ""
language, output_encoding = locale.getdefaultlocale()

if output_encoding==None:
    output_encoding='UTF8'

if len(sys.argv) >= 2:
    db = sys.argv[1]
    if db=="-q":
コード例 #12
0
ファイル: simul.py プロジェクト: alendit/simul
                             'mcopy','detailcopy','perf']
        supported = {'all': ['save','load','compute','out','exit','change',\
                             'copy'],
                     match.Match: ['set','unset','list','image'],\
                     mslgroup.MSLGroup: composite_commands,\
                     sebracket.SEBracket: composite_commands,\
                     debracket.DEBracket: composite_commands,\
                     rrgroup.RRGroup: composite_commands,\
                     combination.Combination: composite_commands,\
                     ipl5.IPL5Bracket: composite_commands}

        words = supported['all'] + supported[type(obj)] + ['name','race','elo']
        completer = Completer(words)
        completer.add_words([p.name for p in obj.get_players()])
        readline.parse_and_bind("tab: complete")
        readline.set_completer(completer.complete)

        while True:
            s = better_input('> ').lower().split(' ')
            s = filter(lambda p: p != '', s)
            s = list(map(lambda p: p.strip(), s))
            if len(s) < 1:
                continue

            if s[0] not in supported['all'] and s[0] not in supported[type(obj)]:
                print('Invalid command for type \'' + str(type(obj)) + '\'')
                continue

            if s[0] == 'exit':
                break
コード例 #13
0
ファイル: mterm.py プロジェクト: sofiakarb/exareme
        os.environ['HOME'] = "C:\\"

histfile = os.path.join(os.environ["HOME"], ".mterm")

automatic_reload = False
if not pipedinput:
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass
    import atexit

    atexit.register(readline.write_history_file, histfile)

    automatic_reload = True
    readline.set_completer(mcomplete)
    readline.parse_and_bind("tab: complete")
    readline.set_completer_delims(' \t\n`!@#$^&*()=+[{]}|;:\'",<>?')

separator = "|"
allquote = False
beeping = False
db = ""
language, output_encoding = locale.getdefaultlocale()

if output_encoding == None:
    output_encoding = 'UTF8'

functions.variables.flowname = 'main'

rawprinter = buildrawprinter(separator)