feat(ui,db,cmd): reduce dublicate code in window subwin logic, unify SQLite helpers, NULL checks added
Some checks failed
CI Code / Check spelling (pull_request) Successful in 18s
CI Code / Linux (arch) (pull_request) Failing after 22s
CI Code / Check coding style (pull_request) Failing after 31s
CI Code / Linux (debian) (pull_request) Successful in 15m14s
CI Code / Linux (ubuntu) (pull_request) Successful in 15m36s

window.c: add _get_subwin_cols, _apply_split_resize, _check_subwin_width; refactor show/hide/resize/refresh/update
database.c: add _db_prepare_ctx, _db_teardown; safer init/queries with fallback timestamp
cmd_defs.c: guard fopen in docgen; inputwin.c: replace assert with runtime check
This commit is contained in:
2025-11-10 15:09:09 +03:00
parent 332cd243c6
commit 5f01f8f546
4 changed files with 83 additions and 52 deletions

View File

@@ -75,6 +75,21 @@ static void _win_print_internal(ProfWin* window, const char* show_char, int pad_
int flags, theme_item_t theme_item, const char* const from, const char* const message, DeliveryReceipt* receipt);
static void _win_print_wrapped(WINDOW* win, const char* const message, size_t indent, int pad_indent);
// Helper: clamp a subwindow width to a sane range [1, cols-1] if possible
static int
_check_subwin_width(int cols, int width)
{
if (cols > 1) {
if (width < 1)
width = 1;
if (width >= cols)
width = cols - 1;
} else {
width = 1;
}
return width;
}
int
win_roster_cols(void)
{
@@ -82,12 +97,7 @@ win_roster_cols(void)
int cols = getmaxx(stdscr);
int width = CEILING((((double)cols) / 100) * roster_win_percent);
// Clamp to a sane range to avoid zero/full-width pads
if (cols > 1) {
if (width < 1) width = 1;
if (width >= cols) width = cols - 1;
} else {
width = 1;
}
width = _check_subwin_width(cols, width);
return width;
}
@@ -98,12 +108,7 @@ win_occpuants_cols(void)
int cols = getmaxx(stdscr);
int width = CEILING((((double)cols) / 100) * occupants_win_percent);
// Clamp to a sane range to avoid zero/full-width pads
if (cols > 1) {
if (width < 1) width = 1;
if (width >= cols) width = cols - 1;
} else {
width = 1;
}
width = _check_subwin_width(cols, width);
return width;
}