From: Vu Nhat Minh Date: Wed, 2 Jul 2014 05:37:35 +0000 (+0900) Subject: configurable X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6fa09c146e4ceb4635c487d6949455efdbc8a947;p=rainbowstream.git configurable --- diff --git a/rainbowstream/colors.py b/rainbowstream/colors.py index e3d32c0..f3c7f85 100644 --- a/rainbowstream/colors.py +++ b/rainbowstream/colors.py @@ -1,50 +1,66 @@ import random import itertools from functools import wraps -from termcolor import * from pyfiglet import figlet_format -def color_code(code): - def inner(text, bold=False): + +def basic_color(code): + """ + 16 colors supported + """ + def inner(text, bold=True): c = code if bold: c = "1;%s" % c return "\033[%sm%s\033[0m" % (c, text) return inner -default = color_code('39') -black = color_code('30') -red = color_code('31') -green = color_code('32') -yellow = color_code('33') -blue = color_code('34') -magenta = color_code('35') -cyan = color_code('36') -grey = color_code('90') -light_red = color_code('91') -light_green = color_code('92') -light_yellow = color_code('93') -light_blue = color_code('94') -light_magenta = color_code('95') -light_cyan = color_code('96') -white = color_code('97') - -on_default = color_code('49') -on_black = color_code('40') -on_red = color_code('41') -on_green = color_code('42') -on_yellow = color_code('43') -on_blue = color_code('44') -on_magenta = color_code('45') -on_cyan = color_code('46') -on_grey = color_code('100') -on_light_red = color_code('101') -on_light_green = color_code('102') -on_light_yellow = color_code('103') -on_light_blue = color_code('104') -on_light_magenta = color_code('105') -on_light_cyan = color_code('106') -on_white = color_code('107') + +def RGB(code): + """ + 256 colors supported + """ + def inner(text, bold=True): + c = code + if bold: + c = "1;%s" % c + return "\033[38;5;%sm%s\033[0m" % (c, text) + return inner + + +default = basic_color('39') +black = basic_color('30') +red = basic_color('31') +green = basic_color('32') +yellow = basic_color('33') +blue = basic_color('34') +magenta = basic_color('35') +cyan = basic_color('36') +grey = basic_color('90') +light_red = basic_color('91') +light_green = basic_color('92') +light_yellow = basic_color('93') +light_blue = basic_color('94') +light_magenta = basic_color('95') +light_cyan = basic_color('96') +white = basic_color('97') + +on_default = basic_color('49') +on_black = basic_color('40') +on_red = basic_color('41') +on_green = basic_color('42') +on_yellow = basic_color('43') +on_blue = basic_color('44') +on_magenta = basic_color('45') +on_cyan = basic_color('46') +on_grey = basic_color('100') +on_light_red = basic_color('101') +on_light_green = basic_color('102') +on_light_yellow = basic_color('103') +on_light_blue = basic_color('104') +on_light_magenta = basic_color('105') +on_light_cyan = basic_color('106') +on_white = basic_color('107') colors_shuffle = [ grey, diff --git a/rainbowstream/config.py b/rainbowstream/config.py index daf1cfd..6afffd5 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -1,3 +1,5 @@ +from .colors import * + # 'search': max search record SEARCH_MAX_RECORD = 5 # 'home': default number of home's tweets @@ -23,5 +25,54 @@ DOMAIN = USER_DOMAIN IMAGE_SHIFT = 10 IMAGE_MAX_HEIGHT = 40 -# Color name can be 'grey', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', or 'white' -SCREEN_NAME_COLOR = 'grey' +# Following 16 basic colors is supported: +# default +# black +# red +# green +# yellow +# blue +# magenta +# cyan +# grey +# light_red +# light_green +# light_yellow +# light_blue +# light_magenta +# light_cyan +# white + +TWEET = { + 'nick' : grey, + 'clock' : grey, + 'id' : grey, + 'favourite' : light_green, + 'rt' : grey, + 'link' : light_cyan, + 'keyword' : on_light_yellow, +} + +MESSAGE = { + 'sender' : grey, + 'recipient' : grey, + 'to' : light_magenta, + 'clock' : grey, + 'id' : grey, +} + +PROFILE = { + 'statuses_count' : light_green, + 'friends_count' : light_green, + 'followers_count' : light_green, + 'nick' : grey, + 'profile_image_url' : light_cyan, + 'description' : light_yellow, + 'location' : light_magenta, + 'url' : light_cyan, + 'clock' : white, +} + +TREND = { + 'url': light_cyan +} \ No newline at end of file diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index d53d5ef..096074b 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -67,10 +67,10 @@ def draw(t, iot=False, keyword=None, fil=[], ig=[]): rid = res[0].rainbow_id # Format info - user = cycle_color(name) + grey(' ' + screen_name + ' ') - meta = grey('[' + clock + '] [id=' + str(rid) + '] ') + user = cycle_color(name) + TWEET['nick'](' ' + screen_name + ' ') + meta = TWEET['clock']('[' + clock + '] ') + TWEET['id']('[id=' + str(rid) + '] ') if favorited: - meta = meta + light_green(u'\u2605') + meta = meta + TWEET['favorite'](u'\u2605') tweet = text.split() # Replace url if expanded_url: @@ -79,15 +79,15 @@ def draw(t, iot=False, keyword=None, fil=[], ig=[]): lambda x: expanded_url[index] if x == url[index] else x, tweet) # Highlight RT - tweet = map(lambda x: grey(x) if x == 'RT' else x, tweet) + tweet = map(lambda x: TWEET['rt'](x) if x == 'RT' else x, tweet) # Highlight screen_name tweet = map(lambda x: cycle_color(x) if x[0] == '@' else x, tweet) # Highlight link - tweet = map(lambda x: light_cyan(x) if x[0:4] == 'http' else x, tweet) + tweet = map(lambda x: TWEET['link'](x) if x[0:4] == 'http' else x, tweet) # Highlight search keyword if keyword: tweet = map( - lambda x: on_light_yellow(x) if + lambda x: TWEET['keyword'](x) if ''.join(c for c in x if c.isalnum()).lower() == keyword.lower() else x, tweet @@ -139,11 +139,12 @@ def print_message(m): res = db.message_to_rainbow_query(mid) rid = res[0].rainbow_id - sender = cycle_color(sender_name) + grey(' ' + sender_screen_name + ' ') + # Draw + sender = cycle_color(sender_name) + MESSAGE['sender'](' ' + sender_screen_name + ' ') recipient = cycle_color( - recipient_name) + grey(' ' + recipient_screen_name + ' ') - user = sender + light_magenta(' >>> ') + recipient - meta = grey('[' + clock + '] [message_id=' + str(rid) + '] ') + recipient_name) + MESSAGE['recipient'](' ' + recipient_screen_name + ' ') + user = sender + MESSAGE['to'](' >>> ') + recipient + meta = MESSAGE['clock']('[' + clock + ']' + MESSAGE['id'](' [message_id=' + str(rid) + '] ') text = ''.join(map(lambda x: x + ' ' if x == '\n' else x, text)) line1 = u"{u:>{uw}}:".format( @@ -178,22 +179,24 @@ def show_profile(u, iot=False): statuses_count = u['statuses_count'] friends_count = u['friends_count'] followers_count = u['followers_count'] + # Create content - statuses_count = light_green(str(statuses_count) + ' tweets') - friends_count = light_green(str(friends_count) + ' following') - followers_count = light_green(str(followers_count) + ' followers') + statuses_count = PROFILE['statuses_count'](str(statuses_count) + ' tweets') + friends_count = PROFILE['friends_count'](str(friends_count) + ' following') + followers_count = PROFILE['followers_count'](str(followers_count) + ' followers') count = statuses_count + ' ' + friends_count + ' ' + followers_count - user = cycle_color(name) + grey(' @' + screen_name + ' : ') + count - profile_image_raw_url = 'Profile photo: ' + light_cyan(profile_image_url) + user = cycle_color(name) + PROFILE['nick'](' @' + screen_name + ' : ') + count + profile_image_raw_url = 'Profile photo: ' + PROFILE['profile_image_url'](profile_image_url) description = ''.join( map(lambda x: x + ' ' * 4 if x == '\n' else x, description)) - description = light_yellow(description) - location = 'Location : ' + light_magenta(location) - url = 'URL : ' + (light_cyan(url) if url else '') + description = PROFILE['description'](description) + location = 'Location : ' + PROFILE['location'](location) + url = 'URL : ' + (PROFILE['url'](url) if url else '') date = parser.parse(created_at) date = date - datetime.timedelta(seconds=time.timezone) clock = date.strftime('%Y/%m/%d %H:%M:%S') - clock = 'Join at ' + white(clock) + clock = 'Join at ' + PROFILE['clock'](clock) + # Format line1 = u"{u:>{uw}}".format( u=user, @@ -219,6 +222,7 @@ def show_profile(u, iot=False): c=clock, cw=len(clock) + 4, ) + # Display printNicely('') printNicely(line1) @@ -239,7 +243,7 @@ def print_trends(trends): for topic in trends[:TREND_MAX]: name = topic['name'] url = topic['url'] - line = cycle_color(name) + ': ' + light_cyan(url) + line = cycle_color(name) + ': ' + TREND['url'](url) printNicely(line) printNicely('') diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 91c115c..bc791b4 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -750,12 +750,12 @@ def cal(): date = ' '.join([cycle_color(i) for i in date.split(' ')]) today = str(int(os.popen('date +\'%d\'').read().strip())) # Display - print month - print date + printNicely(month) + printNicely(date) for line in rel: ary = line.split(' ') ary = map(lambda x: on_grey(x) if x == today else grey(x), ary) - print ' '.join(ary) + printNicely(' '.join(ary)) def help(): @@ -918,7 +918,7 @@ def reset(): printNicely(magenta('Need tips ? Type "h" and hit Enter key!')) g['reset'] = False try: - print eval(g['cmd']) + printNicely(eval(g['cmd'])) except: pass diff --git a/requirements.txt b/requirements.txt index 4f9f78a..1450c39 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ colorama==0.3.1 pyfiglet==0.6.1 python-dateutil==2.2 six==1.6.1 -termcolor==1.1.0 twitter==1.14.3 SQLAlchemy==0.9.4 pysqlite==2.6.3 diff --git a/setup.py b/setup.py index 7cf15ca..b4f59a0 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,6 @@ install_requires = [ "colorama", "pyfiglet", "python-dateutil", - "termcolor", "twitter", "Pillow", "requests",