コード例 #1
0
def test_vertical_border_complex():
    border = '{t.red}r{t.white}w{t.blue}b\n'
    text, seqs, last_seq = border_line = Line.parse(border)
    line = Line.repeat_to_width(border, 10 * len(text))
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == text * 10
    assert line.display == border * 10
コード例 #2
0
def test_two_trailing_tags():
    # green is irrelevant, so dropped from display
    text = '{t.green}{t.blue}'
    line = Line(text, 0, '<')
    assert line.plain == ''
    assert line.display == ''
    assert line.last_seq == '{t.blue}'
コード例 #3
0
def test_two_trailing_tags_with_text():
    # both tags dropped from display because no text follows them
    text = 'abc{t.green}{t.blue}'
    line = Line(text, 3, '<')
    assert line.plain == 'abc'
    assert line.display == 'abc'
    assert line.last_seq == '{t.blue}'
コード例 #4
0
def test_complex_ends_in_non_normal_tag():
    text = '{t.green}{}{}}{blac{t.yellow}k justp{t.cyan}laintext{t.pink}'
    line = Line(text, 25, '<')
    # tags removed,and { and } doubled when not in tag
    assert line.plain == '{}{}}{black justplaintext'
    # Useless tags at end of markup are removed
    # { and } doubled when not part of tag, and end with normal
    assert line.display == '{t.green}{{}}{{}}}}{{blac{t.yellow}k justp{t.cyan}laintext'
    assert line.last_seq == '{t.pink}'
コード例 #5
0
def test_complex():
    text = '{t.green}{}{}}{blac{t.yellow}k justp{t.cyan}laintext{t.pink}x'
    line = Line(text, 26, '<')
    # tags removed,and { and } doubled when not in tag
    assert line.plain == '{}{}}{black justplaintextx'

    # { and } doubled when not part of tag, and end with normal
    assert line.display == '{t.green}{{}}{{}}}}{{blac{t.yellow}k justp{t.cyan}laintext{t.pink}x'
    assert line.last_seq == '{t.pink}'
コード例 #6
0
def test_vertical_border():
    border = 'x\n'
    line = Line.repeat_to_width(border, 10 * len(border))
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == border * 10
    assert line.display == '{t.normal}' + border * 10
コード例 #7
0
def test_parse_dups():
    line = Line('{t.green}xy{t.green}z', 3, '^')
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == 'xyz'
    assert line.last_seq == '{t.green}'
コード例 #8
0
def test_repeat_to_width_with_seqs():
    line = Line.repeat_to_width('{t.red}-{t.white}-{t.blue}-', 4)
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == '----'
    assert line.display == '{t.red}-{t.white}-{t.blue}-{t.red}-'
コード例 #9
0
def test_repeat_to_width_with_seqs():
    line = Line.repeat_to_width('w{t.blue}xy{t.red}z', 10)
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == 'wxyzwxyzwx'
    assert line.display == 'w{t.blue}xy{t.red}zw{t.blue}xy{t.red}zw{t.blue}x'
コード例 #10
0
def test_repeat_to_width():
    line = Line.repeat_to_width('wxyz', 10)
    assert line.plain == 'wxyzwxyzwx'
    assert line.display == '{t.normal}wxyzwxyzwx'
コード例 #11
0
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), "blessedblocks"))
# Previous two lines not needed if blessedblocks modules is installed
from blessedblocks.bare_block import BareBlock
from blessedblocks.block import Grid, SizePref
from blessedblocks.runner import Runner
from blessedblocks.line import Line
from threading import Event, Thread, Lock
from tabulate import tabulate
import datetime
from blessed import Terminal

term = Terminal()
layout = [(0, 1, [2, 3, 4], 5)]
blocks = {}

blocks[0] = BareBlock(text=" ")  # TODO, why is a space needed?
rwb = ('{t.red}My {t.white}American {t.blue}Title!\n' +
       Line.repeat_to_width('{t.red}-{t.white}-{t.blue}-', 18).display)
blocks[1] = BareBlock(vjust='^', hjust='^', text=rwb)
blocks[2] = BareBlock(hjust='<', text=((('x' * 50) + '\n') * 15 + 'x'))
blocks[3] = BareBlock(vjust='=', hjust='^', text='This is some centered text!')
blocks[4] = BareBlock(hjust='>', text=((('x' * 50) + '\n') * 15 + 'x'))
blocks[5] = BareBlock(text=((('z' * 200) + '\n') * 15 + 'x'))

g = Grid(layout, blocks)
top = BareBlock(grid=g)

r = Runner(top)
r.start()
コード例 #12
0
def test_parse_contig_3():
    line = Line('{t.green}{t.blue}{t.red}xyz', 3, '^')
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == 'xyz'
    assert line.last_seq == '{t.red}'
コード例 #13
0
def test_last_sequence_normal():
    text = 'hi there, {t.red}Red{t.normal}!'
    line = Line(text, 14, '<')
    assert line.plain == 'hi there, Red!'
    assert line.display == text
    assert line.last_seq == '{t.normal}'
コード例 #14
0
def test_broken_tag_front():
    text = 't.green}xyz'
    line = Line(text, 11, '<')
    assert line.plain == text
    assert line.display == 't.green}}xyz'  # non-tag brackets doubled in display
    assert line.last_seq is None
コード例 #15
0
def test_width_just_right():
    line = Line('{t.green}xy{t.blue}z', 12, '>')
    left_just, right_just = 9 * ' ', ''
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == left_just + 'xyz' + right_just
コード例 #16
0
def test_simple():
    line = Line('simple line of text', 19, '<')
    assert line.plain == 'simple line of text'
    assert line.display == line.plain
    assert line.last_seq is None
コード例 #17
0
def test_blank_line():
    line = Line('', 12, ',')
    left_just, right_just = '', 12 * ' '
    print(('\n' + line.display + '{t.normal}').format(t=term))
    assert line.plain == right_just
コード例 #18
0

def handler(cmd):
    pass


g = Grid(layout=layout, blocks=blocks, cmds={'x', 'abc'}, handler=handler)

# Main logic
stop_event = Event()
r = Runner(g, stop_event=stop_event)

r.start()

blocks[1].text = ("{t.normal}A bare block with just a rg&b horizontal line\n" +
                  Line.repeat_to_width('{t.red}-{t.green}-{t.blue}-',
                                       r.term_width()).display)

# Start the top output in block 10
top_thread = Thread(target=run_cmd_in_block,
                    args=('top -b -n 1 -w 512', blocks[10], 1))
top_thread.start()

import random
# Refresh some of the blocks in a tight loop
for i in range(300):
    stop_event.wait(.1)
    blocks[2].top_border = str(i % 10)
    if not i % 10:
        blocks[2].bottom_border = random.choice([
            '{t.red}', '{t.white}', '{t.blue}'
        ]) + random.choice(['+', '=', '=', '%'])
コード例 #19
0
def test_just_tag():
    text = '{t.green}'
    line = Line(text, 0, '<')
    assert line.plain == ''
    assert line.display == ''  # ???
    assert line.last_seq == '{t.green}'