From: Lukas Pohlreich Date: Fri, 24 Oct 2014 13:50:51 +0000 (+0200) Subject: Custom prefix with formatting X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=commitdiff_plain;h=b85ec13a903fc1e7b2f52b451f34ab4b52eda375 Custom prefix with formatting --- diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 236c1b8..1b6e5c9 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -204,8 +204,8 @@ def init(args): name = credential['name'] if not get_config('PREFIX'): set_config('PREFIX', screen_name) - g['PREFIX'] = u2str(emojize(c['PREFIX'])) c['original_name'] = g['original_name'] = screen_name[1:] + g['PREFIX'] = u2str(emojize(format_prefix())) g['full_name'] = name g['decorated_name'] = lambda x: color_func( c['DECORATED_NAME'])('[' + x + ']: ', rl=True) @@ -1243,7 +1243,7 @@ def switch(): g['stream_stop'] = True args.track_keywords = keyword # Reset prefix - g['PREFIX'] = u2str(emojize(c['PREFIX'])) + g['PREFIX'] = u2str(emojize(format_prefix(keyword = keyword))) # Start new thread th = threading.Thread( target=stream, @@ -1257,7 +1257,7 @@ def switch(): # Kill old thread g['stream_stop'] = True # Reset prefix - g['PREFIX'] = u2str(emojize(c['PREFIX'])) + g['PREFIX'] = u2str(emojize(format_prefix())) # Start new thread th = threading.Thread( target=stream, @@ -1271,7 +1271,8 @@ def switch(): elif target == 'list': owner, slug = get_slug() # Force python 2 not redraw readline buffer - g['PREFIX'] = g['cmd'] = '/'.join([owner, slug]) + listname = '/'.join([owner, slug]) + g['PREFIX'] = g['cmd'] = u2str(emojize(format_prefix(listname = listname))) printNicely(light_yellow('getting list members ...')) # Get members t = Twitter(auth=authen()) diff --git a/rainbowstream/util.py b/rainbowstream/util.py index e8d3c74..1451aec 100644 --- a/rainbowstream/util.py +++ b/rainbowstream/util.py @@ -2,6 +2,7 @@ import json from twitter.util import printNicely from .colors import * +from .config import * def detail_twitter_error(twitterException): @@ -18,3 +19,25 @@ def detail_twitter_error(twitterException): except: info = "Error: " + twitterException.response_data.decode('utf8') printNicely(yellow(info)) + + +def format_prefix(listname = '', keyword = ''): + """ + Format the custom prefix + """ + formattedPrefix = c['PREFIX'] + username = '@' + c['original_name'] + place = '' + if keyword != '': + place = '/public' + keyword = '#' + keyword + + if listname != '': + username, place = listname.split('/') + place = "/" + place + + formattedPrefix = formattedPrefix.replace("#username", username) + formattedPrefix = formattedPrefix.replace("#place", place) + formattedPrefix = formattedPrefix.replace("#keyword", keyword) + + return formattedPrefix