poe

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

чување fe62432072527084c9587bd4eb9d70686fcb55e8
родитељ e5eccfd2bdd28eddc4f8895e530fe7c284ebcfa3
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Fri, 17 May 2024 00:56:09 +0200

Fix drawing flags in list vs in edit box

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

Diffstat:
Mdraw.c | 39++++++++++++++++++++-------------------
Mpo.c | 8+++++---
Mpo.h | 3++-
измењених датотека: 3, додавања: 27(+), брисања: 23(-)

diff --git a/draw.c b/draw.c @@ -618,7 +618,7 @@ draw_editbox(const struct DrawState* state) struct PoEntry* entry = state->entries + state->msgid_number - 1; size_t dlen = 0; - format_flags(flags_buf, MAXFLAGSBUF, entry); + format_flags(flags_buf, MAXFLAGSBUF, entry, 1); startx = w > maxx ? 0 : (maxx - w) / 2; endx = w > maxx ? maxx - 1 : startx + w; @@ -798,16 +798,20 @@ draw_status(const struct DrawState* state) const struct DrawState* draw_list_visible(const struct DrawState* state) { + int flags_len; + const struct PoEntry* current = NULL; + int max_screen_entries = 0; + int cy = 0; + size_t i = 0; + if (!state) return NULL; if (state->msgid_count == 0) return state; - const struct PoEntry* current = NULL; - int max_screen_entries = state->maxy - 1; - int cy = 0; - size_t i = state->first_shown_msgid; + max_screen_entries = state->maxy - 1; + i = state->first_shown_msgid; while (i <= state->real_msgid_count && cy < max_screen_entries) { @@ -827,32 +831,29 @@ draw_list_visible(const struct DrawState* state) draw_rect(0, state->maxx - 1, cy, cy + 1, LIST_SEL_FG, LIST_SEL_BG); - format_flags(flags_buf, MAXFLAGSBUF, current); + format_flags(flags_buf, MAXFLAGSBUF, current, 0); + flags_len = strlen(flags_buf) + 1; if (!draw_string(0, cy, sel ? LIST_FLAGS_SEL_FG : LIST_FLAGS_FG, sel ? LIST_FLAGS_SEL_BG : LIST_FLAGS_BG, flags_buf, - MAXFLAGSBUF - 1 + 2, MAXFLAGSBUF - 1 + 2, 2, 0, - LEFT, 0, 1, NULL, 0, 0)) + flags_len, flags_len, 2, 0, LEFT, 0, 1, NULL, 0, 0)) return NULL; if (current->msgid) - u32_draw_string(MAXFLAGSBUF - 1 + 2, cy, + u32_draw_string(flags_len, cy, sel ? LIST_MSGID_SEL_FG : LIST_MSGID_FG, sel ? LIST_MSGID_SEL_BG : LIST_MSGID_BG, - current->msgid, - state->maxx / 2 - MAXFLAGSBUF + 1 - 2, - state->maxx / 2 - MAXFLAGSBUF + 1 - 2, 2, 0, - LEFT, 0, 1, state->search, SEARCH_HL_FG, - SEARCH_HL_BG); + current->msgid, state->maxx / 2 - flags_len, + state->maxx / 2 - flags_len, 2, 0, LEFT, 0, 1, + state->search, SEARCH_HL_FG, SEARCH_HL_BG); else if (current == state->entries) /* special */ - draw_string(MAXFLAGSBUF - 1 + 2, cy, + draw_string(flags_len, cy, sel ? LIST_MSGID_SPECIAL_SEL_FG : LIST_MSGID_SPECIAL_FG, sel ? LIST_MSGID_SPECIAL_SEL_BG : LIST_MSGID_SPECIAL_BG, - first_entry_msgid, - state->maxx / 2 - MAXFLAGSBUF + 1 - 2, - state->maxx / 2 - MAXFLAGSBUF + 1 - 2, 2, 0, - LEFT, 0, 1, NULL, 0, 0); + first_entry_msgid, state->maxx / 2 - flags_len, + state->maxx / 2 - flags_len, 2, 0, LEFT, 0, 1, + NULL, 0, 0); /* don't use msgstr_index as then the entire list will shift * when changing currently displayed plural form msgstr in an diff --git a/po.c b/po.c @@ -23,13 +23,15 @@ extern const char* flag_strings[]; int print_error(const int code, const char* msg, ...); char* -format_flags(char* buffer, const size_t max, const struct PoEntry* entry) +format_flags(char* buffer, const size_t max, const struct PoEntry* entry, + const int draw_box) { - snprintf(buffer, max, "[ %c%c%c%c ]", + snprintf(buffer, max, "%s%c%c%c%c%s", draw_box ? "[ " : "", entry->flags & FL_C_FORMAT ? 'C' : ' ', entry->flags & FL_FUZZY ? 'F' : ' ', entry->msgstr_count > 1 ? 'P' : ' ', - entry->flags & FL_NO_C_FORMAT ? 'N' : ' '); + entry->flags & FL_NO_C_FORMAT ? 'N' : ' ', + draw_box ? " ]" : ""); return buffer; } diff --git a/po.h b/po.h @@ -97,7 +97,8 @@ struct PoEntry { size_t ref_comment_lines; }; -char* format_flags(char* buffer, const size_t max, const struct PoEntry* entry); +char* format_flags(char* buffer, const size_t max, const struct PoEntry* entry, + const int draw_box); void init_po_entry(struct PoEntry* entry); void free_po_entry(struct PoEntry* entry); struct PoEntry* set_flags(struct PoEntry* entry, const Flags flags);