mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-21 06:45:24 -06:00
feat(gui): allow set colorful mode from environment variable
Signed-off-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
This commit is contained in:
parent
04f938196a
commit
95ec16dd98
2 changed files with 19 additions and 14 deletions
18
README.md
18
README.md
|
|
@ -308,7 +308,7 @@ coloring:
|
|||
override the `TREM` variable.
|
||||
--force-color Force colorize even when `stdout` is not a TTY terminal.
|
||||
--light Tweak visual results for light theme terminals in monitor mode.
|
||||
Set variable `NVITOP_MONITOR_THEME="light"` on light terminals for convenience.
|
||||
Set variable `NVITOP_MONITOR_MODE="light"` on light terminals for convenience.
|
||||
--gpu-util-thresh th1 th2
|
||||
Thresholds of GPU utilization to determine the load intensity.
|
||||
Coloring rules: light < th1 % <= moderate < th2 % <= heavy.
|
||||
|
|
@ -342,21 +342,19 @@ process filtering:
|
|||
|
||||
`nvitop` can accept the following environment variables for monitor mode:
|
||||
|
||||
| Name | Description | Valid Values | Fallback Value |
|
||||
| -------------------------------------- | -------------------------------- | ----------------------------------------------------------- | -------------- |
|
||||
| `NVITOP_MONITOR_ALWAYS` | Always invoke the monitor mode | `true` / `yes` / `on` / `1`<br>`false` / `no` / `off` / `0` | `true` |
|
||||
| `NVITOP_MONITOR_MODE` | The default display mode | `auto` / `full` / `compact` | `auto` |
|
||||
| `NVITOP_MONITOR_THEME` | The default color theme | `dark` / `light` | `dark` |
|
||||
| `NVITOP_GPU_UTILIZATION_THRESHOLDS` | Thresholds of GPU utilization | `10,75` , `1,99`, ... | `10,75` |
|
||||
| `NVITOP_MEMORY_UTILIZATION_THRESHOLDS` | Thresholds of GPU memory percent | `10,80` , `1,99`, ... | `10,80` |
|
||||
| Name | Description | Valid Values | Default Value |
|
||||
| -------------------------------------- | --------------------------------------------------- | ----------------------------------------------------------------------- | ----------------- |
|
||||
| `NVITOP_MONITOR_ALWAYS` | Always invoke the monitor mode | `true` / `yes` / `on` / `1`<br>`false` / `no` / `off` / `0` | `true` |
|
||||
| `NVITOP_MONITOR_MODE` | The default display mode (a comma-separated string) | `auto` / `full` / `compact`<br>`plain` / `colorful`<br>`dark` / `light` | `auto,plain,dark` |
|
||||
| `NVITOP_GPU_UTILIZATION_THRESHOLDS` | Thresholds of GPU utilization | `10,75` , `1,99`, ... | `10,75` |
|
||||
| `NVITOP_MEMORY_UTILIZATION_THRESHOLDS` | Thresholds of GPU memory percent | `10,80` , `1,99`, ... | `10,80` |
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
# Replace the following export statements if you are not using Bash / Zsh
|
||||
export NVITOP_MONITOR_ALWAYS="true"
|
||||
export NVITOP_MONITOR_MODE="full"
|
||||
export NVITOP_MONITOR_THEME="light"
|
||||
export NVITOP_MONITOR_MODE="full,light"
|
||||
|
||||
# Full monitor mode with light terminal tweaks
|
||||
nvitop
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ from nvitop.version import __version__
|
|||
|
||||
|
||||
TTY = sys.stdin.isatty() and sys.stdout.isatty()
|
||||
NVITOP_MONITOR_MODE = set(
|
||||
map(str.strip, os.environ.get('NVITOP_MONITOR_MODE', '').lower().split(','))
|
||||
)
|
||||
|
||||
|
||||
def parse_arguments(): # pylint: disable=too-many-branches,too-many-statements
|
||||
|
|
@ -112,7 +115,7 @@ def parse_arguments(): # pylint: disable=too-many-branches,too-many-statements
|
|||
action='store_true',
|
||||
help=(
|
||||
'Tweak visual results for light theme terminals in monitor mode.\n'
|
||||
'Set variable `NVITOP_MONITOR_THEME="light"` on light terminals for convenience.'
|
||||
'Set variable `NVITOP_MONITOR_MODE="light"` on light terminals for convenience.'
|
||||
),
|
||||
)
|
||||
gpu_thresholds = Device.GPU_UTILIZATION_THRESHOLDS
|
||||
|
|
@ -210,8 +213,10 @@ def parse_arguments(): # pylint: disable=too-many-branches,too-many-statements
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.colorful:
|
||||
args.colorful = 'colorful' in NVITOP_MONITOR_MODE and 'plain' not in NVITOP_MONITOR_MODE
|
||||
if not args.light:
|
||||
args.light = os.getenv('NVITOP_MONITOR_THEME', 'dark').lower() == 'light'
|
||||
args.light = 'light' in NVITOP_MONITOR_MODE and 'dark' not in NVITOP_MONITOR_MODE
|
||||
if args.user is not None and len(args.user) == 0:
|
||||
args.user.append(USERNAME)
|
||||
if args.gpu_util_thresh is None:
|
||||
|
|
@ -270,9 +275,11 @@ def main(): # pylint: disable=too-many-branches,too-many-statements,too-many-lo
|
|||
del args.monitor
|
||||
|
||||
if hasattr(args, 'monitor') and args.monitor is None:
|
||||
mode = os.getenv('NVITOP_MONITOR_MODE', 'auto').lower()
|
||||
if mode not in ('auto', 'full', 'compact'):
|
||||
mode = NVITOP_MONITOR_MODE.intersection({'auto', 'full', 'compact'})
|
||||
if len(mode) != 1:
|
||||
mode = 'auto'
|
||||
else:
|
||||
mode = mode.pop()
|
||||
args.monitor = mode
|
||||
|
||||
if not setlocale_utf8():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue