Chris
Chris

Reputation: 6732

How does less take over to the console?

I want to take over the console like less does, to make a more interactive app. It seems like they have complete control over what gets drawn where. How can I do that?

Upvotes: 1

Views: 206

Answers (4)

LeoNerd
LeoNerd

Reputation: 8532

Primarily, less and other full-screen terminal applications use the alternate screen mode; otherwise known as DEC mode 1049. terminfo stores the strings needed to enter/exit this mode in

enter_ca_mode=\E[?1049h
exit_ca_mode=\E[?1049l

Once you enter alternate screen mode, you get full control of the screen by the usual escape sequences, drawing to an entirely separate "buffer" on most terminals, that leaves the regular buffer (such as may contain the bash scrollback) unaffected. When you leave alternate screen mode again it restores the previous contents and cursor state.

Upvotes: 1

Null Set
Null Set

Reputation: 5414

The ANSI escape codes might be a place to start. http://en.wikipedia.org/wiki/ANSI_escape_code

Upvotes: 0

ismail
ismail

Reputation: 47602

It uses the ncurses library for handling the terminal.

Upvotes: 5

Phil Willoughby
Phil Willoughby

Reputation: 1734

Look up 'curses' in your system's documentation.

Upvotes: 0

Related Questions