Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to manipulate the terminal you have to use <em>control sequences</em>. Unfortunately, those codes depend on the particular terminal you are using. That's why <code>terminfo</code> (previously <code>termcap</code>) exists in the first place.</p> <p>You don't say if you want to use terminfo or not. So:</p> <ul> <li>If you will use terminfo, it will give you the correct control sequence for each action your terminal supports.</li> <li>If you won't use terminfo... well, you have to manually code every action in every terminal type you want to support.</li> </ul> <p>As you want this for learning purposes, I'll elaborate in the second.</p> <p>You can discover the terminal type you are using from the environment variable <code>$TERM</code>. In linux the most usual are <code>xterm</code> for terminal emulators (XTerm, gnome-terminal, konsole), and <code>linux</code> for virtual terminals (those when X is not running).</p> <p>You can discover the control sequences easily with command <code>tput</code>. But as <code>tput</code> prints them on the console, they will apply immediately, so if you want to really see them, use:</p> <pre><code>$ TERM=xterm tput clear | hd 00000000 1b 5b 48 1b 5b 32 4a |.[H.[2J| $ TERM=linux tput clear | hd 00000000 1b 5b 48 1b 5b 4a |.[H.[J| </code></pre> <p>That is, to clear the screen in a <code>xterm</code> you have to output <code>ESC [ H ESC [ 2J</code> in an xterm but <code>ESC [ H ESC [ J</code> in a linux terminal.</p> <p>About the particular commands you ask about, you should read carefully <code>man 5 terminfo</code>. There is a lot of information there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload