Empty string is false
[rainbowstream.git] / rainbowstream / rainbow.py
index f06b510aa708d39896a8fa0ef1f07ba9b7b15514..377f7d6ed2a1968112f92000967b21d9b78255d8 100644 (file)
@@ -204,9 +204,8 @@ def init(args):
     name = credential['name']
     if not get_config('PREFIX'):
         set_config('PREFIX', screen_name)
-    c['PREFIX'] = emojize(c['PREFIX'])
-    g['PREFIX'] = u2str(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)
@@ -1244,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,
@@ -1258,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,
@@ -1272,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())
@@ -1409,7 +1409,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()))
             reload_config()
             printNicely(green('Updated successfully.'))
         except:
@@ -1964,7 +1964,7 @@ def reconn_notice():
         light_green("h stream") + \
         light_magenta(" for more details.")
     printNicely(guide)
-    sys.stdout.write(g['decorated_name'](c['PREFIX']))
+    sys.stdout.write(g['decorated_name'](g['PREFIX']))
     sys.stdout.flush()
 
 
@@ -2053,10 +2053,10 @@ def stream(domain, args, name='Rainbow Stream'):
                 # the 1st character of that word
                 if current_buffer and g['cmd'] != current_buffer:
                     sys.stdout.write(
-                        g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
+                        g['decorated_name'](g['PREFIX']) + current_buffer)
                     sys.stdout.flush()
                 elif not c['HIDE_PROMPT']:
-                    sys.stdout.write(g['decorated_name'](c['PREFIX']))
+                    sys.stdout.write(g['decorated_name'](g['PREFIX']))
                     sys.stdout.flush()
             elif tweet.get('direct_message'):
                 # Check the semaphore pause and lock (stream process only)
@@ -2073,7 +2073,7 @@ def stream(domain, args, name='Rainbow Stream'):
         printNicely(
             magenta("We have connection problem with twitter'stream API right now :("))
         detail_twitter_error(e)
-        sys.stdout.write(g['decorated_name'](c['PREFIX']))
+        sys.stdout.write(g['decorated_name'](g['PREFIX']))
         sys.stdout.flush()