def test_StartOfLine(self): t = self.t l = lineobj.ReadLineTextBuffer(t, point=len(t)) for i in range(len(t)): l.point = i l.point = lineobj.StartOfLine self.assertEqual(0, l.point)
def __init__(self, rlobj): self.argument = 0 self.rlobj = rlobj self.exit_dispatch = {} self.key_dispatch = {} self.argument = 1 self.prevargument = None self.l_buffer = lineobj.ReadLineTextBuffer('') self._history = history.LineHistory() self.completer_delims = ' \t\n"\\\'`@$><=;|&{(' self.show_all_if_ambiguous = 'off' self.mark_directories = 'on' self.complete_filesystem = 'off' self.completer = None self.begidx = 0 self.endidx = 0 self.tabstop = 4 self.startup_hook = None self.pre_input_hook = None self.first_prompt = True self.cursor_size = 25 self.prompt = '>>> ' self.enable_ipython_paste_for_paths = True self.enable_ipython_paste_list_of_lists = True self.enable_win32_clipboard = True self.paste_line_buffer = [] self._sub_modes = [] return
def _readline_from_keyboard_poll(self): pastebuffer = self.mode.paste_line_buffer if len(pastebuffer) > 0: self.l_buffer = lineobj.ReadLineTextBuffer(pastebuffer[0]) self._update_line() self.mode.paste_line_buffer = pastebuffer[1:] return True c = self.console def nop(e): pass try: event = c.getkeypress() except KeyboardInterrupt: event = self.handle_ctrl_c() try: result = self.mode.process_keyevent(event.keyinfo) except EOFError: logger.stop_logging() raise self._update_line() return result
def __init__(self, rlobj): self.argument = 0 self.rlobj = rlobj self.exit_dispatch = {} self.key_dispatch = {} self.argument = 1 self.prevargument = None self.l_buffer = lineobj.ReadLineTextBuffer("") self._history = history.LineHistory() self.completer_delims = u" \t\n\"\\'`@$><=;|&{(" self.show_all_if_ambiguous = u'off' self.mark_directories = u'on' self.completer = None self.begidx = 0 self.endidx = 0 self.tabstop = 4 self.startup_hook = None self.pre_input_hook = None self.first_prompt = True self.cursor_size = 25 self.prompt = u">>> " #Paste settings #assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n #and replace \ with / for easier use in ipython self.enable_ipython_paste_for_paths = True #automatically convert tabseparated data to list of lists or array constructors self.enable_ipython_paste_list_of_lists = True self.enable_win32_clipboard = True self.paste_line_buffer = [] self._sub_modes = []
def test_NextChar(self): t = self.t l = lineobj.ReadLineTextBuffer(t) for i in range(len(t)): self.assertEqual(i, l.point) l.point = lineobj.NextChar #advance past end of buffer l.point = lineobj.NextChar self.assertEqual(len(t), l.point)
def test_PrevChar(self): t = self.t l = lineobj.ReadLineTextBuffer(t, point=len(t)) for i in range(len(t)): self.assertEqual(len(t) - i, l.point) l.point = lineobj.PrevChar #advance past beginning of buffer l.point = lineobj.PrevChar self.assertEqual(0, l.point)
def test_Point(self): cmd = lineobj.Point tests = [ # "First Second Third" (cmd, "First Second Third", 0), (cmd, "First Second Third", 12), (cmd, "First Second Third", 18), ] for cmd, text, p in tests: l = lineobj.ReadLineTextBuffer(text, p) self.assertEqual(p, cmd(l))
def test_PrevChar(self): cmd = lineobj.PrevChar tests = [ # "First" (cmd, "First", " #", " # "), (cmd, "First", " # ", "# "), (cmd, "First", "# ", "# "), ] for cmd, text, init_point, expected_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) l.point = cmd self.assertEqual(get_point_pos(expected_point), l.point)
def test_WordStart_2(self): cmd = lineobj.WordStart tests = [ # "First Second Third" (cmd, "First Second Third", " # "), (cmd, "First Second Third", " # "), (cmd, "First Second Third", " #"), ] for cmd, text, init_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) self.assertRaises(lineobj.NotAWordError, cmd, l)
def __init__( self, rlobj, argument=1, prevargument=None, show_all_if_ambiguous="on", mark_directories="on", complete_filesystem="off", completer=None, begidx=0, endidx=0, tabstop=4, ): """Initialize the class. Still adding more keyword arguments. Parameters ---------- TODO """ self.rlobj = rlobj self.exit_dispatch = {} self.key_dispatch = {} self.argument = argument self.prevargument = prevargument self.l_buffer = lineobj.ReadLineTextBuffer("") self._history = history.LineHistory() self.completer_delims = r" \t\n\"\\'`@$><=;|&{(" self.show_all_if_ambiguous = show_all_if_ambiguous self.mark_directories = mark_directories self.complete_filesystem = complete_filesystem self.completer = completer self.begidx = begidx self.endidx = endidx self.tabstop = tabstop self.startup_hook = None self.pre_input_hook = None self.first_prompt = True self.cursor_size = 25 self.prompt = ">>> " # Paste settings # assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n # and replace \ with / for easier use in ipython self.enable_ipython_paste_for_paths = True # automatically convert tabseparated data to list of lists or array constructors self.enable_ipython_paste_list_of_lists = True self.enable_win32_clipboard = True self.paste_line_buffer = [] self._sub_modes = []
def __init__(self): self.startup_hook = None self.pre_input_hook = None self.completer = None self.completer_delims = " \t\n\"\\'`@$><=;|&{(" self.console = console.Console() self.size = self.console.size() self.prompt_color = None self.command_color = None self.selection_color = self.console.saveattr<<4 self.key_dispatch = {} self.previous_func = None self.first_prompt = True self.next_meta = False # True to force meta on next character self.tabstop = 4 self.allow_ctrl_c=False self.ctrl_c_tap_time_interval=0.3 self.debug=False self.begidx = 0 self.endidx = 0 # variables you can control with parse_and_bind self.show_all_if_ambiguous = 'off' self.mark_directories = 'on' self.bell_style = 'none' self.mark=-1 self.l_buffer=lineobj.ReadLineTextBuffer("") self._history=history.LineHistory() # this code needs to follow l_buffer and history creation self.editingmodes=[mode(self) for mode in editingmodes] for mode in self.editingmodes: mode.init_editing_mode(None) self.mode=self.editingmodes[0] self.read_inputrc() log("\n".join(self.rl_settings_to_string())) #Paste settings #assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n #and replace \ with / for easier use in ipython self.enable_ipython_paste_for_paths=True #automatically convert tabseparated data to list of lists or array constructors self.enable_ipython_paste_list_of_lists=True self.enable_win32_clipboard=True self.paste_line_buffer=[] self.callback = None
def test_EndOfLine(self): cmd = lineobj.EndOfLine tests = [ # "First Second Third" (cmd, "First Second Third", "# ", " #"), (cmd, "First Second Third", " # ", " #"), (cmd, "First Second Third", " #", " #"), ] for cmd, text, init_point, expected_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) l.point = cmd self.assertEqual(get_point_pos(expected_point), l.point)
def test_WordStart_1(self): cmd = lineobj.WordStart tests = [ # u"First Second Third" (cmd, u"First Second Third", u"# u", u"# u"), (cmd, u"First Second Third", u" # u", u"# u"), (cmd, u"First Second Third", u" # u", u" # u"), ] for cmd, text, init_point, expected_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) l.point = cmd self.assertEqual(get_point_pos(expected_point), l.point)
def readline(self, prompt=''): c = self.console self.readline_setup(prompt) log("in readline: %s" % self.paste_line_buffer) if len(self.paste_line_buffer) > 0: self.l_buffer = lineobj.ReadLineTextBuffer( self.paste_line_buffer[0]) self._update_line() self.paste_line_buffer = self.paste_line_buffer[1:] else: self._readline_from_keyboard() c.write('\r\n') self.add_history(self.l_buffer.copy()) log('returning(%s)' % self.l_buffer.get_line_text()) return self.l_buffer.get_line_text() + '\n'
def readline(self, prompt=''): '''Try to act like GNU readline.''' # handle startup_hook self.ctrl_c_timeout = time.time() self.l_buffer.selection_mark = -1 if self.first_prompt: self.first_prompt = False if self.startup_hook: try: self.startup_hook() except: print 'startup hook failed' traceback.print_exc() c = self.console self.l_buffer.reset_line() self.prompt = prompt self._print_prompt() if self.pre_input_hook: try: self.pre_input_hook() except: print 'pre_input_hook failed' traceback.print_exc() self.pre_input_hook = None log("in readline: %s" % self.paste_line_buffer) if len(self.paste_line_buffer) > 0: self.l_buffer = lineobj.ReadLineTextBuffer( self.paste_line_buffer[0]) self._update_line() self.paste_line_buffer = self.paste_line_buffer[1:] c.write('\r\n') else: self._readline_from_keyboard() c.write('\r\n') self.add_history(self.l_buffer.copy()) log('returning(%s)' % self.l_buffer.get_line_text()) return self.l_buffer.get_line_text() + '\n'
def _readline_from_keyboard_poll(self): pastebuffer = self.mode.paste_line_buffer if len(pastebuffer) > 0: #paste first line in multiline paste buffer self.l_buffer = lineobj.ReadLineTextBuffer(pastebuffer[0]) self._update_line() self.mode.paste_line_buffer = pastebuffer[1:] return True c = self.console def nop(e): pass shouldUpdateLine = True try: event = c.getkeypress() log("Got event %s is printable=%s more events=%s" % (event, event.keyinfo.isPrintable(), c.more_events_pending())) if c.more_events_pending() and event.keyinfo.isPrintable(): log("don't update line char=" + event.char) shouldUpdateLine = False except KeyboardInterrupt: event = self.handle_ctrl_c() try: result = self.mode.process_keyevent(event.keyinfo) except EOFError: logger.stop_logging() raise if shouldUpdateLine: if self.mode.shouldUpdateLine(): self._update_line() else: # just move cursor self._set_cursor() return result
def __init__(self, rlobj, *args, **kwargs): self.l_buffer = lineobj.ReadLineTextBuffer("") super().__init__(rlobj, *args, **kwargs)
def test_copy2(self): l = lineobj.ReadLineTextBuffer("first second", point=5) q = l.copy() self.assertEqual(q.get_line_text(), l.get_line_text()) self.assertEqual(q.point, l.point) self.assertEqual(q.mark, l.mark)
(cmd, "First Second Third", 0), (cmd, "First Second Third", 12), (cmd, "First Second Third", 18), ] for cmd, text, p in tests: l = lineobj.ReadLineTextBuffer(text, p) self.assertEqual(p, cmd(l)) #---------------------------------------------------------------------- # utility functions def get_point_pos(pstr): return pstr.index("#") def get_mark_pos(mstr): try: return mstr.index("#") except ValueError: return -1 #---------------------------------------------------------------------- if __name__ == '__main__': unittest.main() l = lineobj.ReadLineTextBuffer("First Second Third")
def add_history(self, text): self._history.add_history(lineobj.ReadLineTextBuffer(text))
def __init__(self): self.l_buffer = lineobj.ReadLineTextBuffer(u"") self._history = history.LineHistory()