mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-03-12 01:10:39 +01:00
Changed the signature of canonicalColor to return an (fg, bg) pair. Also accepts a shift parameter which is the number of bits to >> the hash of the string. Both are used in Relay.py.
This commit is contained in:
parent
ad432a640a
commit
199de7e71a
@ -244,8 +244,8 @@ def mircColor(s, fg=None, bg=None):
|
|||||||
bg = mircColors[bg]
|
bg = mircColors[bg]
|
||||||
return '\x03%s,%s%s\x03' % (fg, bg, s)
|
return '\x03%s,%s%s\x03' % (fg, bg, s)
|
||||||
|
|
||||||
def canonicalColor(s, bg=False):
|
def canonicalColor(s, bg=False, shift=0):
|
||||||
h = hash(s)
|
h = hash(s) >> shift
|
||||||
fg = h % 14 + 2 # The + 2 is to rule out black and white.
|
fg = h % 14 + 2 # The + 2 is to rule out black and white.
|
||||||
if bg:
|
if bg:
|
||||||
bg = (h >> 4) & 3 # The 5th, 6th, and 7th least significant bits.
|
bg = (h >> 4) & 3 # The 5th, 6th, and 7th least significant bits.
|
||||||
@ -253,9 +253,13 @@ def canonicalColor(s, bg=False):
|
|||||||
bg += 8
|
bg += 8
|
||||||
else:
|
else:
|
||||||
bg += 2
|
bg += 2
|
||||||
return mircColor(s, fg, bg)
|
return (fg, bg)
|
||||||
else:
|
else:
|
||||||
return mircColor(s, fg)
|
return (fg, None)
|
||||||
|
|
||||||
|
_unColorRe = re.compile('\x03(?:\\d+|\\d+,\\d+)?')
|
||||||
|
def unColor(s):
|
||||||
|
return _unColorRe.sub('', s)
|
||||||
|
|
||||||
def isValidArgument(s):
|
def isValidArgument(s):
|
||||||
"""Returns if s is strictly a valid argument for an IRC message."""
|
"""Returns if s is strictly a valid argument for an IRC message."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user