Custom prefix with formatting
authorLukas Pohlreich <pohlreichlukas@gmail.com>
Fri, 24 Oct 2014 13:50:51 +0000 (15:50 +0200)
committerLukas Pohlreich <pohlreichlukas@gmail.com>
Fri, 24 Oct 2014 13:50:51 +0000 (15:50 +0200)
rainbowstream/rainbow.py
rainbowstream/util.py

index 236c1b8..1b6e5c9 100644 (file)
@@ -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())
index e8d3c74..1451aec 100644 (file)
@@ -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