Command wraps around same line after 80 characters

5,437

Solution 1

This worked for me. The target shell needs to be set to check window size and to be set to the correct size of your console gui. After connecting via serial with either putty or minicom:

shopt -s checkwinsize
resize

Solution 2

When you are connected via a serial line, there is no way for the system to negotiate the window size with the terminal (NAWS - Negotiate About Window Size is RFC 1073). In that case you can get either a system default for the size, or even just zeros. Either would confuse the shell's line editor, which needs to know the actual width of the terminal to work with its wraparound feature.

bash gets confused, thinking it has wrapped due to terminal's autowrap feature and moves to the beginning of the current (wrong) line as part of the line-editing/display.

As a workaround, most of the terminals (including minicom — see source) which you would use with a serial interface can respond to the cursor position report escape sequence used by resize to find the window size — and as a side effect set the system's idea of how large your terminal window is.

Share:
5,437

Related videos on Youtube

Oliver G.
Author by

Oliver G.

Updated on September 18, 2022

Comments

  • Oliver G.
    Oliver G. almost 2 years

    I have an annoying problem with minicom connected to a serial console to a Yocto Linux machine.

    The command that I enter wraps around on the same line after 80th character. This becomes very inconvenient to work with. Everything I entered at the beginning of the line gets overwritten by the last chars of that line.

    A SSH connection to the same machine works just fine. After 80th characters ssh go to the next line.

    This is the stty setting:

    stty -a
    speed 115200 baud; rows 24; columns 80; 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; flush = ^O; min = 1; time = 0;
    -parenb -parodd 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
    

    The -w option of minicom has no effect. Still the same behavior

    minicom -w
    

    The resize command is not available on that machine. To which package does it belong? Maybe I can install it.

    How can I fix that behavior?

    • Oliver G.
      Oliver G. over 7 years
      echo $TERM xterm
    • Arkadiusz Drabczyk
      Arkadiusz Drabczyk over 7 years
      show output of stty -a executed inside minicom
    • Arkadiusz Drabczyk
      Arkadiusz Drabczyk over 7 years
      Does running minicom with -w help?
    • Oliver G.
      Oliver G. over 7 years
      If I use putty instead of minicom as serial terminal program and enable the terminal setting "implicit LF in every CR" the behavior is gone.
    • Oliver G.
      Oliver G. over 7 years
      Start minicom CTRL-A then press Z In the menu: Add a linefeed: A so press A
    • stigskov
      stigskov about 6 years
      Maybe 'B' option is what you need (scroll Back)? CTRL A Z B
  • dirkt
    dirkt over 7 years
    I'd still be curious why it wraps around on the same line, instead of into the next line.
  • TheMeaningfulEngineer
    TheMeaningfulEngineer over 5 years
    This seems to have worked for me but am not clear how this was done or how to apply it as a general rule.
  • Mark Inderhees
    Mark Inderhees over 5 years
    Add this to your .bashrc on the target: "shopt -s checkwinsize" and "eval ` resize `"
  • mhck
    mhck over 2 years
    It can be run as one command for simplicity: shopt -s checkwinsize;resize