# vim: set fileencoding=utf-8 # ^^ need this to appease python for using unicode literals in the source # # Copyright (c) 2011 Paul Erickson # # Everyone is permitted to copy and distribute verbatim or modified # copies of this license document, and changing it is allowed as long # as the name is changed. # # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # # 0. You just DO WHAT THE FUCK YOU WANT TO. import weechat as w SCRIPT_NAME = "unicool" SCRIPT_AUTHOR = "Paul Erickson " SCRIPT_VERSION = "1.0.0" SCRIPT_LICENSE = "WTFPL" SCRIPT_DESC = "Converts text to fancier utf-8 codespaces" normal = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] serif = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''] blackletter = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''] class Mapper: def __init__(self, keys, values): self.aDict = dict(zip(keys, values)) def map(self, aString): mappedString = "" for eachChar in list(aString): if eachChar in normal: eachChar = self.aDict[eachChar] mappedString += eachChar return mappedString serifMapper = Mapper(normal, serif) blackletterMapper = Mapper(normal, blackletter) if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): w.hook_command("serif", SCRIPT_DESC, " text", " text: text to be mapped to seriffy unicode", "", "serif_cmd_cb", "") w.hook_command("blackletter", SCRIPT_DESC, " text", " text: text to be mapped to blackletter unicode", "", "blackletter_cmd_cb", "") def serif_cmd_cb(data, buffer, args): input = args if not input: input = w.buffer_get_string(buffer, "input") output = serifMapper.map(input) w.buffer_set(buffer, 'input', output) w.buffer_set(buffer, 'input_pos', '%d' % len(output)) return w.WEECHAT_RC_OK def blackletter_cmd_cb(data, buffer, args): input = args if not input: input = w.buffer_get_string(buffer, "input") output = blackletterMapper.map(input) w.buffer_set(buffer, 'input', output) w.buffer_set(buffer, 'input_pos', '%d' % len(output)) return w.WEECHAT_RC_OK #TODO: make a master /unicool function with flags for each codespace #TODO: add number/punctuation chars #TODO: add other mappings?