feat: add mouse support to TUI
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
61
tui.c
61
tui.c
@@ -385,6 +385,50 @@ static bool handle_command_mode(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle mouse events
|
||||||
|
static void handle_mouse_event(MEVENT *event) {
|
||||||
|
// Convert mouse position to grid coordinates
|
||||||
|
int grid_row = (event->y - 1) / CELL_HEIGHT; // -1 for title row
|
||||||
|
int grid_col = (event->x - 1) / CELL_WIDTH; // -1 for left margin
|
||||||
|
|
||||||
|
// Bounds check
|
||||||
|
if (grid_row < 0 || grid_row >= GRID_ROWS || grid_col < 0 || grid_col >= GRID_COLS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->bstate & BUTTON1_CLICKED) {
|
||||||
|
// Left click: select and trigger clip
|
||||||
|
selected_row = grid_row;
|
||||||
|
selected_col = grid_col;
|
||||||
|
|
||||||
|
int clip_idx = grid_to_clip_index(selected_row, selected_col);
|
||||||
|
engine_trigger_clip(g_engine, clip_idx);
|
||||||
|
engine_process_commands(g_engine);
|
||||||
|
} else if (event->bstate & BUTTON3_CLICKED) {
|
||||||
|
// Right click: select and reset clip
|
||||||
|
selected_row = grid_row;
|
||||||
|
selected_col = grid_col;
|
||||||
|
|
||||||
|
int clip_idx = grid_to_clip_index(selected_row, selected_col);
|
||||||
|
engine_reset_clip(g_engine, clip_idx);
|
||||||
|
engine_process_commands(g_engine);
|
||||||
|
} else if (event->bstate & BUTTON2_CLICKED) {
|
||||||
|
// Middle click: select and trigger scene
|
||||||
|
selected_row = grid_row;
|
||||||
|
selected_col = grid_col;
|
||||||
|
|
||||||
|
engine_trigger_scene(g_engine, selected_row);
|
||||||
|
engine_process_commands(g_engine);
|
||||||
|
} else if (event->bstate & BUTTON1_DOUBLE_CLICKED) {
|
||||||
|
// Double left click: select and trigger scene
|
||||||
|
selected_row = grid_row;
|
||||||
|
selected_col = grid_col;
|
||||||
|
|
||||||
|
engine_trigger_scene(g_engine, selected_row);
|
||||||
|
engine_process_commands(g_engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_sigint(int sig) {
|
static void handle_sigint(int sig) {
|
||||||
(void)sig;
|
(void)sig;
|
||||||
tui_cleanup();
|
tui_cleanup();
|
||||||
@@ -401,6 +445,10 @@ void tui_init(Engine *engine) {
|
|||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
curs_set(0); // Hide cursor
|
curs_set(0); // Hide cursor
|
||||||
|
|
||||||
|
// Enable mouse events
|
||||||
|
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
|
||||||
|
mouseinterval(0); // No click delay
|
||||||
|
|
||||||
// Initialize colors
|
// Initialize colors
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
start_color();
|
start_color();
|
||||||
@@ -433,6 +481,16 @@ void tui_run(Engine *engine) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle mouse events
|
||||||
|
if (ch == KEY_MOUSE) {
|
||||||
|
MEVENT event;
|
||||||
|
if (getmouse(&event) == OK) {
|
||||||
|
handle_mouse_event(&event);
|
||||||
|
draw_grid();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle mode-specific input
|
// Handle mode-specific input
|
||||||
if (current_mode == MODE_MOVE) {
|
if (current_mode == MODE_MOVE) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@@ -707,6 +765,9 @@ void tui_cleanup(void) {
|
|||||||
yank_buffer.count = 0;
|
yank_buffer.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable mouse
|
||||||
|
mousemask(0, NULL);
|
||||||
|
|
||||||
// Restore terminal settings
|
// Restore terminal settings
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
|||||||
Reference in New Issue
Block a user