コード例 #1
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_fmt_strings_remain_unchanged_when_used_to_construct_other_ones(self):
     a = fmtstr('hi', 'blue')
     b = fmtstr('there', 'red')
     c = a + b
     d = green(c)
     self.assertEqual(a.shared_atts['fg'], FG_COLORS['blue'])
     self.assertEqual(b.shared_atts['fg'], FG_COLORS['red'])
コード例 #2
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_right_sequence_in_py3(self):
     red_on_blue = fmtstr('hello', 'red', 'on_blue')
     blue_on_red = fmtstr('there', fg='blue', bg='red')
     green_s = fmtstr('!', 'green')
     full = red_on_blue + ' ' + blue_on_red + green_s
     self.assertEqual(full, on_blue(red("hello"))+" "+on_red(blue("there"))+green("!"))
     self.assertEqual(str(full), '\x1b[31m\x1b[44mhello\x1b[49m\x1b[39m \x1b[34m\x1b[41mthere\x1b[49m\x1b[39m\x1b[32m!\x1b[39m')
コード例 #3
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_funny_chars(self):
     fmtstr('⁇', 'blue')
     fmtstr(u'⁇', 'blue')
     fmtstr(u'⁇', 'blue')
     str(fmtstr('⁇', 'blue'))
     str(fmtstr(u'⁇', 'blue'))
     unicode(fmtstr('⁇', 'blue'))
     unicode(fmtstr(u'⁇', 'blue'))
     self.assertTrue(True)
コード例 #4
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_multiple_bfs_insert(self):
     self.assertEqual(fmtstr('a') + blue('b'),
                      on_blue(' '*2).insert(fmtstr('a')+blue('b'), 0, 2))
     self.assertEqual(on_red('yo') + on_blue('   '),
                      on_blue(' '*5).insert(on_red('yo'), 0, 2))
     self.assertEqual(' ' + on_red('yo') + on_blue('   '),
                      on_blue(' '*6).insert(' ' + on_red('yo'), 0, 3))
     self.assertEqual(on_blue("hey") + ' ' + on_red('yo') + on_blue('   '),
                      on_blue(' '*9).insert(on_blue("hey") + ' ' + on_red('yo'), 0, 6))
     self.assertEqual(on_blue(' '*5) + on_blue("hey") + ' ' + on_red('yo') + on_blue('   '),
                      on_blue(' '*14).insert(on_blue("hey") + ' ' + on_red('yo'), 5, 11))
コード例 #5
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_normal_chars(self):
     fmtstr('a', 'blue')
     fmtstr(u'a', 'blue')
     str(fmtstr('a', 'blue'))
     str(fmtstr(u'a', 'blue'))
     unicode(fmtstr('a', 'blue'))
     unicode(fmtstr(u'a', 'blue'))
     self.assertTrue(True)
コード例 #6
0
ファイル: test.py プロジェクト: 0x0all/curtsies
    def test_len_of_unicode_in_fsarray(self):

        fsa = FSArray(3, 2)
        fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, u'┌─', 2)
        self.assertEqual(fsa.shape, (3, 2))
        fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, fmtstr(u'┌─', 'blue'), 2)
        self.assertEqual(fsa.shape, (3, 2))
コード例 #7
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_copy_with_new_str(self):
     # Change string but not attributes
     a = fmtstr('hello', 'blue')
     b = a.copy_with_new_str('bye')
     self.assertEqual(a.s, 'hello')
     self.assertEqual(b.s, 'bye')
     self.assertEqual(a.basefmtstrs[0].atts, b.basefmtstrs[0].atts)
コード例 #8
0
ファイル: test.py プロジェクト: 0x0all/curtsies
    def test_insert_fmtstr_with_end_without_atts(self):
        a = fmtstr('notion')
        b = a.insert('te', 2, 6)

        self.assertEqual(a.s, "notion")
        self.assertEqual(b.s, "note")
        self.assertEqual(len(b.basefmtstrs), 2)
