コード例 #1
0
 def child():
     import codecs
     from blessed.sequences import Sequence
     term = TestTerminal(kind='xterm-256color')
     # this 'ansi' art contributed by xzip!impure for another project,
     # unlike most CP-437 DOS ansi art, this is actually utf-8 encoded.
     fname = os.path.join(os.path.dirname(__file__), 'wall.ans')
     lines = codecs.open(fname, 'r', 'utf-8').readlines()
     assert term.length(lines[0]) == 67  # ^[[64C^[[34m▄▓▄
     assert term.length(lines[1]) == 75
     assert term.length(lines[2]) == 78
     assert term.length(lines[3]) == 78
     assert term.length(lines[4]) == 78
     assert term.length(lines[5]) == 78
     assert term.length(lines[6]) == 77
コード例 #2
0
 def child():
     import codecs
     from blessed.sequences import Sequence
     term = TestTerminal(kind='xterm-256color')
     # this 'ansi' art contributed by xzip!impure for another project,
     # unlike most CP-437 DOS ansi art, this is actually utf-8 encoded.
     fname = os.path.join(os.path.dirname(__file__), 'wall.ans')
     lines = codecs.open(fname, 'r', 'utf-8').readlines()
     assert term.length(lines[0]) == 67  # ^[[64C^[[34m▄▓▄
     assert term.length(lines[1]) == 75
     assert term.length(lines[2]) == 78
     assert term.length(lines[3]) == 78
     assert term.length(lines[4]) == 78
     assert term.length(lines[5]) == 78
     assert term.length(lines[6]) == 77
