add HIDE_PROMPT config, timeout to check interval and fix readline bug with Python 3
authorOrakaro <nhatminh_179@hotmail.com>
Tue, 5 Aug 2014 15:21:45 +0000 (00:21 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Tue, 5 Aug 2014 15:21:45 +0000 (00:21 +0900)
docs/conf.py
docs/index.rst
rainbowstream/colorset/config
rainbowstream/rainbow.py
setup.py

index 7c71b88..0d7fd1d 100644 (file)
@@ -48,9 +48,9 @@ copyright = u'2014, Vu Nhat Minh'
 # built documents.
 #
 # The short X.Y version.
-version = '0.6.3'
+version = '0.6.4'
 # The full version, including alpha/beta/rc tags.
-release = '0.6.3'
+release = '0.6.4'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
index d8a6927..545002b 100644 (file)
@@ -42,7 +42,7 @@ Use `virtualenv`_
 Troubleshooting\r
 ^^^^^^^^^^^^^^^\r
 \r
-If you use Linux, you might need to install the python-dev package if you haven't already. \r
+If you use Linux, you might need to install the python-dev package if you haven't already.\r
 For debian-based distros, these can be installed with\r
 \r
 .. code:: bash\r
@@ -296,6 +296,8 @@ You can view or set a new value of every config key by ``config`` command (See *
 \r
 -  ``ASCII_ART``: diplay your twitter name by ascii art at stream begin or not.\r
 \r
+-  ``HIDE_PROMPT``: Hide prompt after receiving a tweet or not.\r
+\r
 -  ``SEARCH_MAX_RECORD``: max tweets can display on 'search' command.\r
 \r
 -  ``HOME_TWEET_NUM``: default tweets to display on 'home' command.\r
index 173f522..2003630 100644 (file)
@@ -5,6 +5,8 @@
     "THEME" : "monokai",
     // Ascii Art
     "ASCII_ART" : true,
+    // Hide promt when receive a tweet
+    "HIDE_PROMPT" : true,
     // Prefix
     "PREFIX" : "",
     // 'search': max search record
index eb8f636..f67ef18 100644 (file)
@@ -158,7 +158,6 @@ def init(args):
     themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
     g['themes'] = themes
     # Startup cmd
-    g['OSX_readline_bug'] = False
     g['previous_cmd'] = ''
     # Semaphore init
     c['lock'] = False
@@ -1631,10 +1630,6 @@ def listen():
             cmd = line.split()[0]
         except:
             cmd = ''
-        # MacOSX readline bug (see "stream" function)
-        if g['OSX_readline_bug']:
-            cmd = cmd[1:]
-            g['OSX_readline_bug'] = False
         g['cmd'] = cmd
         try:
             # Lock the semaphore
@@ -1668,7 +1663,7 @@ def stream(domain, args, name='Rainbow Stream'):
         ascii_art(art_dict[domain])
     # These arguments are optional:
     stream_args = dict(
-        timeout=args.timeout,
+        timeout=0.5, # To check g['stream_stop'] after each 0.5 s
         block=not args.no_block,
         heartbeat_timeout=args.heartbeat_timeout)
     # Track keyword
@@ -1694,13 +1689,12 @@ def stream(domain, args, name='Rainbow Stream'):
         StreamLock.acquire()
         g['stream_stop'] = False
         for tweet in tweet_iter:
-            if(g['stream_stop']):
-                StreamLock.release()
-                break
             if tweet is None:
                 printNicely("-- None --")
             elif tweet is Timeout:
-                printNicely("-- Timeout --")
+                if(g['stream_stop']):
+                    StreamLock.release()
+                    break
             elif tweet is HeartbeatTimeout:
                 printNicely("-- Heartbeat Timeout --")
             elif tweet is Hangup:
@@ -1715,17 +1709,17 @@ def stream(domain, args, name='Rainbow Stream'):
                 )
                 # Current readline buffer
                 current_buffer = readline.get_line_buffer().strip()
-                # There is an unexpected behaviour in MacOSX readline:
+                # 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 g['previous_cmd'] != current_buffer:
-                    if len(current_buffer) == 1:
-                        current_buffer = ''
-                        g['OSX_readline_bug'] = True
+                if current_buffer and g['previous_cmd'] != current_buffer:
                     sys.stdout.write(
                         g['decorated_name'](c['PREFIX']) + 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'):
                 print_message(tweet['direct_message'], check_semaphore=True)
     except TwitterHTTPError:
index 20ce446..d95c411 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ import os
 import os.path
 
 # Bumped version
-version = '0.6.3'
+version = '0.6.4'
 
 # Require
 install_requires = [