This page was last modified: July 27 2006 16:21:06   
Too Cool for Internet Explorer

Terminal emulation

The first time I stumbled over the expression "Terminal emulator" was when I configured Vim. I couldn't get syntax highlighting to work, and it turned out that the solution was to change the terminal emulator to "vt100".

But it is never enough for me just to know how things are done... I also want to know why they are done and how they work. So I asked these questions:

  • What exactly is a terminal emulator?
  • What does it do?
  • What difference does it make which one I use?
  • How to I tell my server which terminal emulator to use?

What exactly is a terminal emulator?

The definition of a terminal emulator is related to old style computing, where the big computer was in a room somewhere and everyone used "dumb terminals" to access it. A dumb terminal was basically a screen and a keyboard.

So a terminal emulator is basically a program that runs on your computer and emulates the behavior of a dumb terminal, or perhaps several varieties of terminals.

What does it do?

The terminals used in the old days operated by some electronics that "spoke" a particular language for controlling them. Each terminal manufacturer - in fact, each model of terminal - had its own language. Some terminals were smarter than others, with screens that could do all sorts of things. The smartest terminal of all in those days was DEC's VT100, whose language came to be something of a standard.

So when you use your PC to connect to your server and interact with it, the "language" they speak to each other depends on which emulator is used.

The language dictates what groups of characters will...

  • ...come from which keys on the keyboard and keypad to indicate which key had been pressed
  • ...control which screen functions (cursor placement, font, color, highlighting, etc.) -- called control sequences

What difference does it make which one I use?

The instructions that you give the server via the PC can only work if they are written in a "language" that both your PC and server can understand. Because the terminal emulator is making your PC act like a terminal that is under the control of the server, that language is called your terminal type, or terminal emulation.

Say your PC tells the server to speak "vt100". Then, the server will send you vt100 control sequences. If your PC does speak vt100, things will happen properly on your screen. If your PC doesn't, you won't know what are regular text characters and what are control sequences, so you will end up seeing them all on the screen, as if they were text, resulting in pure and utter garbage.

In my case the terminal type was set to "xterm" and since it obviously does not understand color, my settings for syntax highlighting in Vim, didn't work. I only got black and white, bold text and underline. Changing it to vt100 which understands color, fixed the problem.

How do I tell my server which terminal emulator to use?

Just open the shell profile that belongs to the user. If you want to change the terminal for user bill, just go to bill's homedirectory and open his shell profile. Since I use bash I open .profile and change the terminal.:

cd /usr/home/bill
vim .profile

The file may look like this.:

1 # $FreeBSD: src/share/skel/dot.profile,v 1.19.2.2 2002/07/13 16:29:10 mp Exp $
2 #
3 # .profile - Bourne Shell startup script for login shells
4 # 5 # see also sh(1), environ(7).
6 #
7
8 # remove /usr/games and /usr/X11R6/bin if you want
9 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:
/usr/local/bin:/usr/X11R6/bin:$HOME /bin; export PATH
10
11 # Setting TERM is normally done through /etc/ttys. Do only override
12 # if you're sure that you'll never log in via telnet or xterm or a
13 # serial line.
14 # Use cons25l1 for iso-* fonts
15 # TERM=cons25; export TERM
16 TERM=vt100;   export TERM
17 BLOCKSIZE=K;  export BLOCKSIZE
18 EDITOR=vim;   export EDITOR
19 PAGER=more;   export PAGER
20
21 # set ENV to a file invoked each time sh is started for interactive use.
22 ENV=$HOME/.shrc; export ENV
23 24 [ -x /usr/games/fortune ] && /usr/games/fortune freebsd-tips

Note the bolded text in the above. This is the line where the terminal emulator is set. In this example it is set to vt100.