sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 790a9be55df3b57c21f6a76a8e4346fbff6d3d69
родитељ 8b6662d7a94f3114542dc1ca40824aa0cb2da23f
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Thu, 11 Jul 2024 10:27:57 +0200

Add F2 -> toggle line numbers at runtime

Diffstat:
MTODO | 6------
MTODO.done | 6++++++
Mconfig.def.h | 1+
Mdraw.c | 9+++++----
Mdraw.h | 1+
Msled.1.in | 1+
Msled.c | 7+++++++
Msled.h | 1+
измењених датотека: 8, додавања: 22(+), брисања: 10(-)

diff --git a/TODO b/TODO @@ -3,12 +3,6 @@ TODO [ ] Investigate >2-byte UTF editing (Emoji...) -[ ] Add shortcut key which toggles showing line numbers at runtime - (default state still configured in config.h) - -[x] (vis-like:) Dynamically compute max line number at runtime (number - of digits in the number of the last line drawn on screen) - [~] Code optimization (struct coord...) diff --git a/TODO.done b/TODO.done @@ -1,6 +1,12 @@ Done or canceled todos ====================== +[x] Add shortcut key which toggles showing line numbers at runtime + (default state still configured in config.h) + +[x] (vis-like:) Dynamically compute max line number at runtime (number + of digits in the number of the last line drawn on screen) + </> Make allocation errors prompt to save the file before exiting? - Would this make sense? diff --git a/config.def.h b/config.def.h @@ -126,6 +126,7 @@ static const struct Key global_keys[] = { { .ev = { .key = TB_KEY_DELETE }, .callback = erase_forward }, { .ev = { .key = TB_KEY_F1 }, .callback = show_help }, + { .ev = { .key = TB_KEY_F2 }, .callback = toggle_line_numbers }, { .ev = { .key = TB_KEY_F3 }, .callback = next_match }, { .ev = { .key = TB_KEY_F3, .mod = TB_MOD_SHIFT }, .callback = prev_match }, diff --git a/draw.c b/draw.c @@ -370,7 +370,7 @@ draw_screen(const struct DrawState* state) return 1; maxx = state->maxx; - if (line_numbers) + if (state->line_numbers) maxx -= state->line_numbers_width; if (state->rows_count == 0) @@ -405,10 +405,10 @@ draw_screen(const struct DrawState* state) sei = sec; } } - if (line_numbers) + if (state->line_numbers) draw_line_number(state, i, cy); if (current->text) - u32_draw_string(line_numbers + u32_draw_string(state->line_numbers ? state->line_numbers_width + 2 : 0, cy, TEXT_FG, TEXT_BG, current->text, maxx, maxx, @@ -419,7 +419,7 @@ draw_screen(const struct DrawState* state) cy++; } - tb_set_cursor(line_numbers + tb_set_cursor(state->line_numbers ? state->line_numbers_width + 2 + state->display_column - state->first_shown.col : state->display_column - state->first_shown.col, @@ -691,6 +691,7 @@ init_drawstate(struct DrawState* state, char* error, char* action, state->saved_column = -1; state->help_width = calculate_help_width(state); state->input_dialog_width = calculate_input_dialog_width(state); + state->line_numbers = line_numbers; if (!skip_paste_and_mode_init) { state->paste = NULL; diff --git a/draw.h b/draw.h @@ -77,6 +77,7 @@ struct DrawState { int saved_column; /* display coordinate */ int help_width; /* display parameter */ int input_dialog_width; /* display parameter */ + int line_numbers; /* runtime value */ int line_numbers_width; struct BufferLine* paste; ssize_t paste_count; diff --git a/sled.1.in b/sled.1.in @@ -73,6 +73,7 @@ These are active in all modes, and are as follows: .It Sy Key Ta Sy Action .It \f[CR]Esc\fR Ta Close dialog, clear error, cancel selection .It \f[CR]F1\fR Ta Show help dialog +.It \f[CR]F2\fR Ta Toggle line numbers .It \f[CR]F3\fR Ta Go to next found match .It \f[CR]S-F3\fR Ta Go to previous found match .It \f[CR]F4\fR Ta Show search, then replace dialog diff --git a/sled.c b/sled.c @@ -2441,6 +2441,13 @@ suspend_program(struct DrawState* state) } static int +toggle_line_numbers(struct DrawState* state) +{ + state->line_numbers = !state->line_numbers; + return 0; +} + +static int toggle_overwrite(struct DrawState* state) { TOGGLE(state->mode, M_OVERWRITE); diff --git a/sled.h b/sled.h @@ -86,6 +86,7 @@ static void simple_insert_line(struct DrawState* state); static void simple_join_lines(struct DrawState* state); static void simple_yank(struct DrawState* state); static int suspend_program(struct DrawState* state); +static int toggle_line_numbers(struct DrawState* state); static int toggle_overwrite(struct DrawState* state); static int toggle_selection(struct DrawState* state); static int wrap_para(struct DrawState* state);