From c54f77db3d486ed893aa5927f63536f9aaee8c0d Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 20 Oct 2010 01:52:00 +0200 Subject: play: added color support --- play | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/play b/play index 746cbf0..69316f9 100644 --- a/play +++ b/play @@ -197,7 +197,10 @@ class ProgressWindow(Window): x = int(self.value * self.cols) # 0 to cols-1 x and self.hline(ord('='), x) self.move(0, x) + # Color of the progress indicator + self.attron(curses.color_pair(1)) self.insstr('|') + self.attroff(curses.color_pair(1)) self.touchwin() self.refresh() @@ -220,7 +223,10 @@ class StatusWindow(Window): msg = string.translate(self.current_message, Window.translationTable) self.move(0, 0) self.clrtoeol() + # Color of statusbar messages + self.attron(curses.color_pair(3)) self.insstr(cut(msg, self.cols)) + self.attroff(curses.color_pair(3)) self.touchwin() self.refresh() @@ -257,9 +263,10 @@ class CounterWindow(Window): h, s = divmod(self.values[self.mode], 3600) m, s = divmod(s, 60) self.move(0, 0) - self.attron(curses.A_BOLD) + # Color of the statusbar counter + self.attron(curses.color_pair(1)) self.insstr("%02dh %02dm %02ds" % (h, m, s)) - self.attroff(curses.A_BOLD) + self.attroff(curses.color_pair(1)) self.touchwin() self.refresh() @@ -343,9 +350,10 @@ class TabWindow(Window): child = self.children[self.active_child] self.move(0, 0) self.clrtoeol() - self.attron(curses.A_BOLD) + # Color of the window titlebar text + self.attron(curses.color_pair(2)) self.insstr(child.get_title()) - self.attroff(curses.A_BOLD) + self.attroff(curses.color_pair(2)) if refresh: self.refresh() def add(self, Class): @@ -416,7 +424,8 @@ class ListWindow(Window): if self.visible: self.refresh() self.parent.update_title() - self.update_line(curses.A_REVERSE) + # Color of a selected list item + self.update_line(curses.color_pair(4)) def update_line(self, attr = None, refresh = 1): if not self.buffer: return @@ -980,9 +989,10 @@ class PlaylistWindow(TagListWindow): return re.sub("(http://[^/]+)/?(.*)", "\\1/\\2", url) def putstr(self, entry, *pos): - if entry.is_active(): self.attron(curses.A_BOLD) + # Color of an active *playlist* item + if entry.is_active(): self.attron(curses.color_pair(3)) ListWindow.putstr(self, entry, *pos) - if entry.is_active(): self.attroff(curses.A_BOLD) + if entry.is_active(): self.attroff(curses.color_pair(3)) def change_active_entry(self, direction): if not self.buffer: return @@ -1417,6 +1427,20 @@ class Application: tcattr[0] = tcattr[0] & ~(tty.IXON) tty.tcsetattr(sys.stdin.fileno(), tty.TCSANOW, tcattr) self.w = curses.initscr() + # Function start_color() called after initscr + curses.start_color() + # Added to support transparency + curses.use_default_colors() + # Custom color pairs + # pair 0 is always white on black + # color -1 is the default color if use_default_colors() is called + curses.init_pair(1, curses.COLOR_RED, -1) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_YELLOW, -1) + curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) + # If you'd like it more colorful, you can play with: + # BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN and WHITE + # curses.cbreak() curses.noecho() try: curses.meta(1) @@ -1647,6 +1671,8 @@ def main(): app.run() except SystemExit: app.cleanup() + # Can we display colors? + #print curses.has_colors() except Exception: app.cleanup() import traceback -- cgit v1.2.3