cleanup PR 70
[rainbowstream.git] / rainbowstream / rainbow.py
index ff654091bfb1187649025ad66aad7fd044c2a359..48f207fc607fa25941bb7bf2ad4ee9bc837567a3 100644 (file)
@@ -178,6 +178,11 @@ def upgrade_center():
             notice += light_magenta('You should upgrade with ')
             notice += light_green('pip install -U rainbowstream')
             printNicely(notice)
+        else:
+            notice = light_yellow('You are running latest version (')
+            notice += light_green(current)
+            notice += light_yellow(')')
+            printNicely(notice)
     except:
         pass
 
@@ -1660,6 +1665,7 @@ def help():
     usage += s * 2 + light_green('p') + ' will pause the stream.\n'
     usage += s * 2 + light_green('r') + ' will unpause the stream.\n'
     usage += s * 2 + light_green('c') + ' will clear the screen.\n'
+    usage += s * 2 + light_green('v') + ' will show version info.\n'
     usage += s * 2 + light_green('q') + ' will quit.\n'
     # End
     usage += '\n'
@@ -1778,7 +1784,8 @@ cmdset = [
     'p',
     'r',
     'c',
-    'q'
+    'v',
+    'q',
 ]
 
 # Handle function set
@@ -1824,7 +1831,8 @@ funcset = [
     pause,
     replay,
     clear,
-    quit
+    upgrade_center,
+    quit,
 ]
 
 
@@ -1902,6 +1910,7 @@ def listen():
             [],  # pause
             [],  # reconnect
             [],  # clear
+            [],  # version
             [],  # quit
         ]
     ))
@@ -2018,34 +2027,36 @@ def stream(domain, args, name='Rainbow Stream'):
                 StreamLock.release()
                 break
             elif tweet.get('text'):
-                if time.time() - last_tweet_time >= get_config("STREAM_DELAY"):
-                  last_tweet_time = time.time()
-                  # Check the semaphore pause and lock (stream process only)
-                  if g['pause']:
-                      continue
-                  while c['lock']:
-                      time.sleep(0.5)
-                  # Draw the tweet
-                  draw(
-                      t=tweet,
-                      keyword=args.track_keywords,
-                      humanize=False,
-                      fil=args.filter,
-                      ig=args.ignore,
-                  )
-                  # Current readline buffer
-                  current_buffer = readline.get_line_buffer().strip()
-                  # There is an unexpected behaviour in MacOSX readline + Python 2:
-                  # after completely delete a word after typing it,
-                  # somehow readline buffer still contains
-                  # 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))
-                      sys.stdout.flush()
-                  elif not c['HIDE_PROMPT']:
-                      sys.stdout.write(g['decorated_name'](c['PREFIX']))
-                      sys.stdout.flush()
+                # Slow down the stream by STREAM_DELAY config key
+                if time.time() - last_tweet_time < c['STREAM_DELAY']:
+                    continue
+                last_tweet_time = time.time()
+                # Check the semaphore pause and lock (stream process only)
+                if g['pause']:
+                    continue
+                while c['lock']:
+                    time.sleep(0.5)
+                # Draw the tweet
+                draw(
+                    t=tweet,
+                    keyword=args.track_keywords,
+                    humanize=False,
+                    fil=args.filter,
+                    ig=args.ignore,
+                )
+                # Current readline buffer
+                current_buffer = readline.get_line_buffer().strip()
+                # There is an unexpected behaviour in MacOSX readline + Python 2:
+                # after completely delete a word after typing it,
+                # somehow readline buffer still contains
+                # 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))
+                    sys.stdout.flush()
+                elif not c['HIDE_PROMPT']:
+                    sys.stdout.write(g['decorated_name'](c['PREFIX']))
+                    sys.stdout.flush()
             elif tweet.get('direct_message'):
                 # Check the semaphore pause and lock (stream process only)
                 if g['pause']: