add background support
This commit is contained in:
parent
af0099ba82
commit
8a5b554240
1 changed files with 26 additions and 17 deletions
43
server.py
43
server.py
|
@ -9,14 +9,22 @@ import base64
|
||||||
NULL_CHAR = chr(0)
|
NULL_CHAR = chr(0)
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
"Z": ["a", "a"],
|
"Z": "a", # Black
|
||||||
"B": ["a", "b"],
|
"B": "b", # Blue
|
||||||
"G": ["a", "c"],
|
"G": "c", # Green
|
||||||
"b": ["a", "d"],
|
"M": "d", # Magenta
|
||||||
"R": ["a", "e"],
|
"R": "e", # Red
|
||||||
"r": ["a", "f"],
|
"P": "f", # Pink
|
||||||
"Y": ["a", "g"],
|
"Y": "g", # Yellow
|
||||||
"W": ["a", "h"]
|
"W": "h", # White
|
||||||
|
"z": "i", # Light Black
|
||||||
|
"b": "j", # Light Blue
|
||||||
|
"g": "k", # Light Green
|
||||||
|
"m": "l", # Light Magenta
|
||||||
|
"r": "m", # Light Red
|
||||||
|
"p": "n", # Light Pink
|
||||||
|
"y": "o", # Light Yellow
|
||||||
|
"w": "p" # Light White
|
||||||
}
|
}
|
||||||
|
|
||||||
def write_report(report):
|
def write_report(report):
|
||||||
|
@ -44,14 +52,14 @@ def printchar(c):
|
||||||
release_keys()
|
release_keys()
|
||||||
|
|
||||||
|
|
||||||
def change_color(c: str):
|
def change_color(background: str, foreground: str):
|
||||||
if c in colors:
|
if background in colors and foreground in colors and background.isupper():
|
||||||
# DELETE keypress
|
# DELETE keypress
|
||||||
write_report(NULL_CHAR*2+chr(0x2a)+NULL_CHAR*5)
|
write_report(NULL_CHAR*2+chr(0x2a)+NULL_CHAR*5)
|
||||||
release_keys()
|
release_keys()
|
||||||
write_report(NULL_CHAR*2+chr(4 + ord(colors[c][0]) - ord('a'))+NULL_CHAR*5)
|
write_report(NULL_CHAR*2+chr(4 + ord(colors[background]) - ord('a'))+NULL_CHAR*5)
|
||||||
release_keys()
|
release_keys()
|
||||||
write_report(NULL_CHAR*2+chr(4 + ord(colors[c][1]) - ord('a'))+NULL_CHAR*5)
|
write_report(NULL_CHAR*2+chr(4 + ord(colors[foreground]) - ord('a'))+NULL_CHAR*5)
|
||||||
else:
|
else:
|
||||||
write_report(chr(32)+NULL_CHAR+chr(0x38)+NULL_CHAR*5)
|
write_report(chr(32)+NULL_CHAR+chr(0x38)+NULL_CHAR*5)
|
||||||
release_keys()
|
release_keys()
|
||||||
|
@ -59,16 +67,17 @@ def change_color(c: str):
|
||||||
|
|
||||||
def printstring(s):
|
def printstring(s):
|
||||||
last_c = ''
|
last_c = ''
|
||||||
|
last_last_c = ''
|
||||||
for c in s:
|
for c in s:
|
||||||
if last_c == '§':
|
if last_last_c == '§':
|
||||||
change_color(c)
|
change_color(last_c, c)
|
||||||
elif c != '§':
|
elif c != '§' and last_c != '§':
|
||||||
printchar(c)
|
printchar(c)
|
||||||
last_c = c
|
last_c, last_last_c = c, last_c
|
||||||
|
|
||||||
|
|
||||||
def reset_color():
|
def reset_color():
|
||||||
change_color('G')
|
change_color('Z', 'g')
|
||||||
release_keys()
|
release_keys()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue