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);
}
#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() {
// hostname doesn't just change on runtime
static char* hostname = NULL;
static char hostname_buf[HOSTNAME_SIZE + 1];
if (!hostname) {
// hostnames larger won't render properly
hostname = hostname_buf;
if (gethostname(hostname_buf, HOSTNAME_SIZE) != 0) {
hostname = unknown_str;
} else {
// Ig "successful completion" doesn't contemplate truncation case, so need
// to append the unspecified nullbyte
// char* hidx =
// (char*)utf8back(&hostname[VALUES_COL - VALUES_SEPR - BOX_HMARGIN -
// 1]);
// *hidx = '\0';
static bool hostname_set = false;
static char hostname[HOSTNAME_SIZE + 1];
if (!hostname_set) {
strcpy(hostname, unknown_str);
int ret = gethostname(hostname, HOSTNAME_SIZE);
if (hostname[HOSTNAME_SIZE] != '\0' || ret < 0) {
// assume any type of truncation
hostname[HOSTNAME_SIZE] = '\0';
hostname[HOSTNAME_SIZE - 1] = '_'; // "ellipsis"
}
hostname_set = true;
}
clean_line(box_start, HEAD_ROW);