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)
|
||||
|
||||
colors = {
|
||||
"Z": ["a", "a"],
|
||||
"B": ["a", "b"],
|
||||
"G": ["a", "c"],
|
||||
"b": ["a", "d"],
|
||||
"R": ["a", "e"],
|
||||
"r": ["a", "f"],
|
||||
"Y": ["a", "g"],
|
||||
"W": ["a", "h"]
|
||||
"Z": "a", # Black
|
||||
"B": "b", # Blue
|
||||
"G": "c", # Green
|
||||
"M": "d", # Magenta
|
||||
"R": "e", # Red
|
||||
"P": "f", # Pink
|
||||
"Y": "g", # Yellow
|
||||
"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):
|
||||
|
@ -44,14 +52,14 @@ def printchar(c):
|
|||
release_keys()
|
||||
|
||||
|
||||
def change_color(c: str):
|
||||
if c in colors:
|
||||
def change_color(background: str, foreground: str):
|
||||
if background in colors and foreground in colors and background.isupper():
|
||||
# DELETE keypress
|
||||
write_report(NULL_CHAR*2+chr(0x2a)+NULL_CHAR*5)
|
||||
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()
|
||||
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:
|
||||
write_report(chr(32)+NULL_CHAR+chr(0x38)+NULL_CHAR*5)
|
||||
release_keys()
|
||||
|
@ -59,16 +67,17 @@ def change_color(c: str):
|
|||
|
||||
def printstring(s):
|
||||
last_c = ''
|
||||
last_last_c = ''
|
||||
for c in s:
|
||||
if last_c == '§':
|
||||
change_color(c)
|
||||
elif c != '§':
|
||||
if last_last_c == '§':
|
||||
change_color(last_c, c)
|
||||
elif c != '§' and last_c != '§':
|
||||
printchar(c)
|
||||
last_c = c
|
||||
last_c, last_last_c = c, last_c
|
||||
|
||||
|
||||
def reset_color():
|
||||
change_color('G')
|
||||
change_color('Z', 'g')
|
||||
release_keys()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue