From 2ad8623eb3491a05d2780b2b8c8590b706844d75 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 11 Nov 2019 12:06:16 +0000 Subject: add utils.irc.hash_colorize() to color a string by the string's hash --- src/utils/irc.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/utils') diff --git a/src/utils/irc.py b/src/utils/irc.py index 81db0113..59151a75 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -41,6 +41,11 @@ def color(s: str, foreground: consts.IRCColor, return "%s%s%s%s%s" % (consts.COLOR, foreground_s, background_s, s, consts.COLOR) +HASH_COLORS = list(range(2, 16)) +def hash_colorize(s: str): + code = hash(s)%len(HASH_COLORS) + return color(s, consts.COLOR_CODES[code]) + def bold(s: str) -> str: return "%s%s%s" % (consts.BOLD, s, consts.BOLD) -- cgit v1.3.1-10-gc9f91