unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#48716: 28.0.50; Spurious output from term-emulate-terminal when in line-mode
@ 2021-05-28 15:00 Massimiliano Mirra
  2022-06-03  2:46 ` Sean Whitton
  0 siblings, 1 reply; 2+ messages in thread
From: Massimiliano Mirra @ 2021-05-28 15:00 UTC (permalink / raw)
  To: 48716


[-- Attachment #1.1: Type: text/plain, Size: 4851 bytes --]

Spurious output is occasionally produced when running a command
with `make-term', and the command performs cursor movements and
partial screen clears.

- Reproduction #1 shows what happens when using `yarn' to install
  packages in a NodeJS project. (For ease and reliability of
  reproduction, a recording made with script(1) is run instead
  of the actual command.)

  Run with: emacs -Q -l repro-1.el
  Preview: https://asciinema.org/a/4mMv1aIrMmizwxr01AaEXMQqe

- Reproduction #2 shows a minimal (provided) Python program that
  creates a progress bar.

  Run with: emacs -Q -l repro-2.el
  Preview: https://asciinema.org/a/K6XCPbgkuqk6op4KQyiX9L5n7

The problem only happens in `term-line-mode' (the default).
`term-char-mode' works fine.  It is affected by the rate of output:
changing "scriptreplay" in repro-1.el to "scriptreplay -d 5" (5x
speed) still produces different, though still wrong, output.

