poe

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

чување 87ec77b81ffb6c0c78a6225e7f5392a1386dc8c5
родитељ ad30031da824dfa6c88d00a403734d13e5a58036
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sat, 12 Jun 2021 16:46:09 +0200

Moved colors to config.def.h; added C-Q key; changed empty file handling; edit box displays current msgid/msgstr

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

Diffstat:
Mconfig.def.h | 27+++++++++++++++++++++++++++
Mconfig.h | 27+++++++++++++++++++++++++++
Mdraw.c | 124++++++++++++++++++++++++++++---------------------------------------------------
Mdraw.h | 20--------------------
Mpo.h | 2++
Mpoe.c | 30+++++++++++++++++++-----------
Mutil.h | 6+++---
измењених датотека: 7, додавања: 122(+), брисања: 114(-)

diff --git a/config.def.h b/config.def.h @@ -1,4 +1,31 @@ /* See the file LICENSE for copyright and license details. */ +#define DLG_FG TB_BLACK +#define DLG_BG TB_WHITE +#define EDIT_MSGID_FG TB_BLACK | TB_BOLD +#define EDIT_MSGID_BG TB_WHITE +#define EDIT_MSGSTR_FG TB_YELLOW | TB_BOLD +#define EDIT_MSGSTR_BG TB_BLACK +#define ERROR_FG TB_WHITE | TB_BOLD +#define ERROR_BG TB_RED +#define FLAG_FG TB_YELLOW | TB_BOLD +#define FLAG_BG TB_DEFAULT +#define LIST_MSGID_FG TB_WHITE +#define LIST_MSGID_BG TB_DEFAULT +#define LIST_MSGID_SEL_FG TB_WHITE +#define LIST_MSGID_SEL_BG TB_BLUE +#define LIST_MSGSTR_FG TB_GREEN +#define LIST_MSGSTR_BG TB_DEFAULT +#define LIST_MSGSTR_SEL_FG TB_WHITE | TB_BOLD +#define LIST_MSGSTR_SEL_BG TB_BLUE +#define MSGID_FG TB_GREEN +#define MSGID_BG TB_DEFAULT +#define MSGSTR_FG TB_WHITE +#define MSGSTR_BG TB_DEFAULT +#define SHADOW_FG TB_BLACK +#define SHADOW_BG TB_BLACK | TB_BOLD +#define TITLE_FG TB_BLACK +#define TITLE_BG TB_WHITE + void format_filename(char* result, size_t result_size, const char* format, const struct DrawState* state); void format_msgs(char* result, size_t result_size, const char* format, diff --git a/config.h b/config.h @@ -1,4 +1,31 @@ /* See the file LICENSE for copyright and license details. */ +#define DLG_FG TB_BLACK +#define DLG_BG TB_WHITE +#define EDIT_MSGID_FG TB_BLACK | TB_BOLD +#define EDIT_MSGID_BG TB_WHITE +#define EDIT_MSGSTR_FG TB_YELLOW | TB_BOLD +#define EDIT_MSGSTR_BG TB_BLACK +#define ERROR_FG TB_WHITE | TB_BOLD +#define ERROR_BG TB_RED +#define FLAG_FG TB_YELLOW | TB_BOLD +#define FLAG_BG TB_DEFAULT +#define LIST_MSGID_FG TB_WHITE +#define LIST_MSGID_BG TB_DEFAULT +#define LIST_MSGID_SEL_FG TB_WHITE +#define LIST_MSGID_SEL_BG TB_BLUE +#define LIST_MSGSTR_FG TB_GREEN +#define LIST_MSGSTR_BG TB_DEFAULT +#define LIST_MSGSTR_SEL_FG TB_WHITE | TB_BOLD +#define LIST_MSGSTR_SEL_BG TB_BLUE +#define MSGID_FG TB_GREEN +#define MSGID_BG TB_DEFAULT +#define MSGSTR_FG TB_WHITE +#define MSGSTR_BG TB_DEFAULT +#define SHADOW_FG TB_BLACK +#define SHADOW_BG TB_BLACK | TB_BOLD +#define TITLE_FG TB_BLACK +#define TITLE_BG TB_WHITE + void format_filename(char* result, size_t result_size, const char* format, const struct DrawState* state); void format_msgs(char* result, size_t result_size, const char* format, diff --git a/draw.c b/draw.c @@ -11,29 +11,28 @@ static const char* help_title = " poe - .po File Editor "; static const char* help[] = { - "ESC - Close dialog, clear error", - "ENTER - Edit entry", - "H | F1 - Show this screen", - "g | Home - First entry", - "k | \u2191 - Previous entry", - "j | \u2193 - Next entry", - "G | End - Last entry", - "q - Quit" + "ESC - Close dialog, clear error", + "ENTER - Edit entry", + "H or F1 - Show this screen", + "g or Home - First entry", + "k or \u2191 - Previous entry", + "j or \u2193 - Next entry", + "G or End - Last entry", + "q or C-Q - Quit" }; static const char* editbox_title = " Edit translation "; const char* errors[] = { - [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)", - [ERR_NO_PREV] = "No previous entry", - [ERR_NO_NEXT] = "No next entry", - [ERR_EXIT_KEY] = "Press q to quit", - [ERR_DLG_OPEN] = "Press Esc to close dialog or q to quit" + [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)", + [ERR_EXIT_KEY] = "Press q or C-Q to quit", + [ERR_DLG_OPEN] = "Press Esc to close dialog or q/C-Q to quit", + [ERR_DLG_OPEN_QUIT] = "Press Esc to close dialog", + [ERR_EMPTY_FILE] = "No msgids to edit" }; const char* flag_strings[] = { [FL_C_FORMAT] = "c-format", [FL_FUZZY] = "fuzzy" }; -const char* empty_msgid = "*** No msgid ***"; -const char* empty_msgstr = "*** No msgstr ***"; +const char* empty_file_text = "*** Empty file ***"; const char* program_name = "poe"; void @@ -146,12 +145,12 @@ draw_help(const struct DrawState* state) starty = h > maxy-1 ? 0 : (maxy-h)/2; endy = h > maxy-1 ? maxy-2 : maxy-starty; - draw_box(startx, endx, starty, endy, TB_BLACK, TB_WHITE); - draw_string(startx+1, starty, TB_BLACK | TB_BOLD | TB_REVERSE, TB_WHITE, + draw_box(startx, endx, starty, endy, DLG_FG, DLG_BG); + draw_string(startx+1, starty, TITLE_FG, TITLE_BG, help_title, w-2, strlen(help_title)+2, 1, CENTER); while (row < LEN(help)) { - draw_string(startx+2, starty+3+row, TB_BLACK, TB_WHITE, + draw_string(startx+2, starty+3+row, DLG_FG, DLG_BG, help[row], w-4, w-4, 2, LEFT); row++; } @@ -169,6 +168,13 @@ draw_editbox(const struct DrawState* state) int h = 20; int maxx = state->maxx; int maxy = state->maxy; + char buf[MSGSTR_MAX]; + + if (state->entries[state->msgid_number-1].msgstr) + strncpy(buf, state->entries[state->msgid_number-1].msgstr, + MSGSTR_MAX); + else + buf[0] = 0; startx = w > maxx ? 0 : (maxx - w) / 2; endx = w > maxx ? maxx-1 : maxx-startx; @@ -176,19 +182,21 @@ draw_editbox(const struct DrawState* state) starty = h > maxy-1 ? 0 : (maxy-h)/2; endy = h > maxy-1 ? maxy-2 : maxy-starty; - draw_box(startx, endx, starty, endy, TB_BLACK, TB_WHITE); - draw_string(startx+1, starty, TB_BLACK | TB_BOLD | TB_REVERSE, TB_WHITE, - editbox_title, w-2, strlen(editbox_title)+2, 1, CENTER); - - draw_rect(startx+2, endx-2, starty+1, endy-11, TB_BLACK | TB_BOLD, - TB_WHITE); - draw_string(startx+2, starty+1, TB_BLACK | TB_BOLD, TB_WHITE, - "Test msgid", w-2, strlen("Test msgid")+2, 1, LEFT); - - draw_rect(startx+2, endx-2, endy-11, endy-2, TB_YELLOW | TB_BOLD, - TB_BLACK); - draw_string(startx+2, endy-11, TB_YELLOW | TB_BOLD, TB_BLACK, - "Test msgstr", w-2, strlen("Test msstr")+2, 1, LEFT); + draw_box(startx, endx, starty, endy, DLG_FG, DLG_BG); + draw_string(startx+1, starty, TITLE_FG, TITLE_BG, editbox_title, w-2, + strlen(editbox_title)+2, 1, CENTER); + + draw_rect(startx+2, endx-2, starty+1, endy-11, EDIT_MSGID_FG, + EDIT_MSGID_BG); + draw_string(startx+2, starty+1, EDIT_MSGID_FG, EDIT_MSGID_BG, + state->entries[state->msgid_number-1].msgid, w-2, + strlen(state->entries[state->msgid_number-1].msgid)+2, + 1, LEFT); + + draw_rect(startx+2, endx-2, endy-11, endy-2, EDIT_MSGSTR_FG, + EDIT_MSGSTR_BG); + draw_string(startx+2, endy-11, EDIT_MSGSTR_FG, EDIT_MSGSTR_BG, + buf, w-2, strlen(buf)+2, 1, LEFT); } void @@ -236,10 +244,8 @@ draw_list_visible(const struct PoEntry* start, const struct DrawState* state) if (!start) { - draw_string(0, cy, LIST_MSGID_FG, LIST_MSGID_BG, empty_msgid, - state->maxx/2, state->maxx/2, 2, CENTER); - draw_string(state->maxx/2, cy, LIST_MSGSTR_FG, LIST_MSGSTR_BG, - empty_msgstr, state->maxx/2, state->maxx/2, + draw_string(0, cy, LIST_MSGID_FG, LIST_MSGID_BG, + empty_file_text, state->maxx, state->maxx, 2, CENTER); return; } @@ -254,8 +260,9 @@ draw_list_visible(const struct PoEntry* start, const struct DrawState* state) draw_string(state->maxx/2, cy, sel ? LIST_MSGSTR_SEL_FG : LIST_MSGSTR_FG, sel ? LIST_MSGSTR_SEL_BG : LIST_MSGSTR_BG, - current->msgstr, state->maxx/2, state->maxx/2, - 2, LEFT); + current->msgstr + ? current->msgstr : "", + state->maxx/2, state->maxx/2, 2, LEFT); current++; i++; cy++; @@ -263,49 +270,6 @@ draw_list_visible(const struct PoEntry* start, const struct DrawState* state) } void -draw_entry(const struct PoEntry* entry, const struct DrawState* state) -{ - if (!state) - return; - - uint16_t flags; - - if (entry) - { - draw_string(0, state->maxy/3, MSGID_FG, MSGID_BG, entry->msgid, - state->maxx, state->maxx, state->maxx/4, LEFT); - flags = entry->flags; - while (flags) - { - if (flags & FL_C_FORMAT) - { - flags &= ~FL_C_FORMAT; - draw_string(0, 1, FLAG_FG, FLAG_BG, - flag_strings[FL_C_FORMAT], - state->maxx, state->maxx, 1, LEFT); - } - else if (flags & FL_FUZZY) - { - flags &= ~FL_FUZZY; - draw_string(10, 1, FLAG_FG, FLAG_BG, - flag_strings[FL_FUZZY], state->maxx-10, - state->maxx-10, 1, LEFT); - } - } - draw_string(0, 2*state->maxy/3, MSGSTR_FG, MSGSTR_BG, - entry->msgstr, state->maxx, state->maxx, - state->maxx/4, LEFT); - } - else - { - draw_string(0, state->maxy/3, MSGID_FG, MSGID_BG, empty_msgid, - state->maxx, state->maxx, state->maxx/4, LEFT); - draw_string(0, 2*state->maxy/3, MSGSTR_FG, MSGSTR_BG, empty_msgstr, - state->maxx, state->maxx, state->maxx/4, LEFT); - } -} - -void draw(const struct DrawState* state) { if (!state) diff --git a/draw.h b/draw.h @@ -6,25 +6,6 @@ #define BORDER_VER ((uint32_t)L'\u2502') #define BORDER_HOR ((uint32_t)L'\u2500') -#define ERROR_FG TB_WHITE | TB_BOLD -#define ERROR_BG TB_RED -#define FLAG_FG TB_YELLOW | TB_BOLD -#define FLAG_BG TB_DEFAULT -#define LIST_MSGID_FG TB_WHITE -#define LIST_MSGID_BG TB_DEFAULT -#define LIST_MSGSTR_FG TB_GREEN -#define LIST_MSGSTR_BG TB_DEFAULT -#define LIST_MSGID_SEL_FG TB_WHITE -#define LIST_MSGID_SEL_BG TB_BLUE -#define LIST_MSGSTR_SEL_FG TB_GREEN -#define LIST_MSGSTR_SEL_BG TB_BLUE -#define MSGID_FG TB_GREEN -#define MSGID_BG TB_DEFAULT -#define MSGSTR_FG TB_WHITE -#define MSGSTR_BG TB_DEFAULT -#define SHADOW_FG TB_BLACK -#define SHADOW_BG TB_BLACK | TB_BOLD - typedef enum { LEFT, CENTER, @@ -67,6 +48,5 @@ void draw_editbox(const struct DrawState* state); void draw_status(const struct DrawState* state); void draw_list_visible(const struct PoEntry* start, const struct DrawState* state); -void draw_entry(const struct PoEntry* entry, const struct DrawState* state); void draw(const struct DrawState* state); diff --git a/po.h b/po.h @@ -1,5 +1,7 @@ /* See the file LICENSE for copyright and license details. */ +#define MSGSTR_MAX 4096 + typedef enum { FL_NONE = 0, FL_C_FORMAT = 1, diff --git a/poe.c b/poe.c @@ -72,8 +72,13 @@ handle_key_event(const struct tb_event* ev, struct DrawState* state) if (state->show_edit) state->show_edit = 0; } - else if (ev->ch == 'q') - state->running = 0; + else if (ev->ch == 'q' || ev->key == TB_KEY_CTRL_Q) + { + if (state->show_edit) + strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); + else + state->running = 0; + } else if (state->show_help) strcpy(state->error, errors[ERR_DLG_OPEN]); else if (ev->key == TB_KEY_F1 @@ -84,8 +89,13 @@ handle_key_event(const struct tb_event* ev, struct DrawState* state) } else if (ev->key == TB_KEY_ENTER) { - state->show_edit = 1; - state->error[0] = 0; + if (state->msgid_count == 0) + strcpy(state->error, errors[ERR_EMPTY_FILE]); + else + { + state->show_edit = 1; + state->error[0] = 0; + } } else if (ev->key == TB_KEY_HOME || ev->ch == 'g') @@ -96,9 +106,7 @@ handle_key_event(const struct tb_event* ev, struct DrawState* state) else if (ev->key == TB_KEY_ARROW_UP || ev->ch == 'k') { - if (state->msgid_number < 2) - strcpy(state->error, errors[ERR_NO_PREV]); - else + if (state->msgid_number > 1) { state->error[0] = 0; state->msgid_number--; @@ -107,9 +115,7 @@ handle_key_event(const struct tb_event* ev, struct DrawState* state) else if (ev->key == TB_KEY_ARROW_DOWN || ev->ch == 'j') { - if (state->msgid_number == state->msgid_count) - strcpy(state->error, errors[ERR_NO_NEXT]); - else + if (state->msgid_number < state->msgid_count) { state->error[0] = 0; state->msgid_number++; @@ -139,7 +145,9 @@ main(int argc, char** argv) { .flags = FL_C_FORMAT | FL_FUZZY, .msgid = "First msgid: %s", .msgstr = "Први msgid: %s" }, { .flags = FL_NONE, - .msgid = "Test msgid", .msgstr = "Пробни msgstr" }, + .msgid = "Test msgid", .msgstr = "Пробни msgstr" }, + { .flags = FL_NONE, + .msgid = "Empty msgstr", .msgstr = NULL }, { .flags = FL_FUZZY, .msgid = "Final text", .msgstr = "Последњи текст" }, }; diff --git a/util.h b/util.h @@ -2,10 +2,10 @@ enum { ERR_UNKNOWN_KEY, - ERR_NO_PREV, - ERR_NO_NEXT, ERR_EXIT_KEY, - ERR_DLG_OPEN + ERR_DLG_OPEN, + ERR_DLG_OPEN_QUIT, + ERR_EMPTY_FILE }; #define MAXBUF 255