Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra character in watch colour mode on Ubuntu 17.10 #32

Closed
Rizhiy opened this issue Nov 20, 2017 · 15 comments
Closed

Extra character in watch colour mode on Ubuntu 17.10 #32

Rizhiy opened this issue Nov 20, 2017 · 15 comments
Labels
Milestone

Comments

@Rizhiy
Copy link

Rizhiy commented Nov 20, 2017

When I use command watch --color -n1.0 gpustat --color I get a lot of extra ^: https://imgur.com/a/A9Fxc

This problem doesn't occur without watch.
I'm on Ubuntu 17.10 with wayland.

@wookayin wookayin added the bug label Nov 21, 2017
@wookayin
Copy link
Owner

wookayin commented Nov 21, 2017

Which version of watch are you using? Or, what can be an output of watch gpustat --color (without --color option on the watch)? What is the value of $TERM?

@emberquill
Copy link

emberquill commented Nov 22, 2017

I have the same issue. This is what I get with `watch gpustat --color

watch gpustat --color

I'm also on Ubuntu 17.10, using the watch utility provided by procps-ng 3.3.12

Edit: I took a look at it and as far as I can tell, the issue has something to do with term.normal. Every time it's used in the output, it has an extra \x0f character at the end.

watch --color "gpustat --color | sed 's/\x0f//g'" works as a workaround. I don't know much about the blessings package so I can't really help beyond that.

@Stonesjtu
Copy link
Collaborator

I'll look into the bug. Working on setting a test environment on docker.

@Stonesjtu
Copy link
Collaborator

Stonesjtu commented Nov 22, 2017

I tested as the following and found that the new watch may not escape characters as my terminal.
Because my test computer has no GPUs, test_gpustat.py is used here

 # set force_color=True for gpustat --color
python test_gpustat.py > fc.log
cat fc.log # displays as normal
watch --color -n 1 cat fc.log # many ^ tails

There's a great PR implementing watch/top like monitoring function, which may solve the problems caused by watch.

The original output log file is attached fc.log on Ubuntu 17.10.

@wookayin
Copy link
Owner

wookayin commented Nov 23, 2017

For other environments such as macOS (my local), I can't reproduce the issue with the same version of watch procps-ng 3.3.12. (it could be watch 3.3.12 for LINUX only has the bug) I suspect printed the escape sequence for resetting color might be different.

The attachment is my output fc.log (in macOS), generated using your instructions. We can see the resetting sequence is ^[[0;10m, e.g. ^[[34mGeForce GTX TITAN 0^[[0;10m, while @emberquill's output reads ^[34mGeForce GTX 1070^[m^.

@Stonesjtu Can you please upload your fc.log file for comparison?

If so, I suspect blessings (ncurses) is in charge of this. Can you verify this?

>>> from blessings import Terminal
>>> term = Terminal(kind='linux', force_styling=True)
>>> term.normal
'\x1b[0;10m'

@Stonesjtu
Copy link
Collaborator

Stonesjtu commented Nov 24, 2017

The output on mac renders as normal without extra ^ in Ubuntu 17.10. And yes the term.normal differs unexpectedly.

In [1]: from blessings import Terminal

In [2]: term = Terminal(kind='linux', force_styling=True)

In [3]: term.normal
Out[3]: '\x1b[m\x0f'

And on my PC (Ubuntu 16.04), the term.normal returns correct sequence.

In [3]: term.normal
Out[3]: u'\x1b[0;10m'

@wookayin
Copy link
Owner

wookayin commented Nov 24, 2017

Right. It is from curses.tigetstr('sgr0'), which can be \x1b[0;10m or \x1b[m\x0f or \x1b(B\x1b[m, depending on TERM. The constants are defined in terminfo databases, which might differ in Ubuntu 17.10. Technically speaking, all sequences are correct to reset attributes (if TERM matches).

A problem is that watch is not smart enough to correctly handle all these ANSI or VT-100 escape sequences. Only workaround we can do is just strip those characters that are unknown to watch, just for compatibility.

One easiest way is simply truncate additional control characters (\x0f, or (Bx1b[m), but let me think more if there's more elegant way.

wookayin added a commit that referenced this issue Nov 24, 2017
In some environments (Ubuntu 17.10), the control character sequence
for resetting colors/attributes (sgr0) can't be recognized in
watch command. As a result, an additional character may be shown.

Using different termstr seems to resolve this issue, in that
`term.normal` returns a compatible control sequence.
@wookayin
Copy link
Owner

I've come up with a good workaround. Can you please try it out by installing the latest one from master branch?

Still, we would need a test case and travis setup with Ubuntu 17.10.

@Rizhiy
Copy link
Author

Rizhiy commented Nov 27, 2017

I no longer have this issue when using the latest version of the master branch.

@Rizhiy Rizhiy closed this as completed Nov 27, 2017
@wookayin
Copy link
Owner

Great, thanks! But let me keep this issue open for a while until I add a test/travis setup :)

@wookayin wookayin reopened this Nov 27, 2017
@wookayin wookayin added this to the 0.5 milestone Nov 29, 2017
@mjmikulski
Copy link

Hi!

First of all, thank you for a great tool!

I have the same issue in version 0.4.1 in Ubuntu 16.04. As I understand, this issue was fixed before 0.4.1, am I wrong?

Have a look on the screenshot, a lot of dashes:
issue

OS: Ubuntu 16.04.4 LTS

# gpustat --version
gpustat 0.4.1
# watch --version
watch from procps-ng 3.3.10

Intriguingly, on another, very similar machine, there is no dashes. The only difference is the ubuntu version: 16.04.3 LTS.

Any comments?

@Stonesjtu
Copy link
Collaborator

it's time to merge the builtin top watch support to workaround strange bugs caused by watch.

wookayin added a commit that referenced this issue Jun 12, 2018
This reverts 8d3f917 and adds another workaround patch for #32,
preventing the extra character in watch from being displayed.
@wookayin
Copy link
Owner

I have reverted 8d3f917, because with the xterm-color term the color becomes weird in watch. To have the original issue not happening again, I forced the use of (correct) escape sequence.

@mjmikulski @Stonesjtu Would you be available to verify it again on your environments? (with master branch, 132e99a)

@hak8or
Copy link

hak8or commented Jun 24, 2018

Due to this being reverted, is there consideration for a workaround to add a flag which does not show the first line? That way, using a simple while loop would work well enough. I created an issue (#43) for this.

Edit: My suggestion is already in mainline. For anyone else seeing this from google, if there isn't a new release then get a mainline version of this via pip install git+https://github.com/wookayin/gpustat.git@master.

@wookayin
Copy link
Owner

This is now released as 0.5.0. Sorry for making it a bit late.

wookayin added a commit that referenced this issue Aug 5, 2019
* -a, --show-all (#64)
* --color (#32: should work well with legacy watch)
wookayin added a commit that referenced this issue Feb 2, 2020
- To prevent blinking cursors, do not re-store cursor locations
- Workaround sgr0 character issues (#32) again
- Misc: various style cleanups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants