15

For a while now, I've had this persistent issue on all my terminals, from the gnome default and tilda which I both use to ones I just gave a quick whirl, where my input will overwrite the start of its own line when it should wrap, and only wrapping on the next line.

Pressing Ctrl-A to return to the start of the line will instead return me somewhere up in the line before my first input line, from which any more input just gets very weird.

Because this is a really bad explanation and hard to visualize, here's how it looks:

Screencap: line wrapping test

Does anyone know what this is? It doesn't only happen under certain circumstances, it's a permanent thing that is always there from start to finish of every session in every terminal emulator.

Output of printf "%s\n" "$PS1" "$COLUMNS":

leod:~$ printf "%s\n" "$PS1" "$COLUMNS"
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 
80

Output of stty -a:

leod:~$ stty -a
speed 38400 baud; rows 11; columns 140; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
  • 3
    Add the output of printf "%s\n" "$PS1" "$COLUMNS", please. – muru Jan 15 '18 at 1:23
  • It could be your program test leaves the terminal in an unstable state. If it's a script can you include that in your question? What happens if you start typing without running test first, does text wrap normally? – WinEunuuchs2Unix Jan 15 '18 at 2:41
  • 1
    Can we see the output of stty -a as well please? – steeldriver Jan 15 '18 at 2:56
  • 1
    @WinEunuuchs2Unix wrong test (pun intended). Try type -a test instead. – muru Jan 15 '18 at 3:19
  • 1
    What's the output of printf "%q\n" "$PS1"? There might be raw escape sequences inside PS1, and %s leaves them intact (which might e.g. change the color back and forth which remains unnoticed in the output). %q quotes every nonprintable character in a readable way. – egmont Mar 11 '18 at 22:23
7

It's possible your terminal is not recognizing the window size correctly. I found a related question in U&L Stackexchange, and someone suggested the below way of checking whether this is what's going on:

Type

shopt | grep checkwinsize

If the output is not:

checkwinsize    on

You can use

shopt -s checkwinsize

to activate. To deactivate: shopt -u checkwinsize

  • 1
    Perhaps I didn't test enough but my checkwinsize was already on. I used shopt -u checkwinsize to turn it off and my terminal still wrapped text correctly. I'm not sure if this answer truly solves OP problem. – WinEunuuchs2Unix Apr 1 '18 at 18:38
  • Brilliant. This is the fix I needed. The command line wrap works perfectly now at well over 80 characters. – Randy Mar 29 at 4:24
  • @Randy Glad to hear it worked for you! – Hee Jin Mar 29 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.