2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-08-27 17:16:40 +00:00

fix(genesis): clamp narrow console headers

This commit is contained in:
Vinícius Ferrão
2026-08-20 22:41:25 -03:00
parent 8442dba2bf
commit b719eb8328
3 changed files with 11 additions and 4 deletions
@@ -17,6 +17,7 @@ enum xcat_console_limit {
LOG_LINE_SIZE = 384,
LOG_VIEW_HEIGHT = 17,
LOG_VIEW_WIDTH = 68,
HEADER_RESERVED_COLUMNS = 20,
};
struct console_state {
@@ -112,6 +113,7 @@ void xcat_format_duration(unsigned long long seconds, char *value, size_t size);
bool xcat_read_unsigned_key(const char *path, const char *key, unsigned long long *number);
unsigned int xcat_list_files(const char *directory, const char *suffix, char *names,
size_t names_size);
int xcat_header_context_columns(int screen_columns);
void xcat_load_console_state(struct console_state *state);
void xcat_build_status_view(const struct console_state *state, struct status_view *view);
@@ -112,12 +112,11 @@ static void draw_header(const struct status_view *view) {
int columns;
newtGetScreenSize(&columns, NULL);
available = columns - 20;
available = xcat_header_context_columns(columns);
xcat_set_text(context, sizeof(context), "%.*s", available, view->identity);
if ((int)strlen(context) > available)
context[available] = '\0';
newtDrawRootText(1, 0, "xCAT Genesis");
newtDrawRootText(-((int)strlen(context) + 1), 0, context);
if (context[0] != '\0')
newtDrawRootText(-((int)strlen(context) + 1), 0, context);
}
static void update_form(struct console_form *screen, const struct status_view *view,
@@ -215,3 +215,9 @@ unsigned int xcat_list_files(const char *directory, const char *suffix, char *na
closedir(stream);
return count;
}
int xcat_header_context_columns(int screen_columns) {
if (screen_columns <= HEADER_RESERVED_COLUMNS)
return 0;
return screen_columns - HEADER_RESERVED_COLUMNS;
}