~nickwinston123/armagetronad/arma_chatbot_config

« back to all changes in this revision

Viewing changes to arma_terminal/arma_terminal.py

  • Committer: hackermans
  • Date: 2025-05-29 20:16:47 UTC
  • Revision ID: nickwinston123@gmail.com-20250529201647-ybinllbs3ntf7xld
- arma_terminal
 - added clear_key setting that will clear the log buffer
 - added ability to click line and copy to clipboard or press f2 to copy entire buffer
- ollama_chat
 - smart_processor param to enable AI if there are smart_processor_active_players active players or less
 - Ractor/fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import configparser
7
7
import logging
8
8
import sys
 
9
import pyperclip
 
10
 
9
11
 
10
12
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
11
13
 
18
20
    sys.exit(1)
19
21
 
20
22
try:
21
 
    CONSOLE_LOG       = config.get('Paths',    'console_log')
22
 
    COMMANDS_FILE     = config.get('Paths',    'commands_file')
23
 
    COMMAND_PREFIX    = config.get('Settings', 'command_prefix')
24
 
    MAX_LOG_LINES     = config.getint('Settings', 'max_log_lines', fallback=1000)
 
23
    CONSOLE_LOG     = config.get('Paths',    'console_log')
 
24
    COMMANDS_FILE   = config.get('Paths',    'commands_file')
 
25
    COMMAND_PREFIX  = config.get('Settings', 'command_prefix')
 
26
    MAX_LOG_LINES   = config.getint('Settings', 'max_log_lines', fallback=1000)
 
27
    CLEAR_KEY       = config.get('Settings', 'clear_key', fallback='clear')
25
28
except Exception as e:
26
29
    logging.error(f"Error retrieving config values: {e}")
27
30
    sys.exit(1)
149
152
            scroll_offset = 0
150
153
            continue
151
154
 
 
155
        if ch == curses.KEY_F2:
 
156
            with lock:
 
157
                pyperclip.copy('\n'.join(lines))
 
158
                lines.append("→ COPIED entire log buffer to clipboard.")
 
159
            continue
 
160
 
152
161
        if ch == curses.KEY_MOUSE:
153
162
            try:
154
163
                _, mx, my, _, bstate = curses.getmouse()
155
164
                if bstate & curses.BUTTON1_PRESSED:
156
 
                    if 1 <= my < log_h - 1 and mx == width - 2:
 
165
                    if 1 <= my < log_h - 1 and mx < width - 3:
 
166
                        visible_y = my - 1
 
167
                        line_index = start_idx + visible_y
 
168
                        if line_index < len(wrapped):
 
169
                            text = wrapped[line_index]
 
170
                            pyperclip.copy(text)
 
171
                            with lock:
 
172
                                lines.append(f"→ COPIED line to clipboard: {text}")
 
173
                    elif 1 <= my < log_h - 1 and mx == width - 2:
157
174
                        dragging = True
158
175
                        drag_start_y = my
159
176
                        drag_start_offset = scroll_offset
190
207
            if cmd.lower() in ("exit", "quit"):
191
208
                return
192
209
            full_cmd = f"{COMMAND_PREFIX} {cmd}" if COMMAND_PREFIX else cmd
193
 
            try:
194
 
                with open(COMMANDS_FILE, 'a', encoding='utf-8') as f:
195
 
                    f.write(full_cmd + "\n")
196
 
                    f.flush()
197
 
                    os.fsync(f.fileno())
198
 
            except Exception as e:
 
210
        
 
211
            if cmd == CLEAR_KEY:
199
212
                with lock:
200
 
                    lines.append(f"→ ERROR writing command: {e}")
 
213
                    lines.clear()
 
214
                    lines.append("→ CLEARED log buffer.")
201
215
            else:
202
 
                with lock:
203
 
                    lines.append(f"→ SENT: {full_cmd}")
 
216
                try:
 
217
                    with open(COMMANDS_FILE, 'a', encoding='utf-8') as f:
 
218
                        f.write(full_cmd + "\n")
 
219
                        f.flush()
 
220
                        os.fsync(f.fileno())
 
221
                except Exception as e:
 
222
                    with lock:
 
223
                        lines.append(f"→ ERROR writing command: {e}")
 
224
                else:
 
225
                    with lock:
 
226
                        lines.append(f"→ SENT: {full_cmd}")
 
227
 
204
228
        elif ch in (curses.KEY_EXIT, '\x1b'):
205
229
            return
206
230