コード例 #3
0
    def child(kind, lines=25, cols=80):
        # set the pty's virtual window size
        val = struct.pack('HHHH', lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
        term = TestTerminal(kind=kind)

        pony_msg = 'pony express, all aboard, choo, choo!'
        pony_len = len(pony_msg)
        pony_colored = u''.join([
            '%s%s' % (
                term.color(n % 7),
                ch,
            ) for n, ch in enumerate(pony_msg)
        ])
        pony_colored += term.normal
        ladjusted = term.ljust(pony_colored)
        radjusted = term.rjust(pony_colored)
        centered = term.center(pony_colored)
        assert (term.length(pony_colored) == pony_len)
        assert (term.length(centered.strip()) == pony_len)
        assert (term.length(centered) == len(pony_msg.center(term.width)))
        assert (term.length(ladjusted.strip()) == pony_len)
        assert (term.length(ladjusted) == len(pony_msg.ljust(term.width)))
        assert (term.length(radjusted.strip()) == pony_len)
        assert (term.length(radjusted) == len(pony_msg.rjust(term.width)))
コード例 #4
0
    def child():
        term = TestTerminal(kind="xterm-256color")

        # given,
        given = term.bold_red(u"コンニチハ, セカイ!")
        expected = sum((2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 1))

        # exercise,
        assert term.length(given) == expected
コード例 #5
0
 def child(kind):
     t = TestTerminal(kind=kind)
     pony_msg = "pony express, all aboard, choo, choo!"
     pony_len = len(pony_msg)
     pony_colored = u"".join(["%s%s" % (t.color(n % 7), ch) for n, ch in enumerate(pony_msg)])
     pony_colored += t.normal
     ladjusted = t.ljust(pony_colored, 88)
     radjusted = t.rjust(pony_colored, 88)
     centered = t.center(pony_colored, 88)
     assert t.length(pony_colored) == pony_len
     assert t.length(centered.strip()) == pony_len
     assert t.length(centered) == len(pony_msg.center(88))
     assert t.length(ladjusted.strip()) == pony_len
     assert t.length(ladjusted) == len(pony_msg.ljust(88))
     assert t.length(radjusted.strip()) == pony_len
     assert t.length(radjusted) == len(pony_msg.rjust(88))
コード例 #6
0
 def child(kind):
     term = TestTerminal(kind=kind)
     pony_msg = 'pony express, all aboard, choo, choo!'
     pony_len = len(pony_msg)
     pony_colored = u''.join(
         ['%s%s' % (term.color(n % 7), ch,)
          for n, ch in enumerate(pony_msg)])
     pony_colored += term.normal
     ladjusted = term.ljust(pony_colored, 88)
     radjusted = term.rjust(pony_colored, 88)
     centered = term.center(pony_colored, 88)
     assert (term.length(pony_colored) == pony_len)
     assert (term.length(centered.strip()) == pony_len)
     assert (term.length(centered) == len(pony_msg.center(88)))
     assert (term.length(ladjusted.strip()) == pony_len)
     assert (term.length(ladjusted) == len(pony_msg.ljust(88)))
     assert (term.length(radjusted.strip()) == pony_len)
     assert (term.length(radjusted) == len(pony_msg.rjust(88)))
コード例 #7
0
    def child():
        term = TestTerminal(kind='xterm-256color')

        # given,
        given = term.bold_red(u'コンニチハ, セカイ!')
        expected = sum((
            2,
            2,
            2,
            2,
            2,
            1,
            1,
            2,
            2,
            2,
            1,
        ))

        # exercise,
        assert term.length(given) == expected
コード例 #8
0
    def child(kind, lines=25, cols=80):
        # set the pty's virtual window size
        val = struct.pack("HHHH", lines, cols, 0, 0)
        fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
        t = TestTerminal(kind=kind)

        pony_msg = "pony express, all aboard, choo, choo!"
        pony_len = len(pony_msg)
        pony_colored = u"".join(["%s%s" % (t.color(n % 7), ch) for n, ch in enumerate(pony_msg)])
        pony_colored += t.normal
        ladjusted = t.ljust(pony_colored)
        radjusted = t.rjust(pony_colored)
        centered = t.center(pony_colored)
        assert t.length(pony_colored) == pony_len
        assert t.length(centered.strip()) == pony_len
        assert t.length(centered) == len(pony_msg.center(t.width))
        assert t.length(ladjusted.strip()) == pony_len
        assert t.length(ladjusted) == len(pony_msg.ljust(t.width))
        assert t.length(radjusted.strip()) == pony_len
        assert t.length(radjusted) == len(pony_msg.rjust(t.width))
コード例 #9
0
 def child(kind):
     term = TestTerminal(kind=kind)
     pony_msg = 'pony express, all aboard, choo, choo!'
     pony_len = len(pony_msg)
     pony_colored = u''.join([
         '%s%s' % (
             term.color(n % 7),
             ch,
         ) for n, ch in enumerate(pony_msg)
     ])
     pony_colored += term.normal
     ladjusted = term.ljust(pony_colored, 88)
     radjusted = term.rjust(pony_colored, 88)
     centered = term.center(pony_colored, 88)
     assert (term.length(pony_colored) == pony_len)
     assert (term.length(centered.strip()) == pony_len)
     assert (term.length(centered) == len(pony_msg.center(88)))
     assert (term.length(ladjusted.strip()) == pony_len)
     assert (term.length(ladjusted) == len(pony_msg.ljust(88)))
     assert (term.length(radjusted.strip()) == pony_len)
     assert (term.length(radjusted) == len(pony_msg.rjust(88)))
コード例 #10
0
    def child(kind):
        term = TestTerminal(kind=kind)
        # Create a list of ascii characters, to be separated
        # by word, to be zipped up with a cycling list of
        # terminal sequences. Then, compare the length of
        # each, the basic plain_texterm.__len__ vs. the Terminal
        # method length. They should be equal.
        plain_text = (u'The softest things of the world '
                      u'Override the hardest things of the world '
                      u'That which has no substance '
                      u'Enters into that which has no openings')
        if term.bold:
            assert (term.length(term.bold) == 0)
            assert (term.length(term.bold(u'x')) == 1)
            assert (term.length(term.bold_red) == 0)
            assert (term.length(term.bold_red(u'x')) == 1)
            assert (term.strip(term.bold) == u'')
            assert (term.rstrip(term.bold) == u'')
            assert (term.lstrip(term.bold) == u'')
            assert (term.strip(term.bold(u'  x  ')) == u'x')
            assert (term.strip(term.bold(u'z  x  q'), 'zq') == u'  x  ')
            assert (term.rstrip(term.bold(u'  x  ')) == u'  x')
            assert (term.lstrip(term.bold(u'  x  ')) == u'x  ')
            assert (term.strip(term.bold_red) == u'')
            assert (term.rstrip(term.bold_red) == u'')
            assert (term.lstrip(term.bold_red) == u'')
            assert (term.strip(term.bold_red(u'  x  ')) == u'x')
            assert (term.rstrip(term.bold_red(u'  x  ')) == u'  x')
            assert (term.lstrip(term.bold_red(u'  x  ')) == u'x  ')
            assert (term.strip_seqs(term.bold) == u'')
            assert (term.strip_seqs(term.bold(u'  x  ')) == u'  x  ')
            assert (term.strip_seqs(term.bold_red) == u'')
            assert (term.strip_seqs(term.bold_red(u'  x  ')) == u'  x  ')

        if term.underline:
            assert (term.length(term.underline) == 0)
            assert (term.length(term.underline(u'x')) == 1)
            assert (term.length(term.underline_red) == 0)
            assert (term.length(term.underline_red(u'x')) == 1)
            assert (term.strip(term.underline) == u'')
            assert (term.strip(term.underline(u'  x  ')) == u'x')
            assert (term.strip(term.underline_red) == u'')
            assert (term.strip(term.underline_red(u'  x  ')) == u'x')
            assert (term.rstrip(term.underline_red(u'  x  ')) == u'  x')
            assert (term.lstrip(term.underline_red(u'  x  ')) == u'x  ')
            assert (term.strip_seqs(term.underline) == u'')
            assert (term.strip_seqs(term.underline(u'  x  ')) == u'  x  ')
            assert (term.strip_seqs(term.underline_red) == u'')
            assert (term.strip_seqs(term.underline_red(u'  x  ')) == u'  x  ')

        if term.reverse:
            assert (term.length(term.reverse) == 0)
            assert (term.length(term.reverse(u'x')) == 1)
            assert (term.length(term.reverse_red) == 0)
            assert (term.length(term.reverse_red(u'x')) == 1)
            assert (term.strip(term.reverse) == u'')
            assert (term.strip(term.reverse(u'  x  ')) == u'x')
            assert (term.strip(term.reverse_red) == u'')
            assert (term.strip(term.reverse_red(u'  x  ')) == u'x')
            assert (term.rstrip(term.reverse_red(u'  x  ')) == u'  x')
            assert (term.lstrip(term.reverse_red(u'  x  ')) == u'x  ')
            assert (term.strip_seqs(term.reverse) == u'')
            assert (term.strip_seqs(term.reverse(u'  x  ')) == u'  x  ')
            assert (term.strip_seqs(term.reverse_red) == u'')
            assert (term.strip_seqs(term.reverse_red(u'  x  ')) == u'  x  ')

        if term.blink:
            assert (term.length(term.blink) == 0)
            assert (term.length(term.blink(u'x')) == 1)
            assert (term.length(term.blink_red) == 0)
            assert (term.length(term.blink_red(u'x')) == 1)
            assert (term.strip(term.blink) == u'')
            assert (term.strip(term.blink(u'  x  ')) == u'x')
            assert (term.strip(term.blink(u'z  x  q'), u'zq') == u'  x  ')
            assert (term.strip(term.blink_red) == u'')
            assert (term.strip(term.blink_red(u'  x  ')) == u'x')
            assert (term.strip_seqs(term.blink) == u'')
            assert (term.strip_seqs(term.blink(u'  x  ')) == u'  x  ')
            assert (term.strip_seqs(term.blink_red) == u'')
            assert (term.strip_seqs(term.blink_red(u'  x  ')) == u'  x  ')

        if term.home:
            assert (term.length(term.home) == 0)
            assert (term.strip(term.home) == u'')
        if term.clear_eol:
            assert (term.length(term.clear_eol) == 0)
            assert (term.strip(term.clear_eol) == u'')
        if term.enter_fullscreen:
            assert (term.length(term.enter_fullscreen) == 0)
            assert (term.strip(term.enter_fullscreen) == u'')
        if term.exit_fullscreen:
            assert (term.length(term.exit_fullscreen) == 0)
            assert (term.strip(term.exit_fullscreen) == u'')

        # horizontally, we decide move_down and move_up are 0,
        assert (term.length(term.move_down) == 0)
        assert (term.length(term.move_down(2)) == 0)
        assert (term.length(term.move_up) == 0)
        assert (term.length(term.move_up(2)) == 0)

        # other things aren't so simple, somewhat edge cases,
        # moving backwards and forwards horizontally must be
        # accounted for as a "length", as <x><move right 10><y>
        # will result in a printed column length of 12 (even
        # though columns 2-11 are non-destructive space
        assert (term.length(u'x\b') == 0)
        assert (term.strip(u'x\b') == u'')

        # XXX why are some terminals width of 9 here ??
        assert (term.length(u'\t') in (8, 9))
        assert (term.strip(u'\t') == u'')
        assert (term.length(u'_' + term.move_left) == 0)

        if term.cub:
            assert (term.length((u'_' * 10) + term.cub(10)) == 0)

        assert (term.length(term.move_right) == 1)

        if term.cuf:
            assert (term.length(term.cuf(10)) == 10)

        # vertical spacing is unaccounted as a 'length'
        assert (term.length(term.move_up) == 0)
        assert (term.length(term.cuu(10)) == 0)
        assert (term.length(term.move_down) == 0)
        assert (term.length(term.cud(10)) == 0)

        # this is how manpages perform underlining, this is done
        # with the 'overstrike' capability of teletypes, and aparently
        # less(1), '123' -> '1\b_2\b_3\b_'
        text_wseqs = u''.join(
            itertools.chain(*zip(plain_text, itertools.cycle(['\b_']))))
        assert (term.length(text_wseqs) == len(plain_text))
コード例 #11
0
    def child(kind):
        t = TestTerminal(kind=kind)
        # Create a list of ascii characters, to be separated
        # by word, to be zipped up with a cycling list of
        # terminal sequences. Then, compare the length of
        # each, the basic plain_text.__len__ vs. the Terminal
        # method length. They should be equal.
        plain_text = (
            u"The softest things of the world "
            u"Override the hardest things of the world "
            u"That which has no substance "
            u"Enters into that which has no openings"
        )
        if t.bold:
            assert t.length(t.bold) == 0
            assert t.length(t.bold(u"x")) == 1
            assert t.length(t.bold_red) == 0
            assert t.length(t.bold_red(u"x")) == 1
            assert t.strip(t.bold) == u""
            assert t.rstrip(t.bold) == u""
            assert t.lstrip(t.bold) == u""
            assert t.strip(t.bold(u"  x  ")) == u"x"
            assert t.strip(t.bold(u"z  x  q"), "zq") == u"  x  "
            assert t.rstrip(t.bold(u"  x  ")) == u"  x"
            assert t.lstrip(t.bold(u"  x  ")) == u"x  "
            assert t.strip(t.bold_red) == u""
            assert t.rstrip(t.bold_red) == u""
            assert t.lstrip(t.bold_red) == u""
            assert t.strip(t.bold_red(u"  x  ")) == u"x"
            assert t.rstrip(t.bold_red(u"  x  ")) == u"  x"
            assert t.lstrip(t.bold_red(u"  x  ")) == u"x  "
            assert t.strip_seqs(t.bold) == u""
            assert t.strip_seqs(t.bold(u"  x  ")) == u"  x  "
            assert t.strip_seqs(t.bold_red) == u""
            assert t.strip_seqs(t.bold_red(u"  x  ")) == u"  x  "

        if t.underline:
            assert t.length(t.underline) == 0
            assert t.length(t.underline(u"x")) == 1
            assert t.length(t.underline_red) == 0
            assert t.length(t.underline_red(u"x")) == 1
            assert t.strip(t.underline) == u""
            assert t.strip(t.underline(u"  x  ")) == u"x"
            assert t.strip(t.underline_red) == u""
            assert t.strip(t.underline_red(u"  x  ")) == u"x"
            assert t.rstrip(t.underline_red(u"  x  ")) == u"  x"
            assert t.lstrip(t.underline_red(u"  x  ")) == u"x  "
            assert t.strip_seqs(t.underline) == u""
            assert t.strip_seqs(t.underline(u"  x  ")) == u"  x  "
            assert t.strip_seqs(t.underline_red) == u""
            assert t.strip_seqs(t.underline_red(u"  x  ")) == u"  x  "

        if t.reverse:
            assert t.length(t.reverse) == 0
            assert t.length(t.reverse(u"x")) == 1
            assert t.length(t.reverse_red) == 0
            assert t.length(t.reverse_red(u"x")) == 1
            assert t.strip(t.reverse) == u""
            assert t.strip(t.reverse(u"  x  ")) == u"x"
            assert t.strip(t.reverse_red) == u""
            assert t.strip(t.reverse_red(u"  x  ")) == u"x"
            assert t.rstrip(t.reverse_red(u"  x  ")) == u"  x"
            assert t.lstrip(t.reverse_red(u"  x  ")) == u"x  "
            assert t.strip_seqs(t.reverse) == u""
            assert t.strip_seqs(t.reverse(u"  x  ")) == u"  x  "
            assert t.strip_seqs(t.reverse_red) == u""
            assert t.strip_seqs(t.reverse_red(u"  x  ")) == u"  x  "

        if t.blink:
            assert t.length(t.blink) == 0
            assert t.length(t.blink(u"x")) == 1
            assert t.length(t.blink_red) == 0
            assert t.length(t.blink_red(u"x")) == 1
            assert t.strip(t.blink) == u""
            assert t.strip(t.blink(u"  x  ")) == u"x"
            assert t.strip(t.blink(u"z  x  q"), u"zq") == u"  x  "
            assert t.strip(t.blink_red) == u""
            assert t.strip(t.blink_red(u"  x  ")) == u"x"
            assert t.strip_seqs(t.blink) == u""
            assert t.strip_seqs(t.blink(u"  x  ")) == u"  x  "
            assert t.strip_seqs(t.blink_red) == u""
            assert t.strip_seqs(t.blink_red(u"  x  ")) == u"  x  "

        if t.home:
            assert t.length(t.home) == 0
            assert t.strip(t.home) == u""
        if t.clear_eol:
            assert t.length(t.clear_eol) == 0
            assert t.strip(t.clear_eol) == u""
        if t.enter_fullscreen:
            assert t.length(t.enter_fullscreen) == 0
            assert t.strip(t.enter_fullscreen) == u""
        if t.exit_fullscreen:
            assert t.length(t.exit_fullscreen) == 0
            assert t.strip(t.exit_fullscreen) == u""

        # horizontally, we decide move_down and move_up are 0,
        assert t.length(t.move_down) == 0
        assert t.length(t.move_down(2)) == 0
        assert t.length(t.move_up) == 0
        assert t.length(t.move_up(2)) == 0

        # other things aren't so simple, somewhat edge cases,
        # moving backwards and forwards horizontally must be
        # accounted for as a "length", as <x><move right 10><y>
        # will result in a printed column length of 12 (even
        # though columns 2-11 are non-destructive space
        assert t.length(u"x\b") == 0
        assert t.strip(u"x\b") == u""

        # XXX why are some terminals width of 9 here ??
        assert t.length(u"\t") in (8, 9)
        assert t.strip(u"\t") == u""
        assert t.length(u"_" + t.move_left) == 0

        if t.cub:
            assert t.length((u"_" * 10) + t.cub(10)) == 0

        assert t.length(t.move_right) == 1

        if t.cuf:
            assert t.length(t.cuf(10)) == 10

        # vertical spacing is unaccounted as a 'length'
        assert t.length(t.move_up) == 0
        assert t.length(t.cuu(10)) == 0
        assert t.length(t.move_down) == 0
        assert t.length(t.cud(10)) == 0

        # this is how manpages perform underlining, this is done
        # with the 'overstrike' capability of teletypes, and aparently
        # less(1), '123' -> '1\b_2\b_3\b_'
        text_wseqs = u"".join(itertools.chain(*zip(plain_text, itertools.cycle(["\b_"]))))
        assert t.length(text_wseqs) == len(plain_text)