示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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))
示例#5
0
 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)
示例#6
0
    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)
示例#7
0
 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)
示例#8
0
    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 = 'on'
        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 = ">>> "

        # 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 = []
示例#9
0
    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
        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
示例#10
0
 def add_history(self, text):
     self._history.add_history(lineobj.ReadLineTextBuffer(text))
示例#11
0
 def __init__(self):
     self.l_buffer = lineobj.ReadLineTextBuffer("")
     self._history = history.LineHistory()
示例#12
0
 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)
示例#13
0
            (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")