8

I am looking to implement a remote client in which connects to Linux through nc and starts bash. So I need to tell bash what features I can parse from the stdout that it sends to me, and how I am going to send keycodes and other stuff to its stdin, so that it could parse them too.

This is done with TERM=something environment variable, which I need to set to some value. If I don't set it, then various programs start to complain:

$ mc
The TERM environment variable is unset!

I found that I can set TERM to dumb to say that my client is really limited. And still it seems that I am missing something.

$ export TERM=dumb
$ mc
Your terminal lacks the ability to clear the screen or position the cursor.

From here it looks like dumb terminal don't have these two abilities, but what abilities it is still expected to have? Is there a specification or some de-facto standard about it?

3
  • 2
    dumb is literally that. it just spits out characters you send it and has no positioning capabilities other than carriage return and outputting spaces. there's no "cursor" to move around, therefore you can't print "complicated" interfaces in it, without basically printing out the entire screen every time something changes. and note that this isn't bash complaining, this is mc. it requires a proper terminal. try vt100 or something instead of dumb.
    – Marc B
    Aug 17, 2016 at 16:12
  • @MarcB, oh, I won't be able to implement vt100 for sure, I just want to check that my dumb implementation works as expected from dumb terminals. For example I noticed that my standard terminal on Linux doesn't automatically scroll when the character is printed on the last column of last line. Aug 17, 2016 at 16:16
  • It would (only) do that when printing an additional character to wrap to the next line. Aug 18, 2016 at 8:03

2 Answers 2

11

Going to the source can help. The terminal database has comments. Here is a slice from that:

#### Specials
#
# Special "terminals".  These are used to label tty lines when you don't
# know what kind of terminal is on it.  The characteristics of an unknown
# terminal are the lowest common denominator - they look about like a ti 700.
#

dumb|80-column dumb tty,
        am,
        cols#80,
        bel=^G, cr=^M, cud1=^J, ind=^J,
unknown|unknown terminal type,
        gn, use=dumb,

The "dumb" and "unknown" terminal types are assumed, but rarely used:

  • "dumb" has automargins (text "wraps" at the right margin), is assumed to have 80 columns, and an ASCII BEL and carriage return. For lack of something better, cud1 (cursor down) is an ASCII line-feed. The ind (index) value is the same, implying that text scrolls up when you reach the bottom of the screen.

    There is no cursor-addressing (cup) nor alternates (such as moving along a row or column arbitrarily).

  • "unknown" adds the "generic" flag, which marks it as unsuitable for use by curses applications. Think of it as a printer.

As for minimum requirements, that actually depends upon the individual application. ncurses can manage to move around the screen without actually having cup. It works with a half-dozen strategies. If you read the source for mvcur, you can get an idea of what it needs.

However, applications such as mc do not simply rely upon ncurses to decide if it works, since (in this case) it may link with slang (which doesn't check that closely). So mc does its own checks, which may add restrictions.

In practice, unless you choose a limited terminal description such as "dumb", most of the terminals you are likely to encounter will work.

Further reading:

2
  • So, ^G is byte 0x07 and means that my client should beep when it receives one? And ^M is 0x0D, which is \r, and ^Jis actually \n, so when remote sends 0x0D my client should get cursor back at the start of line. Aug 18, 2016 at 8:24
  • yes - but: the carriage return may be (normally is) translated by the terminal driver (not the terminal itself) into ^M^J. The terminal description only tells what the terminal can do. Aug 18, 2016 at 8:26
7

Your best source of information will be the terminfo entry, easily viewed with the infocmp tool:

infocmp dumb
#       Reconstructed via infocmp from file: /lib/terminfo/d/dumb
dumb|80-column dumb tty,
        am,
        cols#80,
        bel=^G, cr=^M, cud1=^J, ind=^J,

which makes it pretty clear that the dumb terminal is quite limited ...

4
  • Thanks. Now I need only to decipher that flags.. =) Aug 17, 2016 at 16:20
  • in man terminfo on modern linux there's a nice list of capabilities with some explanations, at least enough to decode what's going on.
    – fvu
    Aug 17, 2016 at 16:28
  • Still would be nice to get those explanations online. May 15, 2017 at 8:25
  • including -L doesn't work? Ex: $ infocmp -L dumb. May I ask, what flags are you talking about?
    – nate
    May 15, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.