[PR #15] [MERGED] Fix locale encoding when C.UTF-8 is not available #121

Closed
opened 2026-05-05 03:26:17 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/XuehaiPan/nvitop/pull/15
Author: @XuehaiPan
Created: 4/19/2022
Status: Merged
Merged: 4/19/2022
Merged by: @XuehaiPan

Base: devHead: fix-locale-utf8


📝 Commits (1)

  • 1c2744e fix(gui/libcurses): fix locale encoding when C.UTF-8 is not available

📊 Changes

4 files changed (+22 additions, -26 deletions)

View changed files

📝 nvitop/cli.py (+5 -14)
📝 nvitop/gui/__init__.py (+2 -1)
📝 nvitop/gui/library/__init__.py (+1 -1)
📝 nvitop/gui/library/libcurses.py (+14 -10)

📄 Description

Issue Type

  • Bug fix

Runtime Environment

  • Operating system and version: CentOS Linux release 7.9.2009 (Core)
  • Terminal emulator and version: Windows Terminal 1.12.10732.0
  • Python version: 3.6.8
  • NVML version (driver version): 512.15
  • nvitop version or commit: dev@93926f3
  • python-ml-py version: 11.450.51
  • Locale: en_US.UTF-8

Description

The fresh installed CentOS 7 does not have locale C.UTF-8.

[root@centos /]# locale -a
C
en_US.utf8
POSIX
[root@centos /]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
[root@centos /]# 

nvitop sets the locale setting to C which does not support Unicode box-drawing characters. However the system default, which is en_US.utf8, does support Unicode characters.

93926f3865/nvitop/gui/library/libcurses.py (L88-L97)

Motivation and Context

Reorder locale encoding detection. Let the system default (setlocale(LC_ALL, '')) precedes setlocale(LC_ALL, 'C'). Fix box-drawing on CentOS 7.

Fixes #14

Testing

Tested on CentOS 7 docker container.

Images / Videos

Set locale to C:

Screenshot 1

Set locale to system default:

Screenshot 2


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/XuehaiPan/nvitop/pull/15 **Author:** [@XuehaiPan](https://github.com/XuehaiPan) **Created:** 4/19/2022 **Status:** ✅ Merged **Merged:** 4/19/2022 **Merged by:** [@XuehaiPan](https://github.com/XuehaiPan) **Base:** `dev` ← **Head:** `fix-locale-utf8` --- ### 📝 Commits (1) - [`1c2744e`](https://github.com/XuehaiPan/nvitop/commit/1c2744e453540b532d1b0330db16d943fb6d2a5c) fix(gui/libcurses): fix locale encoding when `C.UTF-8` is not available ### 📊 Changes **4 files changed** (+22 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `nvitop/cli.py` (+5 -14) 📝 `nvitop/gui/__init__.py` (+2 -1) 📝 `nvitop/gui/library/__init__.py` (+1 -1) 📝 `nvitop/gui/library/libcurses.py` (+14 -10) </details> ### 📄 Description <!-- Provide a descriptive summary of the changes in the title above --> #### Issue Type <!-- Pick relevant types and delete the rest --> - Bug fix #### Runtime Environment <!-- Details of your runtime environment --> - Operating system and version: CentOS Linux release 7.9.2009 (Core) - Terminal emulator and version: Windows Terminal 1.12.10732.0 - Python version: `3.6.8` - NVML version (driver version): `512.15` - `nvitop` version or commit: `dev@93926f3` - `python-ml-py` version: `11.450.51` - Locale: `en_US.UTF-8` #### Description <!-- Describe the changes in detail --> The fresh installed CentOS 7 does not have locale `C.UTF-8`. ```console [root@centos /]# locale -a C en_US.utf8 POSIX [root@centos /]# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8 [root@centos /]# ``` `nvitop` sets the locale setting to `C` which does not support Unicode box-drawing characters. However the system default, which is `en_US.utf8`, does support Unicode characters. https://github.com/XuehaiPan/nvitop/blob/93926f3865015cc02550ee7e27f5ce3a73adf8aa/nvitop/gui/library/libcurses.py#L88-L97 #### Motivation and Context <!-- Why are these changes required? --> <!-- What problems do these changes solve? --> <!-- Link to relevant issues --> Reorder locale encoding detection. Let the system default (`setlocale(LC_ALL, '')`) precedes `setlocale(LC_ALL, 'C')`. Fix box-drawing on CentOS 7. Fixes #14 #### Testing <!-- What tests have been run? --> <!-- How does the changes affect other areas of the codebase? --> Tested on CentOS 7 docker container. #### Images / Videos <!-- Only if relevant --> <!-- Link or embed images and videos of screenshots, sketches etc. --> Set locale to `C`: ![Screenshot 1](https://user-images.githubusercontent.com/16078332/163951408-5a4bab8c-d69d-4d8c-a8ab-4a623b5ef41c.png) Set locale to system default: ![Screenshot 2](https://user-images.githubusercontent.com/16078332/163951461-01169a28-6ef5-477b-b9b5-87f229b3874f.png) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 03:26:17 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/nvitop#121
No description provided.