From 335e7803e51d6c981c422f835a102e3e51429d8f Mon Sep 17 00:00:00 2001 From: Orakaro Date: Wed, 6 Aug 2014 00:21:45 +0900 Subject: [PATCH] add HIDE_PROMPT config, timeout to check interval and fix readline bug with Python 3 --- docs/conf.py | 4 ++-- docs/index.rst | 4 +++- rainbowstream/colorset/config | 2 ++ rainbowstream/rainbow.py | 24 +++++++++--------------- setup.py | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7c71b88..0d7fd1d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/docs/index.rst b/docs/index.rst index d8a6927..545002b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -42,7 +42,7 @@ Use `virtualenv`_ Troubleshooting ^^^^^^^^^^^^^^^ -If you use Linux, you might need to install the python-dev package if you haven't already. +If you use Linux, you might need to install the python-dev package if you haven't already. For debian-based distros, these can be installed with .. code:: bash @@ -296,6 +296,8 @@ You can view or set a new value of every config key by ``config`` command (See * - ``ASCII_ART``: diplay your twitter name by ascii art at stream begin or not. +- ``HIDE_PROMPT``: Hide prompt after receiving a tweet or not. + - ``SEARCH_MAX_RECORD``: max tweets can display on 'search' command. - ``HOME_TWEET_NUM``: default tweets to display on 'home' command. diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config index 173f522..2003630 100644 --- a/rainbowstream/colorset/config +++ b/rainbowstream/colorset/config @@ -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 diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index eb8f636..f67ef18 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -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: diff --git a/setup.py b/setup.py index 20ce446..d95c411 100644 --- 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 = [ -- 2.25.1