mirror of
https://github.com/TheBlewish/Automated-AI-Web-Researcher-Ollama.git
synced 2025-01-19 00:47:46 +00:00
Update Web-LLM.py for windows
Updated input handling to use msvcrt Modified get_multiline_input function Updated system messages for Windows (CTRL+Z instead of CTRL+D) Added Windows-specific checks Removed Unix-specific imports
This commit is contained in:
parent
82e6321461
commit
a53d85e284
60
Web-LLM.py
60
Web-LLM.py
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import msvcrt
|
||||
import os
|
||||
from colorama import init, Fore, Style
|
||||
import logging
|
||||
|
@ -12,10 +13,9 @@ from strategic_analysis_parser import StrategicAnalysisParser
|
|||
from research_manager import ResearchManager
|
||||
|
||||
# Initialize colorama
|
||||
if os.name == 'nt': # Windows-specific initialization
|
||||
init(convert=True, strip=False, wrap=True)
|
||||
else:
|
||||
init()
|
||||
if os.name != 'nt':
|
||||
print("This version is Windows-specific. Please use the Unix version for other operating systems.")
|
||||
sys.exit(1)
|
||||
|
||||
# Set up logging
|
||||
log_directory = 'logs'
|
||||
|
@ -68,65 +68,52 @@ def print_header():
|
|||
- For research mode: start message with '@'
|
||||
Example: "@analyze the impact of AI on healthcare"
|
||||
|
||||
Press CTRL+D (Linux/Mac) or CTRL+Z (Windows) to submit input.
|
||||
Press CTRL+Z to submit input.
|
||||
""" + Style.RESET_ALL)
|
||||
|
||||
def get_multiline_input() -> str:
|
||||
"""Get multiline input using raw terminal mode for reliable CTRL+D handling"""
|
||||
print(f"{Fore.GREEN}📝 Enter your message (Press CTRL+D to submit):{Style.RESET_ALL}")
|
||||
"""Windows-compatible multiline input handler"""
|
||||
print(f"{Fore.GREEN}📝 Enter your message (Press CTRL+Z to submit):{Style.RESET_ALL}")
|
||||
lines = []
|
||||
|
||||
import termios
|
||||
import tty
|
||||
import sys
|
||||
|
||||
# Save original terminal settings
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
current_line = []
|
||||
|
||||
try:
|
||||
# Set terminal to raw mode
|
||||
tty.setraw(fd)
|
||||
|
||||
current_line = []
|
||||
while True:
|
||||
# Read one character at a time
|
||||
char = sys.stdin.read(1)
|
||||
if msvcrt.kbhit():
|
||||
char = msvcrt.getch()
|
||||
|
||||
# CTRL+D detection
|
||||
if not char or ord(char) == 4: # EOF or CTRL+D
|
||||
sys.stdout.write('\n') # New line for clean display
|
||||
# CTRL+Z detection (Windows equivalent of CTRL+D)
|
||||
if char in [b'\x1a', b'\x04']: # CTRL+Z or CTRL+D
|
||||
sys.stdout.write('\n')
|
||||
if current_line:
|
||||
lines.append(''.join(current_line))
|
||||
return ' '.join(lines).strip()
|
||||
|
||||
# Handle special characters
|
||||
elif ord(char) == 13: # Enter
|
||||
elif char == b'\r': # Enter
|
||||
sys.stdout.write('\n')
|
||||
lines.append(''.join(current_line))
|
||||
current_line = []
|
||||
|
||||
elif ord(char) == 127: # Backspace
|
||||
elif char == b'\x08': # Backspace
|
||||
if current_line:
|
||||
current_line.pop()
|
||||
sys.stdout.write('\b \b') # Erase character
|
||||
sys.stdout.write('\b \b')
|
||||
|
||||
elif ord(char) == 3: # CTRL+C
|
||||
elif char == b'\x03': # CTRL+C
|
||||
sys.stdout.write('\n')
|
||||
return 'q'
|
||||
|
||||
# Normal character
|
||||
elif 32 <= ord(char) <= 126: # Printable characters
|
||||
current_line.append(char)
|
||||
sys.stdout.write(char)
|
||||
elif 32 <= ord(char[0]) <= 126:
|
||||
current_line.append(char.decode('utf-8'))
|
||||
sys.stdout.write(char.decode('utf-8'))
|
||||
|
||||
# Flush output
|
||||
sys.stdout.flush()
|
||||
|
||||
finally:
|
||||
# Restore terminal settings
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
print() # New line for clean display
|
||||
except Exception as e:
|
||||
logger.error(f"Error in multiline input: {str(e)}")
|
||||
return 'q'
|
||||
|
||||
def initialize_system():
|
||||
"""Initialize system with proper error checking"""
|
||||
|
@ -296,7 +283,6 @@ def main():
|
|||
if 'research_manager' in locals() and research_manager:
|
||||
if hasattr(research_manager, 'ui'):
|
||||
research_manager.ui.cleanup()
|
||||
curses.endwin()
|
||||
except:
|
||||
pass
|
||||
os._exit(0)
|
||||
|
|
Loading…
Reference in a new issue