feat: support long hostnames

close #49
This commit is contained in:
javalsai 2025-07-04 03:56:51 +02:00
parent ba836e5cd4
commit 5b5adf76b7
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8

View File

@ -322,25 +322,21 @@ u_char get_render_pos_offset(struct opts_field* self, u_char maxlen) {
return pos - ofield_display_cursor_col(self, maxlen); return pos - ofield_display_cursor_col(self, maxlen);
} }
#define HOSTNAME_SIZE (VALUES_COL - VALUES_SEPR - BOX_HMARGIN) #define HOSTNAME_SIZE (VALUES_COL - VALUES_SEPR - BOX_HMARGIN - 1)
// TODO: make hostname utf8 compatible
void print_head() { void print_head() {
// hostname doesn't just change on runtime // hostname doesn't just change on runtime
static char* hostname = NULL; static bool hostname_set = false;
static char hostname_buf[HOSTNAME_SIZE + 1]; static char hostname[HOSTNAME_SIZE + 1];
if (!hostname) { if (!hostname_set) {
// hostnames larger won't render properly strcpy(hostname, unknown_str);
hostname = hostname_buf; int ret = gethostname(hostname, HOSTNAME_SIZE);
if (gethostname(hostname_buf, HOSTNAME_SIZE) != 0) { if (hostname[HOSTNAME_SIZE] != '\0' || ret < 0) {
hostname = unknown_str; // assume any type of truncation
} else { hostname[HOSTNAME_SIZE] = '\0';
// Ig "successful completion" doesn't contemplate truncation case, so need hostname[HOSTNAME_SIZE - 1] = '_'; // "ellipsis"
// to append the unspecified nullbyte
// char* hidx =
// (char*)utf8back(&hostname[VALUES_COL - VALUES_SEPR - BOX_HMARGIN -
// 1]);
// *hidx = '\0';
} }
hostname_set = true;
} }
clean_line(box_start, HEAD_ROW); clean_line(box_start, HEAD_ROW);