The culprit appears to be following lines from `term-emulate-terminal'
in term.el; commenting them out fixes this problem:

   (when (and (> (point-max) (process-mark proc))
      (term-in-line-mode))
     (narrow-to-region (point-min) (process-mark proc)))


In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.29,
cairo version 1.17.4)
 of 2021-05-16 built on 956e3d7386ff
Repository revision: 78575c53fc8c78de1494822f9f6680e2a21308d6
Repository branch: pgtk-nativecomp
Windowing system distributor 'System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-sound=alsa --with-modules --with-x-toolkit=gtk3 --with-cairo
 --with-xwidgets --with-native-compilation --with-pgtk
 --without-compress-install --without-gconf --without-gsettings
 --without-m17n-flt --enable-autodepend --enable-link-time-optimization
 CC=/usr/bin/clang 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe
 -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS
 -Wformat -Werror=format-security -fstack-clash-protection
 -fcf-protection -g -flto'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
 'CPP=/usr/bin/clang -E''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM HARFBUZZ JPEG JSON LCMS2
LIBOTF LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER
PGTK PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XIM
XWIDGETS GTK3 ZLIB

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LC_MESSAGES: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/pgtk-win pgtk-win term/common-win tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads
xwidget-internal dbusbind inotify dynamic-setting font-render-setting
cairo move-toolbar gtk x-toolkit pgtk lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 69245 8432)
 (symbols 48 6922 0)
 (strings 32 20554 2262)
 (string-bytes 1 684028)
 (vectors 16 13527)
 (vector-slots 8 293613 14217)
 (floats 8 22 39)
 (intervals 56 240 0)
 (buffers 992 10))

-- 
Massimiliano Mirra
massimilianomirra.com

[-- Attachment #1.2: Type: text/html, Size: 5811 bytes --]

[-- Attachment #2: repro-1.el --]
[-- Type: text/x-emacs-lisp, Size: 394 bytes --]

(require 'term)

;; Using a recording created with script(1) for reproducibility.
;; The recording was created with:
;;
;;   git clone https://github.com/bard/starter-node-basic
;;   cd starter-node-basic
;;   script -c yarn
;;
(switch-to-buffer
 (make-term "test"
            shell-file-name
            nil
            "-c"
            "scriptreplay -t repro-1.timingfile repro-1.script"))



[-- Attachment #3: repro-1.timingfile --]
[-- Type: application/octet-stream, Size: 5646 bytes --]

0.140852 4
0.000330 4
0.000035 32
0.021369 8
0.000055 35
0.007566 4
0.000030 4
0.000030 43
0.002250 4
0.000026 4
0.000020 38
0.000512 4
0.000026 4
0.000013 4
0.060727 4
0.000019 17
0.000038 4
0.060234 4
0.000032 17
0.000027 4
0.061645 4
0.000010 17
0.000066 4
0.060175 21
0.000007 4
0.061015 37
0.060294 37
0.094692 25
0.060537 25
0.059418 56
0.060172 54
0.060210 41
0.000008 4
0.060141 46
0.060242 4
0.000020 43
0.061177 49
0.061498 26
0.062423 4
0.000009 51
0.000003 4
0.062269 33
0.060723 25
0.060960 33
0.060174 24
0.060393 31
0.060101 33
0.059661 32
0.060888 44
0.060859 54
0.060159 52
0.060362 31
0.060463 33
0.060066 27
0.062041 24
0.060912 33
0.060813 42
0.059416 42
0.060295 42
0.060311 42
0.060862 52
0.060206 52
0.060319 4
0.000010 48
0.059729 28
0.060396 4
0.000009 16
0.000017 4
0.059928 4
0.000100 20
0.060413 31
0.061299 4
0.000561 34
0.059393 29
0.059991 38
0.061874 4
0.000039 23
0.061332 24
0.059831 4
0.000021 20
0.000020 4
0.061821 26
0.060006 34
0.060513 45
0.060270 45
0.060031 45
0.061162 26
0.061338 29
0.069640 24
0.000012 4
0.060476 4
0.000007 21
0.000012 4
0.060534 24
0.060715 4
0.000026 21
0.000019 4
0.060237 23
0.060353 35
0.059947 41
0.065710 26
0.062405 28
0.059935 43
0.000007 4
0.060214 43
0.060169 24
0.000010 4
0.059639 42
0.059693 4
0.000055 24
0.060618 24
0.060454 24
0.060095 24
0.059982 31
0.065346 32
0.000490 4
0.061313 29
0.000048 4
0.065889 27
0.060500 4
0.000009 17
0.000039 4
0.060741 24
0.000009 4
0.059576 39
0.060694 33
0.063603 31
0.000007 4
0.059949 23
0.060386 32
0.060653 33
0.060762 27
0.062305 29
0.065330 4
0.000011 24
0.064103 51
0.000010 4
0.060524 4
0.000010 15
0.059981 37
0.059536 26
0.059974 45
0.061566 33
0.056762 8
0.000103 178
0.002359 26
0.000008 4
0.034245 8
0.000058 175
0.026315 31
0.059994 27
0.059411 28
0.060388 38
0.000008 4
0.059829 28
0.061126 33
0.060544 27
0.060866 28
0.060254 31
0.061529 27
0.059660 4
0.000048 25
0.060534 29
0.059533 29
0.116381 4
0.000014 4
0.000993 4
0.000035 4
0.000025 35
0.000008 2
0.010546 8
0.000151 4
0.000008 97
0.085381 4
0.000021 97
0.060851 4
0.000008 97
0.061860 101
0.061441 4
0.000009 97
0.061023 4
0.000009 97
0.045321 95
0.000077 131
0.005490 4
0.000010 4
0.000014 40
0.001329 4
0.000020 4
0.000042 99
0.000077 4
0.000006 4
0.000035 131
0.000042 8
0.000033 136
0.000054 4
0.000006 4
0.000027 139
0.000049 4
0.000009 4
0.000025 161
0.000046 4
0.000009 4
0.000025 147
0.000050 4
0.000010 4
0.000024 143
0.000034 4
0.000009 4
0.000028 138
0.000030 4
0.000011 4
0.000022 134
0.000029 4
0.000009 4
0.000028 139
0.000032 4
0.000005 4
0.000032 150
0.000030 4
0.000011 4
0.000021 144
0.000034 4
0.000004 4
0.000027 139
0.000029 4
0.000009 4
0.000022 149
0.000029 4
0.000009 4
0.000023 137
0.000029 4
0.000010 4
0.000022 140
0.000029 4
0.000005 4
0.000026 148
0.000033 4
0.000004 4
0.000026 145
0.000066 145
0.000019 4
0.000010 4
0.000022 135
0.000030 4
0.000009 4
0.000043 139
0.000021 4
0.000006 4
0.000033 133
0.000030 4
0.000004 4
0.000027 140
0.000031 4
0.000006 4
0.000025 131
0.000139 8
0.000012 148
0.000032 4
0.000005 4
0.000027 146
0.000094 145
0.000023 8
0.000021 136
0.000036 4
0.000006 4
0.000022 137
0.000067 149
0.000031 4
0.000007 4
0.000033 146
0.000065 144
0.000034 4
0.000007 4
0.000020 138
0.000032 4
0.000006 4
0.000026 141
0.000033 4
0.000006 4
0.000025 146
0.000032 4
0.000006 4
0.000031 142
0.000030 4
0.000006 4
0.000025 137
0.000033 4
0.000006 4
0.000023 130
0.000041 4
0.000006 4
0.000025 136
0.000033 4
0.000010 4
0.000025 136
0.000033 4
0.000006 4
0.000021 138
0.000035 4
0.000006 4
0.000022 147
0.000035 4
0.000006 4
0.000024 137
0.000033 4
0.000007 4
0.000023 129
0.000032 4
0.000007 4
0.000022 132
0.000033 4
0.000006 4
0.000022 150
0.000031 4
0.000009 4
0.000025 139
0.000032 4
0.000006 4
0.000024 134
0.000034 4
0.000005 4
0.000033 150
0.000021 4
0.000006 4
0.000021 139
0.000038 4
0.000006 4
0.000024 133
0.000038 4
0.000007 4
0.000024 134
0.000033 4
0.000006 4
0.000025 134
0.000031 4
0.000005 4
0.000023 141
0.000035 4
0.000006 4
0.000024 135
0.000032 4
0.000006 4
0.000023 136
0.000033 4
0.000006 4
0.000024 138
0.000035 4
0.000006 4
0.000024 144
0.000032 4
0.000012 4
0.000016 129
0.000032 4
0.000006 4
0.000024 137
0.000035 4
0.000007 4
0.000023 136
0.000035 4
0.000006 4
0.000024 139
0.000033 4
0.000006 4
0.000022 140
0.000032 4
0.000006 4
0.000022 137
0.000037 4
0.000007 4
0.000021 119
0.000032 4
0.000005 4
0.000023 127
0.000034 4
0.000006 4
0.000027 127
0.000037 4
0.000006 4
0.000022 131
0.000040 4
0.000006 4
0.000022 183
0.000039 4
0.000006 4
0.000022 188
0.000052 4
0.000005 4
0.000023 168
0.000075 4
0.000006 4
0.000024 106
0.000035 4
0.000006 4
0.000022 140
0.000035 4
0.000005 4
0.000025 175
0.105125 101
0.004237 4
0.000007 4
0.000051 4
0.000011 4
0.000024 4
0.000010 97
0.730066 4
0.000019 4
0.000019 4
0.000004 4
0.000023 4
0.000019 97
0.062477 4
0.000010 97
0.065142 4
0.000008 97
0.061503 101
0.072942 4
0.000021 97
0.062339 4
0.000008 97
0.061602 4
0.000010 97
0.060847 4
0.000015 97
0.061186 4
0.000008 97
0.063503 4
0.000007 97
0.063473 4
0.000009 97
0.062259 101
0.062401 4
0.000006 97
0.064965 4
0.000008 97
0.067685 4
0.000015 97
0.059789 4
0.000014 97
0.061366 101
0.063674 4
0.000012 97
0.060893 4
0.000007 97
0.061051 4
0.000007 97
0.061726 4
0.000013 97
0.060933 4
0.000008 97
0.060813 4
0.000036 97
0.061608 4
0.000007 97
0.060838 4
0.000015 97
0.064366 4
0.000007 97
0.061591 4
0.000007 97
0.063178 4
0.000009 97
0.061916 4
0.000010 97
0.060657 4
0.000017 97
0.062495 4
0.000011 97
0.018135 16
0.000084 101
0.060241 101
0.061489 4
0.000010 97
0.008454 4
0.000045 4
0.000031 43
0.005472 4
0.062359 4
0.000007 4
0.000022 35
0.003435 34
0.070429 29
0.003790 8
0.000074 25

[-- Attachment #4: repro-1.script --]
[-- Type: application/octet-stream, Size: 20082 bytes --]

[-- Attachment #5: repro-2.el --]
[-- Type: text/x-emacs-lisp, Size: 150 bytes --]

(require 'term)

(switch-to-buffer
 (make-term "test"
            shell-file-name
            nil
            "-c"
            "python repro-2.py"))


[-- Attachment #6: repro-2.py --]
[-- Type: text/x-python, Size: 392 bytes --]

# a simple progress bar

import time
import sys

progressbar_width = 40

sys.stdout.write("[%s]" % (" " * progressbar_width))
sys.stdout.flush()
sys.stdout.write("\b" * (progressbar_width + 1))  # return to start of line, after '['

for i in range(progressbar_width):
    time.sleep(0.1)
    sys.stdout.write("-")
    sys.stdout.flush()

sys.stdout.write("]\n")  # this ends the progress bar

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#48716: 28.0.50; Spurious output from term-emulate-terminal when in line-mode
  2021-05-28 15:00 bug#48716: 28.0.50; Spurious output from term-emulate-terminal when in line-mode Massimiliano Mirra
@ 2022-06-03  2:46 ` Sean Whitton
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Whitton @ 2022-06-03  2:46 UTC (permalink / raw)
  To: Massimiliano Mirra, 48716

Hello,

On Fri 28 May 2021 at 04:00PM +01, Massimiliano Mirra wrote:

> Spurious output is occasionally produced when running a command
> with `make-term', and the command performs cursor movements and
> partial screen clears.
>
> [...]
>
> The culprit appears to be following lines from `term-emulate-terminal'
> in term.el; commenting them out fixes this problem:
>
>    (when (and (> (point-max) (process-mark proc))
>       (term-in-line-mode))
>      (narrow-to-region (point-min) (process-mark proc)))

The code assumes anything after the process mark is prospective input,
which is very often going to be wrong when the command moves the cursor
-- even if the command just emits \r.  One way to fix this might be to
add text properties to actual output, thereby distinguishing it from
something the user has typed.

-- 
Sean Whitton





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-03  2:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 15:00 bug#48716: 28.0.50; Spurious output from term-emulate-terminal when in line-mode Massimiliano Mirra
2022-06-03  2:46 ` Sean Whitton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).