Better highlighting.
[FeedLint.git] / display.py
blob7cc45bfae00ef87cc9d55a3ea583dac86a8cc2a6
1 import sys
2 import curses
4 curses.setupterm()
6 cursor_pos = 0
7 n_cols = curses.tigetnum('cols') or 80
9 COLOURS = {
10 'BLACK' : 0,
11 'BLUE' : 1,
12 'GREEN' : 2,
13 'CYAN' : 3,
14 'RED' : 4,
15 'MAGENTA' : 5,
16 'YELLOW' : 6,
17 'WHITE' : 7,
20 set_fg = curses.tigetstr('setf') or ''
21 normal = curses.tigetstr('sgr0') or ''
23 def checking(msg):
24 global cursor_pos
25 if cursor_pos:
26 result('!')
27 msg = ' ' + msg
28 cursor_pos = len(msg)
29 sys.stdout.write(msg)
31 def result(msg, colour = 'GREEN'):
32 global cursor_pos
33 result_col = n_cols - max(10, len(msg)) - 1
34 if cursor_pos > result_col:
35 print
36 cursor_pos = 0
37 if colour:
38 msg = highlight(msg, colour)
39 print " " * (result_col - cursor_pos), "[ %s ]" % msg
40 cursor_pos = 0
42 def error(msg):
43 result(msg, 'RED')
45 def highlight(msg, colour):
46 return curses.tparm(set_fg, COLOURS[colour]) + msg + curses.tparm(normal)