コード例 #9
0
def matches_lines(rows, columns, matches, current, config):
    highlight_color = func_for_letter(config.color_scheme['operator'].lower())

    if not matches:
        return []
    color = func_for_letter(config.color_scheme['main'])
    max_match_width = max(len(m) for m in matches)
    words_wide = max(1, (columns - 1) // (max_match_width + 1))
    if os.path.sep in matches[0]: # filename completion
        pass
    elif '.' in matches[0]:
        matches = [m.rstrip('.').rsplit('.')[-1] for m in matches]
        if current:
            current = current.rstrip('.').rsplit('.')[-1]
    else:
        pass

    matches_lines = [fmtstr(' ').join(color(m.ljust(max_match_width))
                                      if m != current
                                      else highlight_color(m.ljust(max_match_width))
                                      for m in matches[i:i+words_wide])
                     for i in range(0, len(matches), words_wide)]

    logging.debug('match: %r' % current)
    logging.debug('matches_lines: %r' % matches_lines)
    return matches_lines
コード例 #10
0
def paint_history(rows, columns, display_lines):
    lines = []
    for r, line in zip(range(rows), display_lines[-rows:]):
        lines.append(fmtstr(line[:columns]))
    r = fsarray(lines, width=columns)
    assert r.shape[0] <= rows, repr(r.shape)+' '+repr(rows)
    assert r.shape[1] <= columns, repr(r.shape)+' '+repr(columns)
    return r
コード例 #11
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_len_of_unicode(self):
     self.assertEqual(len(fmtstr(u'┌─')), 2)
     lines = [u'┌─', 'an', u'┌─']
     r = fsarray(lines)
     self.assertEqual(r.shape, (3, 2))
     self.assertEqual(len(fmtstr(fmtstr(u'┌─'))), len(fmtstr(u'┌─')))
     self.assertEqual(fmtstr(fmtstr(u'┌─')), fmtstr(u'┌─'))
コード例 #12
0
ファイル: test.py プロジェクト: 0x0all/curtsies
    def test_insert_with_multiple_basefmtstrs(self):
        a = fmtstr('notion')
        b = a.insert('te', 2, 6)
        c = b.insert('de', 0)

        self.assertEqual(a.s, "notion")
        self.assertEqual(b.s, "note")
        self.assertEqual(c.s, "denote")
        self.assertEqual(len(c.basefmtstrs), 3)
コード例 #13
0
ファイル: repl.py プロジェクト: NaveenPrasanth/testingrepo
 def current_line_formatted(self):
     """The colored current line (no prompt, not wrapped)"""
     if self.config.syntax:
         fs = bpythonparse(format(self.tokenize(self._current_line), self.formatter))
         logging.debug('Display line %r -> %r', self._current_line, fs)
     else:
         fs = fmtstr(self._current_line)
     if hasattr(self, 'old_fs') and str(fs) != str(self.old_fs):
         pass
         #logging.debug('calculating current formatted line: %r', repr(fs))
     self.old_fs = fs
     return fs
コード例 #14
0
ファイル: test.py プロジェクト: 0x0all/curtsies
    def test_insert_fmtstr_with_end_with_atts(self):
        # Need to test with fmtstr consisting of multiple basefmtstrs
        # and with attributes
        a = fmtstr('notion', 'blue')
        b = a.insert('te', 2, 6)

        self.assertEqual(a.s, "notion")
        self.assertEqual(a.basefmtstrs[0].atts, {'fg': 34})
        self.assertEqual(len(a.basefmtstrs), 1)

        self.assertEqual(b.s, 'note')
        self.assertEqual(b.basefmtstrs[0].atts, {'fg': 34})
        self.assertEqual(b.basefmtstrs[1].atts, {})
        self.assertEqual(len(b.basefmtstrs), 2)
コード例 #15
0
ファイル: repl.py プロジェクト: NaveenPrasanth/testingrepo
    def push(self, line, insert_into_history=True):
        """Push a line of code onto the buffer, start running the buffer

        If the interpreter successfully runs the code, clear the buffer
        """
        if self.paste_mode:
            self.saved_indent = 0
        else:
            indent = len(re.match(r'[ ]*', line).group())
            if line.endswith(':'):
                indent = max(0, indent + self.config.tab_length)
            elif line and line.count(' ') == len(line):
                indent = max(0, indent - self.config.tab_length)
            elif line and ':' not in line and line.strip().startswith(('return', 'pass', 'raise', 'yield')):
                indent = max(0, indent - self.config.tab_length)
            self.saved_indent = indent

        #current line not added to display buffer if quitting #TODO I don't understand this comment
        if self.config.syntax:
            display_line = bpythonparse(format(self.tokenize(line), self.formatter))
            # careful: self.tokenize requires that the line not be in self.buffer yet!

            logging.debug('display line being pushed to buffer: %r -> %r', line, display_line)
            self.display_buffer.append(display_line)
        else:
            self.display_buffer.append(fmtstr(line))

        if insert_into_history:
            self.insert_into_history(line)
        self.buffer.append(line)

        code_to_run = '\n'.join(self.buffer)

        logging.debug('running %r in interpreter', self.buffer)
        try:
            c = bool(code.compile_command('\n'.join(self.buffer)))
            self.saved_predicted_parse_error = False
        except (ValueError, SyntaxError, OverflowError):
            c = self.saved_predicted_parse_error = True
        if c:
            logging.debug('finished - buffer cleared')
            self.display_lines.extend(self.display_buffer_lines)
            self.display_buffer = []
            self.buffer = []
            self.cursor_offset_in_line = 0

        self.coderunner.load_code(code_to_run)
        self.run_code_and_maybe_finish()
コード例 #16
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_mul(self):
     self.assertEqual(fmtstr('heyhey'), fmtstr('hey')*2)
     pass
コード例 #17
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_add_unicode_to_byte(self):
     fmtstr(u'┌') + fmtstr('a')
     fmtstr('a') + fmtstr(u'┌')
     u'┌' + fmtstr(u'┌')
     u'┌' + fmtstr('a')
     fmtstr(u'┌') + u'┌'
     fmtstr('a') + u'┌'
コード例 #18
0
def formatted_docstring(docstring, columns, config):
    color = func_for_letter(config.color_scheme['comment'])
    return sum(([color(x) for x in (display_linize(line, columns) if line else fmtstr(''))]
                for line in docstring.split('\n')), [])
コード例 #19
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_equality(self):
     x = fmtstr("adfs")
     self.assertEqual(x, x)
     self.assertTrue(fmtstr("adfs"), fmtstr("adfs"))
     self.assertTrue(fmtstr("adfs", 'blue'), fmtstr("adfs", fg='blue'))
コード例 #20
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_index(self):
     self.assertEqual(fmtstr('Hi!', 'blue')[0], fmtstr('H', 'blue'))
     self.assertRaises(IndexError, fmtstr('Hi!', 'blue').__getitem__, 5)
コード例 #21
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_insert_fmtstr_without_end(self):
     a = fmtstr('notion')
     b = a.insert(fmtstr('ta'), 2)
     self.assertEqual(a.s, 'notion')
     self.assertEqual(b.s, 'notation')
     self.assertEqual(len(b.basefmtstrs), 3)
コード例 #22
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_simple_composition(self):
     a = fmtstr('hello ', 'underline', 'on_blue')
     b = fmtstr('there', 'red', 'on_blue')
     c = a + b
     fmtstr(c, bg='red')
     self.assertTrue(True)
コード例 #23
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_slice(self):
     self.assertEqual(fmtstr('Hi!', 'blue')[1:2], fmtstr('i', 'blue'))
     self.assertEqual(fmtstr('Hi!', 'blue')[1:], fmtstr('i!', 'blue'))
コード例 #24
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_insert_of_empty_fmtstr(self):
     self.assertEqual(fmtstr('ab').insert('', 1), fmtstr('ab'))
コード例 #25
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_simple_beginning_insert(self):
     self.assertEqual(fmtstr('abc').insert('d', 0), fmtstr('dabc'))
     self.assertEqual(fmtstr('abc').insert('d', 0), 'd'+fmtstr('abc'))
コード例 #26
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_immutibility_of_FmtStr(self):
     a = fmtstr('hi', 'blue')
     b = green(a)
     self.assertEqual(a.shared_atts['fg'], FG_COLORS['blue'])
     self.assertEqual(b.shared_atts['fg'], FG_COLORS['green'])
コード例 #27
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_unicode_repr(self):
     repr(BaseFmtStr(u'–'))
     self.assertEqual(repr(fmtstr(u'–')), repr(u'–'))
コード例 #28
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_output_type(self):
     self.assertEqual(type(str(fmtstr('hello', 'blue'))), str)
     self.assertEqual(type(unicode(fmtstr('hello', 'blue'))), unicode)
     self.assertEqual(type(str(fmtstr(u'hello', 'blue'))), str)
     self.assertEqual(type(unicode(fmtstr(u'hello', 'blue'))), unicode)
コード例 #29
0
ファイル: repl.py プロジェクト: NaveenPrasanth/testingrepo
    def paint(self, about_to_exit=False, user_quit=False):
        """Returns an array of min_height or more rows and width columns, plus cursor position

        Paints the entire screen - ideally the terminal display layer will take a diff and only
        write to the screen in portions that have changed, but the idea is that we don't need
        to worry about that here, instead every frame is completely redrawn because
        less state is cool!
        """
        # The hairiest function in the curtsies - a cleanup would be great.

        if about_to_exit:
            self.clean_up_current_line_for_exit() # exception to not changing state!

        width, min_height = self.width, self.height
        show_status_bar = bool(self.status_bar._message) or (self.config.curtsies_fill_terminal or self.status_bar.has_focus)
        if show_status_bar:
            min_height -= 1

        current_line_start_row = len(self.lines_for_display) - max(0, self.scroll_offset)
        if self.request_paint_to_clear_screen: # or show_status_bar and about_to_exit ?
            self.request_paint_to_clear_screen = False
            if self.config.curtsies_fill_terminal: #TODO clean up this logic - really necessary check?
                arr = FSArray(self.height - 1 + current_line_start_row, width)
            else:
                arr = FSArray(self.height + current_line_start_row, width)
        else:
            arr = FSArray(0, width)
        #TODO test case of current line filling up the whole screen (there aren't enough rows to show it)

        if current_line_start_row < 0: #if current line trying to be drawn off the top of the screen
            logging.debug('#<---History contiguity broken by rewind--->')
            msg = "#<---History contiguity broken by rewind--->"
            arr[0, 0:min(len(msg), width)] = [msg[:width]]

            # move screen back up a screen minus a line
            while current_line_start_row < 0:
                self.scroll_offset = self.scroll_offset - self.height
                current_line_start_row = len(self.lines_for_display) - max(-1, self.scroll_offset)

            history = paint.paint_history(max(0, current_line_start_row - 1), width, self.lines_for_display)
            arr[1:history.height+1,:history.width] = history

            if arr.height <= min_height:
                arr[min_height, 0] = ' ' # force scroll down to hide broken history message
        else:
            history = paint.paint_history(current_line_start_row, width, self.lines_for_display)
            arr[:history.height,:history.width] = history

        current_line = paint.paint_current_line(min_height, width, self.current_cursor_line)
        if user_quit: # quit() or exit() in interp
            current_line_start_row = current_line_start_row - current_line.height
        logging.debug("---current line row slice %r, %r", current_line_start_row, current_line_start_row + current_line.height)
        logging.debug("---current line col slice %r, %r", 0, current_line.width)
        arr[current_line_start_row:current_line_start_row + current_line.height,
            0:current_line.width] = current_line

        if current_line.height > min_height:
            return arr, (0, 0) # short circuit, no room for infobox

        lines = paint.display_linize(self.current_cursor_line+'X', width)
                                       # extra character for space for the cursor
        current_line_end_row = current_line_start_row + len(lines) - 1

        if self.stdin.has_focus:
            cursor_row, cursor_column = divmod(len(self.current_stdouterr_line) + self.stdin.cursor_offset_in_line, width)
            assert cursor_column >= 0, cursor_column
        elif self.coderunner.running: #TODO does this ever happen?
            cursor_row, cursor_column = divmod(len(self.current_cursor_line) + self.cursor_offset_in_line, width)
            assert cursor_column >= 0, (cursor_column, len(self.current_cursor_line), len(self._current_line), self.cursor_offset_in_line)
        else:
            cursor_row, cursor_column = divmod(len(self.current_cursor_line) - len(self._current_line) + self.cursor_offset_in_line, width)
            assert cursor_column >= 0, (cursor_column, len(self.current_cursor_line), len(self._current_line), self.cursor_offset_in_line)
        cursor_row += current_line_start_row

        if self.list_win_visible:
            logging.debug('infobox display code running')
            visible_space_above = history.height
            visible_space_below = min_height - current_line_end_row - 1

            info_max_rows = max(visible_space_above, visible_space_below)
            infobox = paint.paint_infobox(info_max_rows, int(width * self.config.cli_suggestion_width), self.matches, self.argspec, self.current_word, self.docstring, self.config)

            if visible_space_above >= infobox.height and self.config.curtsies_list_above:
                arr[current_line_start_row - infobox.height:current_line_start_row, 0:infobox.width] = infobox
            else:
                arr[current_line_end_row + 1:current_line_end_row + 1 + infobox.height, 0:infobox.width] = infobox
                logging.debug('slamming infobox of shape %r into arr of shape %r', infobox.shape, arr.shape)

        logging.debug('about to exit: %r', about_to_exit)
        if show_status_bar:
            if self.config.curtsies_fill_terminal:
                if about_to_exit:
                    arr[max(arr.height, min_height), :] = FSArray(1, width)
                else:
                    arr[max(arr.height, min_height), :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config)

                    if self.presentation_mode:
                        rows = arr.height
                        columns = arr.width
                        last_key_box = paint.paint_last_events(rows, columns, [events.pp_event(x) for x in self.last_events if x])
                        arr[arr.height-last_key_box.height:arr.height, arr.width-last_key_box.width:arr.width] = last_key_box
            else:
                statusbar_row = min_height + 1 if arr.height == min_height else arr.height
                if about_to_exit:
                    arr[statusbar_row, :] = FSArray(1, width)
                else:
                    arr[statusbar_row, :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config)

        if self.config.color_scheme['background'] not in ('d', 'D'):
            for r in range(arr.height):
                arr[r] = fmtstr(arr[r], bg=color_for_letter(self.config.color_scheme['background']))
        logging.debug('returning arr of size %r', arr.shape)
        logging.debug('cursor pos: %r', (cursor_row, cursor_column))
        return arr, (cursor_row, cursor_column)
コード例 #30
0
ファイル: test.py プロジェクト: 0x0all/curtsies
 def test_unicode_slicing(self):
     self.assertEqual(fmtstr(u'┌adfs', 'blue')[:2], fmtstr(u'┌a', 'blue'))
     self.assertEqual(type(fmtstr(u'┌adfs', 'blue')[:2].s), type(fmtstr(u'┌a', 'blue').s))
     self.assertEqual(len(fmtstr(u'┌adfs', 'blue')[:2]), 2)