From: vunhat_minh Date: Fri, 19 Sep 2014 08:36:26 +0000 (+0900) Subject: fix readline calculation messed up with color sequence X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be4dba0eaa164b49f37930e9fa41e240cd36f06c;p=rainbowstream.git fix readline calculation messed up with color sequence --- diff --git a/docs/conf.py b/docs/conf.py index 113b0ae..640b529 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 = '1.0.4' +version = '1.0.5' # The full version, including alpha/beta/rc tags. -release = '1.0.4' +release = '1.0.5' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rainbowstream/colors.py b/rainbowstream/colors.py index bdbc4b4..335847f 100644 --- a/rainbowstream/colors.py +++ b/rainbowstream/colors.py @@ -2,11 +2,12 @@ def basic_color(code): """ 16 colors supported """ - def inner(text, bold=True): + def inner(text, rl=False): c = code - if bold: - c = "1;%s" % c - return "\033[%sm%s\033[0m" % (c, text) + if rl: + return "\001\033[%sm\002%s\001\033[0m\002" % (c, text) + else: + return "\033[%sm%s\033[0m" % (c, text) return inner @@ -14,9 +15,12 @@ def term_color(code): """ 256 colors supported """ - def inner(text): + def inner(text, rl=False): c = code - return "\033[38;5;%sm%s\033[0m" % (c, text) + if rl: + return "\001\033[38;5;%sm\002%s\001\033[0m\002" % (c, text) + else: + return "\033[38;5;%sm%s\033[0m" % (c, text) return inner diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 5f7ab72..b4cd5f9 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -161,7 +161,7 @@ def init(args): c['original_name'] = g['original_name'] = screen_name[1:] g['full_name'] = name g['decorated_name'] = lambda x: color_func( - c['DECORATED_NAME'])('[' + x + ']: ') + c['DECORATED_NAME'])('[' + x + ']: ', rl=True) # Theme init files = os.listdir(os.path.dirname(__file__) + '/colorset') themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json'] @@ -366,7 +366,8 @@ def quote(): if not formater: return # Get comment - prefix = light_magenta('Compose your ') + light_green('#comment: ') + prefix = light_magenta('Compose your ', rl=True) + \ + light_green('#comment: ', rl=True) comment = raw_input(prefix) if comment: quote = comment.join(formater.split('#comment')) @@ -844,7 +845,8 @@ def get_slug(): Get slug """ # Get list name - list_name = raw_input(light_magenta('Give me the list\'s name ("@owner/list_name"): ')) + list_name = raw_input( + light_magenta('Give me the list\'s name ("@owner/list_name"): ', rl=True)) # Get list name and owner try: owner, slug = list_name.split('/') @@ -937,7 +939,10 @@ def list_add(t): """ owner, slug = get_slug() # Add - user_name = raw_input(light_magenta('Give me name of the newbie: ')) + user_name = raw_input( + light_magenta( + 'Give me name of the newbie: ', + rl=True)) if user_name.startswith('@'): user_name = user_name[1:] try: @@ -957,7 +962,10 @@ def list_remove(t): """ owner, slug = get_slug() # Remove - user_name = raw_input(light_magenta('Give me name of the unlucky one: ')) + user_name = raw_input( + light_magenta( + 'Give me name of the unlucky one: ', + rl=True)) if user_name.startswith('@'): user_name = user_name[1:] try: @@ -1027,9 +1035,15 @@ def list_new(t): """ Create a new list """ - name = raw_input(light_magenta('New list\'s name: ')) - mode = raw_input(light_magenta('New list\'s mode (public/private): ')) - description = raw_input(light_magenta('New list\'s description: ')) + name = raw_input(light_magenta('New list\'s name: ', rl=True)) + mode = raw_input( + light_magenta( + 'New list\'s mode (public/private): ', + rl=True)) + description = raw_input( + light_magenta( + 'New list\'s description: ', + rl=True)) try: t.lists.create( name=name, @@ -1045,10 +1059,16 @@ def list_update(t): """ Update a list """ - slug = raw_input(light_magenta('Your list that you want to update: ')) - name = raw_input(light_magenta('Update name (leave blank to unchange): ')) - mode = raw_input(light_magenta('Update mode (public/private): ')) - description = raw_input(light_magenta('Update description: ')) + slug = raw_input( + light_magenta( + 'Your list that you want to update: ', + rl=True)) + name = raw_input( + light_magenta( + 'Update name (leave blank to unchange): ', + rl=True)) + mode = raw_input(light_magenta('Update mode (public/private): ', rl=True)) + description = raw_input(light_magenta('Update description: ', rl=True)) try: if name: t.lists.update( @@ -1073,7 +1093,10 @@ def list_delete(t): """ Delete a list """ - slug = raw_input(light_magenta('Your list that you want to delete: ')) + slug = raw_input( + light_magenta( + 'Your list that you want to delete: ', + rl=True)) try: t.lists.destroy( slug='-'.join(slug.split()), @@ -1170,7 +1193,7 @@ def switch(): elif target == 'list': owner, slug = get_slug() # Force python 2 not redraw readline buffer - g['cmd'] = '/'.join([owner,slug]) + g['cmd'] = '/'.join([owner, slug]) printNicely(light_yellow('getting list members ...')) # Get members t = Twitter(auth=authen()) diff --git a/setup.py b/setup.py index d5f6bba..1e28de9 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os import os.path # Bumped version -version = '1.0.4' +version = '1.0.5' # Require install_requires = [