Merge pull request #73 from polarkac/custom_prefix
[rainbowstream.git] / rainbowstream / rainbow.py
index 236c1b831e1c8b46688d81e3d9f3955c12ce1394..fe144015df00367a566d8e0a1b5cc0abf4cd23b2 100644 (file)
@@ -204,8 +204,9 @@ 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['listname'] = g['keyword'] = ''
+    g['PREFIX'] = u2str(emojize(format_prefix()))
     g['full_name'] = name
     g['decorated_name'] = lambda x: color_func(
         c['DECORATED_NAME'])('[' + x + ']: ', rl=True)
@@ -1242,8 +1243,12 @@ def switch():
             # Kill old thread
             g['stream_stop'] = True
             args.track_keywords = keyword
+            # Set the variable to tracked keyword
+            # and reset the listname
+            g['keyword'] = keyword
+            g['listname'] = ''
             # Reset prefix
-            g['PREFIX'] = u2str(emojize(c['PREFIX']))
+            g['PREFIX'] = u2str(emojize(format_prefix(keyword = g['keyword'])))
             # Start new thread
             th = threading.Thread(
                 target=stream,
@@ -1256,8 +1261,10 @@ def switch():
         elif target == 'mine':
             # Kill old thread
             g['stream_stop'] = True
+            # Reset the tracked keyword and listname
+            g['keyword'] = g['listname'] = ''
             # Reset prefix
-            g['PREFIX'] = u2str(emojize(c['PREFIX']))
+            g['PREFIX'] = u2str(emojize(format_prefix()))
             # Start new thread
             th = threading.Thread(
                 target=stream,
@@ -1271,7 +1278,12 @@ 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])
+            # Set the listname variable 
+            # and reset tracked keyword
+            g['listname'] = listname
+            g['keyword'] = ''
+            g['PREFIX'] = g['cmd'] = u2str(emojize(format_prefix(listname = g['listname'])))
             printNicely(light_yellow('getting list members ...'))
             # Get members
             t = Twitter(auth=authen())
@@ -1408,7 +1420,7 @@ def config():
                 g['decorated_name'] = lambda x: color_func(
                     c['DECORATED_NAME'])('[' + x + ']: ')
             elif key == 'PREFIX':
-                g['PREFIX'] = u2str(emojize(c['PREFIX']))
+                g['PREFIX'] = u2str(emojize(format_prefix(listname = g['listname'], keyword = g['keyword'])))
             reload_config()
             printNicely(green('Updated successfully.'))
         except: