def render(tweet, selected=False, max_width=None): lines = tweet.text.splitlines() spacing = ' ' * (15 - len(tweet.author)) if selected: modificators = [curses.A_UNDERLINE] else: modificators = [] first_line = True result = Text() for line in lines: splitted_line = CursesTweetRenderer.split_for_max_width( line, max_width, modificators, ) for screen_line in splitted_line: # raise RuntimeError(splitted_line) if first_line: result += Text( spacing, Green(), tweet.author, Default(), ' ', Default(modificators), ) + screen_line first_line = False else: result += Text( Default(), '\n' + ' ' * 16, ) + screen_line result += Text(Default(), '\n') return result
def test_it_renders_single_line_tweets(): tweet = Tweet( 'fooser', 'this is a tweet', ) expected = Text( ' ', Green(), 'fooser', Default(), ' ', 'this is a tweet', '\n', ) assert expected == CursesTweetRenderer.render(tweet)
def test_it_underlines_selected_tweets(): tweet = Tweet( 'fooser', 'this is a tweet', ) expected = Text( ' ', Green(), 'fooser', Default(), ' ', Default([curses.A_UNDERLINE]), 'this is a tweet', Default(), '\n', ) assert expected == CursesTweetRenderer.render(tweet, selected=True)
def test_renders_with_limited_screen_width(): tweet_text = ( 'This is a long tweet, its 68 characters long. ZzZzZzZzZzZzZzZzZzZzZz') assert 68 == len(tweet_text) tweet = Tweet( 'fooser', tweet_text, ) expected = Text( ' ', Green(), 'fooser', Default(), ' ', 'This is a long tweet, its 68 characters long. ', '\n ', Blue(), '| ', Default(), 'ZzZzZzZzZzZzZzZzZzZzZz', '\n', ) assert expected == CursesTweetRenderer.render(tweet, max_width=62)
def test_text_renders_to_string_with_colors(): assert 'test it' == str(Text('test', Green(), ' it'))
def test_you_can_add_one_text_to_another_with_colors(): assert Text('first') + Text(Green(), 'second') == \ Text('first', Green(), 'second')