X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Fcolors.py;h=a39dcb6b0c41ac9d78e1495c27e92bf4cda17d56;hp=bdbc4b44c14d6af7c4009af898b13ed3e86bd44f;hb=0e6d22d6fb2c54f5eb37028da1414279e2d1a625;hpb=531f568231af56035b61bb196b0e43fa79ff223e diff --git a/rainbowstream/colors.py b/rainbowstream/colors.py index bdbc4b4..a39dcb6 100644 --- a/rainbowstream/colors.py +++ b/rainbowstream/colors.py @@ -2,11 +2,16 @@ def basic_color(code): """ 16 colors supported """ - def inner(text, bold=True): + def inner(text, rl=False): + """ + Every raw_input with color sequences should be called with + rl=True to avoid readline messed up the length calculation + """ 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 +19,16 @@ def term_color(code): """ 256 colors supported """ - def inner(text): + def inner(text, rl=False): + """ + Every raw_input with color sequences should be called with + rl=True to avoid readline messed up the length calculation + """ 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