Goodbye readchar

This commit is contained in:
edschuy95 2026-01-10 17:22:43 -05:00
parent 845ce2c622
commit 66d5032085
12 changed files with 480 additions and 3641 deletions

View file

@ -6,8 +6,7 @@ import sys
import random
import re
import queue
import readchar
#import winpty
#import readchar
import ctypes
import subprocess
@ -308,43 +307,6 @@ def change_mode():
send_command(pty_proc,f"echo _musicmode {current_mode}")
playlist = load_playlist(playlist_path)
#def adjust_volume(up=True):
# global volume
# volume = min(1.0, max(0.0, volume + (VOLUME_STEP if up else -VOLUME_STEP)))
# pygame.mixer.music.set_volume(volume)
# print(f"[DEBUG] Volume: {volume:.2f}")
# ==========================================================
# ==================== QUAKE MONITOR ======================
# def monitor_game(pty_proc):
# #pty version
# global serverstatus_sent
# buffer = ""
# while not stop_flag.is_set() or shutdown_event.is_set():
# try:
# data = pty_proc.read(1024)
# if not data:
# break
# # Normalize to string
# if isinstance(data, bytes):
# data = data.decode(errors="ignore")
# buffer += data
# while "\n" in buffer:
# line, buffer = buffer.split("\n", 1)
# line = strip_ansi(line).strip()
# if line:
# #print(f"[GAME] {line}")
# #print(f"[GAME RAW] {repr(line)}")
# handle_game_line(line, pty_proc)
# except EOFError or KeyboardInterrupt:
# break
def monitor_game(proc):
#subprocess version
global serverstatus_sent
@ -369,7 +331,6 @@ def monitor_game(proc):
handle_game_line(line, proc)
def handle_game_line(line, pty_proc):
global volume, current_map, ra3_maps, ra3_maps_path, volumecheck, is_ra3, gametypecheck, is_playing, arenacheck, is_in_map, is_ra3_map, last_arena0
global serverstatus_sent
@ -478,15 +439,6 @@ def handle_game_line(line, pty_proc):
threading.Timer(.3, lambda: stop_playback()).start()
#stop_playback()
# def send_command(pty_proc, cmd):
# # winpty version
# try:
# pty_proc.write(cmd + "\r\n")
# pty_proc.flush()
# #print(f"[DEBUG] Sent command: {cmd}")
# except Exception as e:
# print(f"[DEBUG] Failed to send command: {e}")
def send_command(proc, cmd):
#subprocess version
try:
@ -497,19 +449,19 @@ def send_command(proc, cmd):
# ==========================================================
# ==================== KEYBOARD HANDLER ===================
def keyboard_listener():
while not stop_flag.is_set():
key = readchar.readkey()
if key.lower() == '[':
previous_track()
elif key.lower() == ']':
next_track()
elif key == '\'':
toggle_pause()
elif key == '\\':
change_mode()
# ==========================================================
# # ==================== KEYBOARD HANDLER ===================
# def keyboard_listener():
# while not stop_flag.is_set():
# key = readchar.readkey()
# if key.lower() == '[':
# previous_track()
# elif key.lower() == ']':
# next_track()
# elif key == '\'':
# toggle_pause()
# elif key == '\\':
# change_mode()
# # ==========================================================
# ======================== MAIN ===========================
def main():
@ -548,15 +500,7 @@ def main():
# Start track watcher thread
watcher_thread = threading.Thread(target=track_watcher, daemon=True)
watcher_thread.start()
# # Launch quake process via PTY
# try:
# pty_proc = winpty.PtyProcess.spawn([game_exe, "--showterminalconsole",] + sys.argv[1:] )
# except Exception as e:
# print(f"Failed to start game: {e}")
# return
# # Launch quake process via subprocess
pty_proc = subprocess.Popen(
[game_exe, "--showterminalconsole"] + sys.argv[1:],