add -p flag

specify colour palette to use
This commit is contained in:
wowaname 2016-09-30 22:43:28 +00:00
parent f5139cb351
commit dd219645d0

View File

@ -8,39 +8,17 @@
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
# #
# 0. You just DO WHAT THE FUCK YOU WANT TO. # 0. You just DO WHAT THE FUCK YOU WANT TO.
# 2016-08-02, wowaname <wowaname@volatile.ch>
# v0.3: add -x, fork to prismx.py
# 2015-11-16, wowaname <wowaname@volatile.ch>
# v0.2.9: wrote an actual parser rather than regex
# 2014-09-03, Matthew Martin <phy1729@gmail.com>
# v0.2.8: add color reset to the end of the output
# 2013-11-26, Seganku <seganku@zenu.net>
# v0.2.7: add -c switch for the option to pass output to a command
# 2013-07-19, Sebastien Helleu <flashcode@flashtux.org>
# v0.2.6: use buffer received in command callback instead of current buffer
# 2013-05-04, Rylai
# v0.2.5: add -e switch for the option to destroy the eyes of all
# who have the misfortune of seeing your text
# 2013-04-26, Biohazard
# v0.2.4: add support for using the command through keybindings
# 2013-03-12, R1cochet
# v0.2.3: add -b switch for backwards/reverse text
# 2013-01-29, SuperT1R:
# v0.2.2: add -m switch to append /me to the beginning of the output
import weechat as w import weechat as w
import random import random
import re import re
SCRIPT_NAME = "prismx" SCRIPT_NAME = "prismx"
SCRIPT_AUTHOR = "Alex Barrett <al.barrett@gmail.com>" SCRIPT_AUTHOR = "Alex Barrett <al.barrett@gmail.com>"
SCRIPT_VERSION = "0.3" SCRIPT_VERSION = "0.3.1"
SCRIPT_LICENSE = "WTFPL" SCRIPT_LICENSE = "WTFPL"
SCRIPT_DESC = "Taste the rainbow." SCRIPT_DESC = "Taste the rainbow."
# red, lightred, brown, yellow, green, lightgreen, cyan, # red, lightred, brown, yellow, green, lightgreen, cyan,
# lightcyan, blue, lightblue, magenta, lightmagenta # lightcyan, blue, lightblue, magenta, lightmagenta
ncolors = [5, 4, 7, 8, 3, 9, 10, 11, 2, 12, 6, 13] ncolors = [5, 4, 7, 8, 3, 9, 10, 11, 2, 12, 6, 13]
@ -67,19 +45,20 @@ regex_words = "[^%(n)s]+[%(n)s%(s)s]*" % { 'n': chars_neutral, 's': chars_contro
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
SCRIPT_LICENSE, SCRIPT_DESC, "", ""): SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
w.hook_command("prism", w.hook_command("prism",
SCRIPT_DESC, SCRIPT_DESC,
"[-rwmbe] text|-c[wbe] <sep> <command> <sep>text", "[-rwmbexsp] [palette] text|-c[wbexsp] [palette] <sep> <command> <sep>text",
" -r: randomizes the order of the color sequence\n" " -r: randomizes the order of the color sequence\n"
" -w: color entire words instead of individual characters\n" " -w: color entire words instead of individual characters\n"
" -m: append /me to beginning of output\n" " -m: append /me to beginning of output\n"
" -b: backwards text (entire string is reversed)\n" " -b: backwards text (entire string is reversed)\n"
" -e: eye-destroying colors (randomized background colors)\n" " -e: eye-destroying colors (randomized background colors)\n"
" -c: specify a separator to turn on colorization\n" " -c: specify a separator to turn on colorization\n"
" eg. -c : /topic :howdy howdy howdy\n" " eg. -c : /topic :howdy howdy howdy\n"
" -x: extended color set, requires 256color terminal\n" " -x: extended color set, requires 256color terminal\n"
" -s: stretch to fit text\n" " -s: stretch to fit text\n"
" text: text to be colored", " -p: specify color palette to use, comma separated\n"
"-r|-w|-m|-b|-e|-c", "prism_cmd_cb", "") " text: text to be colored",
"-r|-w|-m|-b|-e|-c", "prism_cmd_cb", "")
def prism_cmd_cb(data, buffer, args): def prism_cmd_cb(data, buffer, args):
global color_index global color_index
@ -107,11 +86,16 @@ def prism_cmd_cb(data, buffer, args):
where = input.find(find, cmdstop+1) where = input.find(find, cmdstop+1)
cmd = input[cmdstop+1:where] cmd = input[cmdstop+1:where]
input = input[where+len(find):] input = input[where+len(find):]
else: input = input[optstop+bool(optstop):] else:
input = input[optstop+bool(optstop):]
regex = regex_words if 'w' in opts else regex_chars regex = regex_words if 'w' in opts else regex_chars
inc = 'r' not in opts inc = 'r' not in opts
bs = 'e' in opts bs = 'e' in opts
colors = ncolors if 'x' not in opts else (xxcolors if bs or not inc else xcolors) colors = ncolors if 'x' not in opts else (xxcolors if bs or not inc else xcolors)
if 'p' in opts:
i = input.find(' ')
colors = input[:i].split(',')
input = input[i+1:]
input = input[::-1] if 'b' in opts else input input = input[::-1] if 'b' in opts else input
output = u"" output = u""
tokens = re.findall(regex, input) tokens = re.findall(regex, input)