Charles Lohr
Charles Lohr

Reputation: 919

Ncurses output of 'sl' changes if running on a terminal verses from a log?

I'm writing a terminal, and was trying to use steam locomotive as a test bed, and ran into an unusual problem. Even in a regular terminal like xterm or mate-terminal, the output is different if you run the application, i.e. sl verses if you log it to a file i.e. sl > sl.txt then cat it cat sl.txt

This is particularly pronounced on sl-h where in the first few seconds, codes are output which would make the X/O for the railroad crossing which if catted show incorrectly putting the X/O at the beginning of the line.

bad truncated output from SL

It seems that there is an ioctl that's happening that somehow changes newline behavior to advance to the next line, but not return back to the beginning. I.e. strace sl-h 2> sllog.txt shows: ioctl(1, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig -icanon echo ...}) = 0

How would you be able to detect this as a terminal? What systems are in place? Why wouldn't ncurses just use escape sequences to convey this information? There's a lot of questions that I'm not sure how to handle in my terminal.

Upvotes: 0

Views: 70

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54475

ncurses (like Unix curses) puts the terminal into raw mode for two reasons:

  • ability to read single characters (and ignore signals such as quit that might be bound to them), and
  • ability to manage the output, including movement around the screen with fewer characters than a simple printf.

In raw mode, the Unix-style conversion of line-feed to carriage-return and line-feed is disabled. That lets ncurses move directly down by one row (in the same column) with a single characters. Cursor addressing would typically use 6 or more characters. Even a cursor-down would use 3 characters.

Incidentally, that treatment of line-feed is the reason why the terminal descriptions often have the cursor-down capability assigned to a line-feed.

Upvotes: 1

Related Questions