Search code examples
telnetvt100

VT100 escape sequences: Cursor movement wrap around to end of line


I'm creating a Telnet CLI application that is controlled with VT100 escape sequences. So to e.g. navigate the cursor left the <ESC>[D escape sequence is sent from the Telnet server to the client, which may be Putty or Gnome-terminal. Unfortunately, with lines that are longer than the Putty line length, the escape sequence above will not permit navigating the cursor to the line above the current line.

An example. Cursor is '|'. Comments are marked with '//'

----------------
>potato| // Now I press left arrow which sends esc sequence to application
----------------
>potat|o // Works as expected. The cursor moved left
----------------

Another example

----------------
>potatopotatopot // This is a long command which goes over two lines
|ato             // Now I press left arrow which sends esc sequence to application
----------------
>potatopotatopot // The cursor didn't move, since the escape sequence 
|ato             // does nothing if the cursor is at the edge
----------------

I have been searching for any other escape sequence that would wrap around when at the edge, but found none. I have neither found any escape sequence that changes the terminal mode to something that allows wrapping.

So how is terminal navigation like this commonly handled?


Solution

  • The bw capability in a termcap terminal description says whether moving left at the edge of a screen wraps to the previous line. It was present in a PuTTy description I checked (infocmp putty under ncurses), but not in many others (e.g. not in infocmp gnome).

    You could try to keep track of which column the cursor is in and use movement control sequences when you want to wrap round to the previous line. You would have to know the width of the user's screen, which can be done by them setting the LINES and COLS environmental variables.