Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def foo():
- return 'abc'
- def bar():
- return 'hello'
- def colorize(text, bg, fg="#ffffff", next_bg="#333333", arrow=None):
- """ Format text in pango formatting and add powerline characters
- text: string
- Text to format
- bg: string
- Color name or html colorcode, background color
- fg: string (#ffffff)
- Color name or html colorcode, foreground color
- next_bg: string (#333333)
- Color name or html colorcode, background color for powerline arrow
- arrow: string
- 'l' or 'r': powerline arrow to append left or right
- """
- out_str = "<span background=\"%s\" foreground=\"%s\"> %s </span>" % (bg, fg, text)
- arrows = {'left': '', 'right': ''}
- if arrow is not None:
- arrow_str = "<span foreground=\"%s\" background=\"%s\">%s</span>"\
- % (bg, next_bg, arrows[arrow])
- if arrow == 'left':
- out_str = arrow_str + out_str
- else:
- out_str = out_str + arrow_str
- return out_str
- def combine_funs(funs, colors, fg_color, direction='left', bg='#333333'):
- colors.append(bg) # Set correct background after last arrow
- # If left, switch fore/background colors of arrow icons
- offset = 1 if direction == 'right' else -1
- # Loop through items and colors, render formatted text
- out_str = ''
- for index, item in enumerate(funs):
- try:
- cmd_output = line[index]()
- except:
- cmd_output = '#ERROR'
- out_str = out_str + colorize(cmd_output, colors[index], fg_color,
- colors[index+offset], direction)
- return out_str
- funs = [foo, bar]
- colors = ['#A22300', '#CD2300'] # Background
- fg_color = 'white' # Foreground
- direction = 'left' # Pointing direction of powerline arrows
- combine_funs(funs, colors, text_color, direction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement