poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување c8dcb1c7507073367e9407cbd92286e4144f1344
родитељ 1494b2807f67a26127739ba46154a9e1160ac6d6
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Thu, 24 Feb 2022 21:56:32 +0100

Convert main logic to termbox2; clang-format

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mdraw.c | 5++---
Mpo.c | 2+-
Mpoe.c | 36+++++++++++++++---------------------
измењених датотека: 3, додавања: 18(+), брисања: 25(-)

diff --git a/draw.c b/draw.c @@ -134,7 +134,7 @@ init_drawstate(struct DrawState* state, char* error, char* filename, void free_drawstate(struct DrawState* state) { - size_t i = 0; + size_t i = 0; for (i = 0; i < state->input_rows_count; i++) free_bufferline(state->input_buffer + i); @@ -580,8 +580,7 @@ draw_help(const struct DrawState* state) draw_box(startx, endx, starty, endy, DLG_FG, DLG_BG); if (!draw_string(startx, starty, TITLE_FG, TITLE_BG, help_title, - strlen(help_title) + 2, w, 1, 1, CENTER, 0, 0, NULL, 0, - 0)) + strlen(help_title) + 2, w, 1, 1, CENTER, 0, 0, NULL, 0, 0)) return NULL; while (row < LEN(help)) { diff --git a/po.c b/po.c @@ -503,7 +503,7 @@ save_file(const struct PoEntry* entries, const size_t real_msgid_count, const struct PoEntry* current = entries; FILE* output = NULL; #ifdef CREATE_BACKUPS - char* backup_filename = NULL; + char* backup_filename = NULL; #endif struct stat st; diff --git a/poe.c b/poe.c @@ -12,7 +12,6 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <time.h> #include <unistd.h> #define TB_OPT_V1_COMPAT @@ -1543,28 +1542,28 @@ erase_prev_word(struct DrawState* state) return 0; } -int +int insert_space(struct DrawState* state) { insert_char(state, (uint32_t)L' '); return 0; } -int +int insert_tab(struct DrawState* state) { insert_char(state, (uint32_t)L'\t'); return 0; } -int +int insert_search_space(struct DrawState* state) { insert_search_char(state, (uint32_t)L' '); return 0; } -int +int insert_search_tab(struct DrawState* state) { insert_search_char(state, (uint32_t)L'\t'); @@ -1738,7 +1737,7 @@ toggle_fuzzy(struct DrawState* state) return 0; } -int +int toggle_info_focused(struct DrawState* state) { state->edit_info_focused = !state->edit_info_focused; @@ -2020,10 +2019,8 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) { current = top_level_keys + key; if (((current->ev.key == ev->key) && !ev->ch) - || (current->ev.ch - && (current->ev.ch == ev->ch))) - if (current->callback - && !current->callback(state)) + || (current->ev.ch && (current->ev.ch == ev->ch))) + if (current->callback && !current->callback(state)) return; } @@ -2089,11 +2086,11 @@ int main(int argc, char** argv) { struct tb_event ev; - struct timespec sleep_spec; char error[MAXBUFLINE]; char prompt[MAXBUFLINE]; struct DrawState state; char filename[MAXPATH]; + int recalculate_size = 1; struct stat st; *error = 0; @@ -2168,27 +2165,24 @@ main(int argc, char** argv) { tb_clear(); - int maxx = tb_width(); - if (maxx != state.maxx) + if (recalculate_size) { - state.maxx = maxx; + state.maxx = tb_width(); state.help_width = calculate_help_width(&state); state.edit_width = calculate_edit_width(&state); state.search_width = calculate_search_width(&state); + recalculate_size = 0; } state.maxy = tb_height(); if (!draw(&state)) strcpy(state.error, errors[ERR_CANT_ALLOC]); tb_present(); - if (tb_peek_event(&ev, 20) > 0 && ev.type == TB_EVENT_KEY) + result = tb_poll_event(&ev); + if (result == TB_OK && ev.type == TB_EVENT_RESIZE) + recalculate_size = 1; + else if (result == TB_OK && ev.type == TB_EVENT_KEY) handle_key_event(&ev, &state); - if (state.running) - { - sleep_spec.tv_nsec = 500; - sleep_spec.tv_sec = 0; - nanosleep(&sleep_spec, NULL); - } } tb_shutdown(); if (state.error && *state.error)