fgsdfgfdggdfg
This commit is contained in:
commit
a4c56bde06
|
@ -0,0 +1,63 @@
|
|||
import sys
|
||||
import re
|
||||
|
||||
irc_to_ansi_map = {
|
||||
'0': '15',
|
||||
'1': '0',
|
||||
'2': '18',
|
||||
'3': '2',
|
||||
'4': '196',
|
||||
'5': '52',
|
||||
'6': '92',
|
||||
'7': '208',
|
||||
'8': '226',
|
||||
'9': '10',
|
||||
'10': '45',
|
||||
'11': '14',
|
||||
'12': '12',
|
||||
'13': '201',
|
||||
'14': '243',
|
||||
'15': '250',
|
||||
}
|
||||
|
||||
def foreground(c):
|
||||
if c == None:
|
||||
return ''
|
||||
return f'\033[38;5;{c}m'
|
||||
|
||||
def background(c):
|
||||
if c == None:
|
||||
return ''
|
||||
return f'\033[48;5;{c}m'
|
||||
|
||||
def reset():
|
||||
return f'\033[0m'
|
||||
|
||||
_IRC_COLOR_PAT = re.compile(r'\x03(\d+),(\d+)')
|
||||
|
||||
#print(f'{background(201)}{foreground(45)}nigger')
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print('./irccolor2ansiesc.py <ascii>')
|
||||
exit()
|
||||
with open(sys.argv[1], mode='r', errors='replace') as ascii_handle:
|
||||
for line in ascii_handle:
|
||||
line = line.strip('\r\n')
|
||||
bits = line.split('\x03')
|
||||
for bit in bits:
|
||||
bit = "\x03" + bit
|
||||
res = _IRC_COLOR_PAT.findall(bit)
|
||||
if len(res) == 1:
|
||||
fg,bg = res[0]
|
||||
fg = irc_to_ansi_map.get(fg, None)
|
||||
bg = irc_to_ansi_map.get(bg, None)
|
||||
pat = r'[\x02\x0F\x16\x1D\x1F]|\x03(\d{,2}(,\d{,2})?)?'
|
||||
stripped = re.sub(pat, '', bit)
|
||||
print(f"{foreground(fg)}{background(bg)}{stripped}{reset()}", end='')
|
||||
else:
|
||||
print(bit, end='')
|
||||
print(reset()+"\n", end='')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue