Skip to content

Commit ef4f749

Browse files
committed
Unicode character support in screen tab names
1 parent 6657e9f commit ef4f749

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Action.c

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

ScreenManager.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ static inline bool drawTab(const int* y, int* x, int l, const char* name, bool c
169169
(*x)++;
170170
if (*x >= l)
171171
return false;
172-
int nameWidth = (int)strnlen(name, l - *x);
172+
const char* ptr = name;
173+
int nameWidth = String_mbswidth(&ptr, (size_t)INT_MAX, l - *x);
173174
attrset(CRT_colors[cur ? SCREENS_CUR_TEXT : SCREENS_OTH_TEXT]);
174-
mvaddnstr(*y, *x, name, nameWidth);
175+
mvaddnstr(*y, *x, name, (int)(ptr - name));
175176
*x += nameWidth;
176177
if (*x >= l)
177178
return false;

0 commit comments

Comments
 (0)