Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

-
- Remove third-party dependency `windows-curses` for Windows support by [@XuehaiPan](https://github.com/XuehaiPan) in [#149](https://github.com/XuehaiPan/nvitop/pull/149).

------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bash install-nvidia-driver.sh --latest # install the latest

Run `bash install-nvidia-driver.sh --help` for more information.

<a name="curses">*</a> The `curses` library is a built-in module of Python on Unix-like systems, and it is supported by a third-party package called `windows-curses` on Windows using PDCurses. Inconsistent behavior of `nvitop` may occur on different terminal emulators on Windows, such as missing mouse support.
<a name="curses">*</a> The `curses` library is a built-in module of Python on Unix-like systems, and `nvitop` supports Windows using ANSI escape codes. Inconsistent behavior of `nvitop` may occur on different terminal emulators on Windows, such as missing mouse support.

------

Expand Down
36 changes: 36 additions & 0 deletions docs/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
accessdenied
acs
addch
addnstr
addstr
api
args
ascii
attr
bel
bg
bool
boolean
bstate
cbreak
chgat
chtype
cli
cmdline
codepoint
colorama
colorscheme
compat
conf
const
cpython
csi
csv
ctrl
ctx
Expand All @@ -27,13 +39,15 @@ divmod
docstring
doctest
ecc
endwin
enum
env
environ
esc
failsafe
fallbacks
fg
fileno
fmt
func
getch
Expand All @@ -49,6 +63,8 @@ gpuprocesssnapshot
gpus
gpustatslogger
hostname
ignorable
initscr
ints
ipython
isinstance
Expand All @@ -57,6 +73,7 @@ keras
kib
kmd
kwargs
leaveok
len
libcuda
libcudart
Expand All @@ -71,13 +88,15 @@ mig
migdevice
milliwatts
mps
msvcrt
mypy
namespace
nan
noheader
noqa
nosuchprocess
nounits
num
nvidia
nvidia-smi
nvisel
Expand All @@ -86,6 +105,7 @@ nvml
nvmlerror
oneshot
ord
ored
os
ot
pan
Expand All @@ -103,16 +123,28 @@ pytorch
redhat
reentrant
resourcemetriccollector
rgb
rlist
rss
rstrip
rtx
runtime
rw
rx
rxvt
sanitization
scrollok
selectable
setupterm
sgi's
sgr
shader
sm
smi
stderr
stdin
stdout
stdscr
str
struct
subclasses
Expand All @@ -123,6 +155,7 @@ superset
sys
tcc
tensorflow
termios
throughputinfo
toml
traceback
Expand All @@ -134,10 +167,13 @@ uid
uids
unallocated
uncase
ungetch
unicode
unicodedata
uptime
utils
uuid
wcwidth
wddm
wdm
widestring
Expand Down
3 changes: 2 additions & 1 deletion nvitop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
__all__ = [*api.__all__, 'select_devices']

# Add submodules to the top-level namespace
submodule = api
for submodule in (
caching,
collector,
Expand All @@ -57,4 +58,4 @@
# Required for `python -m nvitop.select` to work properly
sys.modules.pop(f'{__name__}.select', None)

del sys
del sys, submodule
33 changes: 12 additions & 21 deletions nvitop/api/termcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@
__all__ = ['colored', 'cprint']


if os.name == 'nt': # Windows
try:
from colorama import init
except ImportError:
pass
else:
init()
try:
from colorama import just_fix_windows_console
except ImportError:
pass
else:
just_fix_windows_console()


ATTRIBUTES: dict[Attribute, int] = {
Expand All @@ -122,7 +121,6 @@
'concealed': 8,
'strike': 9,
}

HIGHLIGHTS: dict[Highlight, int] = {
'on_black': 40,
'on_grey': 40, # Actually black but kept for backwards compatibility
Expand All @@ -142,7 +140,6 @@
'on_light_cyan': 106,
'on_white': 107,
}

COLORS: dict[Color, int] = {
'black': 30,
'grey': 30, # Actually black but kept for backwards compatibility
Expand All @@ -162,8 +159,6 @@
'light_cyan': 96,
'white': 97,
}


RESET = '\033[0m'


Expand Down Expand Up @@ -239,19 +234,15 @@ def colored(
if not _can_do_color(no_color=no_color, force_color=force_color):
return result

fmt_str = '\033[%dm%s'
sequence = []
if color is not None:
result = fmt_str % (COLORS[color], result)

sequence.append(COLORS[color])
if on_color is not None:
result = fmt_str % (HIGHLIGHTS[on_color], result)

sequence.append(HIGHLIGHTS[on_color])
if attrs is not None:
for attr in attrs:
result = fmt_str % (ATTRIBUTES[attr], result)

result += RESET

sequence.extend(ATTRIBUTES[attr] for attr in attrs)
if sequence:
return f'\033[{";".join(map(str, sequence))}m{result}{RESET}'
return result


Expand Down
3 changes: 1 addition & 2 deletions nvitop/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"""The interactive NVIDIA-GPU process viewer."""

import argparse
import curses
import os
import sys
import textwrap

from nvitop.api import HostProcess, libnvml
from nvitop.tui import TUI, USERNAME, Device, colored, libcurses, set_color, setlocale_utf8
from nvitop.tui import TUI, USERNAME, Device, colored, curses, libcurses, set_color, setlocale_utf8
from nvitop.version import __version__


Expand Down
2 changes: 2 additions & 0 deletions nvitop/tui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
USERNAME,
Device,
colored,
curses,
libcurses,
set_color,
setlocale_utf8,
Expand All @@ -21,6 +22,7 @@
'USERNAME',
'Device',
'colored',
'curses',
'libcurses',
'set_color',
'setlocale_utf8',
Expand Down
3 changes: 2 additions & 1 deletion nvitop/tui/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# pylint: disable=missing-module-docstring

from nvitop.tui.library import host
from nvitop.tui.library import curses, host
from nvitop.tui.library.device import Device, MigDevice
from nvitop.tui.library.displayable import Displayable, DisplayableContainer
from nvitop.tui.library.history import BufferedHistoryGraph, HistoryGraph
Expand Down Expand Up @@ -80,6 +80,7 @@
'WideString',
'bytes2human',
'colored',
'curses',
'cut_string',
'host',
'libcurses',
Expand Down
Loading