Skip to content

watch: incorrect output with --no-wrap && (blank lines || wide characters)

With no options, watch performs the following correctly in a terminal with 39 columns.

$ watch watch
(...)
 -v, --version  output version informat
ion and exit

For more details see watch(1).
$ cat /tmp/del
やまと - 大和国(奈良県)を特に指すとと
もに日

が成立する前、日本列島には、中国の王朝
から「倭国」・「倭」
$ watch 'cat /tmp/del'
やまと - 大和国(奈良県)を特に指すとと
もに日

が成立する前、日本列島には、中国の王朝
から「倭国」・「倭」

Now with --no-wrap.

$ watch -w watch
(...)
 -v, --version  output version informat
For more details see watch(1).
$ watch -w 'cat /tmp/del'
やまと - 大和国(奈良県)を特に指すとと
が成立する前、日本列島には、中国の王朝
から「倭国」・「倭」

The synthetic line restarts of the form x=-1; continue; in run_command() are likely the cause. In the cat instance the last line isn't cut at all because the last character has wcwidth()==2, I suppose. Please merge in !186 (closed) before you fix.