Skip to content

Commit 13ec188

Browse files
committed
Unicode character support in screen tab names
1 parent dd2dc57 commit 13ec188

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Action.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ Htop_Reaction Action_setScreenTab(State* st, int x) {
413413
int rem = x - SCREEN_TAB_MARGIN_LEFT;
414414
for (unsigned int i = 0; i < settings->nScreens; i++) {
415415
const char* tab = settings->screens[i]->heading;
416-
int width = rem >= bracketWidth ? (int)strnlen(tab, rem - bracketWidth + 1) : 0;
416+
const char* ptr = tab;
417+
int width = rem >= bracketWidth ? String_mbswidth(&ptr, SIZE_MAX, rem - bracketWidth + 1) : 0;
417418
if (width >= rem - bracketWidth + 1) {
418419
settings->ssIndex = i;
419420
setActiveScreen(settings, st, i);

ScreenManager.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ static inline bool drawTab(const int* y, int* x, int l, const char* name, bool c
177177
(*x)++;
178178
if (*x >= l)
179179
return false;
180-
int nameWidth = (int)strnlen(name, l - *x);
180+
const char* ptr = name;
181+
int nameWidth = String_mbswidth(&ptr, (size_t)INT_MAX, l - *x);
181182
attrset(CRT_colors[cur ? SCREENS_CUR_TEXT : SCREENS_OTH_TEXT]);
182-
mvaddnstr(*y, *x, name, nameWidth);
183+
mvaddnstr(*y, *x, name, (int)(ptr - name));
183184
*x += nameWidth;
184185
if (*x >= l)
185186
return false;

0 commit comments

Comments
 (0)