ref: 7ee165723ab3ce8294d6ce91f7f59dd4858c8ecb
parent: 7a27b6ed75a5a9916c458f009e0c23f04a7313c5
author: cancel <cancel@cancel.fm>
date: Tue Dec 11 14:55:52 EST 2018
Add quote to toggle selection resize mode
--- a/tui_main.c
+++ b/tui_main.c
@@ -46,6 +46,7 @@
Tui_input_mode_normal = 0,
Tui_input_mode_append = 1,
Tui_input_mode_piano = 2,
+ Tui_input_mode_selresize = 3,
} Tui_input_mode;
typedef enum {
@@ -437,6 +438,10 @@
wattrset(win, A_reverse);
wprintw(win, "trigger");
break;
+ case Tui_input_mode_selresize:
+ wattrset(win, A_bold);
+ wprintw(win, "select");
+ break;
}
wattrset(win, A_normal);
wprintw(win, "\t%s", filename);
@@ -1022,6 +1027,29 @@
a->is_draw_dirty = true;
}
+Usz guarded_selection_axis_resize(Usz x, int delta) {
+ if (delta < 0) {
+ if (delta > INT_MIN && (Usz)(-delta) < x) {
+ x -= (Usz)(-delta);
+ }
+ } else if (x < SIZE_MAX - (Usz)delta) {
+ x += (Usz)delta;
+ }
+ return x;
+}
+
+void app_modify_selection_size(App_state* a, int delta_y, int delta_x) {
+ Usz cur_h = a->tui_cursor.h;
+ Usz cur_w = a->tui_cursor.w;
+ Usz new_h = guarded_selection_axis_resize(cur_h, delta_y);
+ Usz new_w = guarded_selection_axis_resize(cur_w, delta_x);
+ if (cur_h != new_h || cur_w != new_w) {
+ a->tui_cursor.h = new_h;
+ a->tui_cursor.w = new_w;
+ a->is_draw_dirty = true;
+ }
+}
+
typedef enum {
App_dir_up,
App_dir_down,
@@ -1030,7 +1058,11 @@
} App_dir;
void app_dir_input(App_state* a, App_dir dir) {
- switch (dir) {
+ switch (a->input_mode) {
+ case Tui_input_mode_normal:
+ case Tui_input_mode_append:
+ case Tui_input_mode_piano:
+ switch (dir) {
case App_dir_up:
app_move_cursor_relative(a, -1, 0);
break;
@@ -1043,6 +1075,23 @@
case App_dir_right:
app_move_cursor_relative(a, 0, 1);
break;
+ }
+ break;
+ case Tui_input_mode_selresize:
+ switch (dir) {
+ case App_dir_up:
+ app_modify_selection_size(a, -1, 0);
+ break;
+ case App_dir_down:
+ app_modify_selection_size(a, 1, 0);
+ break;
+ case App_dir_left:
+ app_modify_selection_size(a, 0, -1);
+ break;
+ case App_dir_right:
+ app_modify_selection_size(a, 0, 1);
+ break;
+ }
}
}
@@ -1174,6 +1223,7 @@
switch (a->input_mode) {
case Tui_input_mode_normal:
case Tui_input_mode_append:
+ case Tui_input_mode_selresize:
app_write_character(a, c);
break;
case Tui_input_mode_piano:
@@ -1182,33 +1232,11 @@
}
}
-Usz guarded_selection_axis_resize(Usz x, int delta) {
- if (delta < 0) {
- if (delta > INT_MIN && (Usz)(-delta) < x) {
- x -= (Usz)(-delta);
- }
- } else if (x < SIZE_MAX - (Usz)delta) {
- x += (Usz)delta;
- }
- return x;
-}
-
-void app_modify_selection_size(App_state* a, int delta_y, int delta_x) {
- Usz cur_h = a->tui_cursor.h;
- Usz cur_w = a->tui_cursor.w;
- Usz new_h = guarded_selection_axis_resize(cur_h, delta_y);
- Usz new_w = guarded_selection_axis_resize(cur_w, delta_x);
- if (cur_h != new_h || cur_w != new_w) {
- a->tui_cursor.h = new_h;
- a->tui_cursor.w = new_w;
- a->is_draw_dirty = true;
- }
-}
-
typedef enum {
App_input_cmd_undo,
App_input_cmd_toggle_append_mode,
App_input_cmd_toggle_piano_mode,
+ App_input_cmd_toggle_selresize_mode,
App_input_cmd_step_forward,
App_input_cmd_toggle_show_event_list,
App_input_cmd_toggle_play_pause,
@@ -1242,6 +1270,14 @@
}
a->is_draw_dirty = true;
break;
+ case App_input_cmd_toggle_selresize_mode:
+ if (a->input_mode == Tui_input_mode_selresize) {
+ a->input_mode = Tui_input_mode_normal;
+ } else {
+ a->input_mode = Tui_input_mode_selresize;
+ }
+ a->is_draw_dirty = true;
+ break;
case App_input_cmd_step_forward:
undo_history_push(&a->undo_hist, &a->field, a->tick_num);
orca_run(a->field.buffer, a->markmap_r.buffer, a->field.height,
@@ -1661,6 +1697,9 @@
break;
case AND_CTRL('v'):
app_input_cmd(&app_state, App_input_cmd_paste);
+ break;
+ case '\'':
+ app_input_cmd(&app_state, App_input_cmd_toggle_selresize_mode);
break;
case ' ':
app_input_cmd(&app_state, App_input_cmd_toggle_play_pause);