duangu1868
duangu1868
2016-08-17 16:09
浏览 180

TERM =哑终端必须具备的功能

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?

图片转代码服务由CSDN问答提供 功能建议

我希望在 golang ,它通过 nc 连接到Linux并启动 bash 。 所以我需要告诉 bash 我可以从它发送给我的 stdout 解析哪些功能,以及如何将键码和其他内容发送到它的 stdin ,以便它也可以解析它们。

这是通过 TERM = something 环境变量完成的,我需要将其设置为某个值 。 如果我没有设置它,那么各种程序都会开始抱怨:

  $ mc 
未设置TERM环境变量!
   \  n 
 

我发现我可以将TERM设置为 dumb ,以表示我的客户确实受到限制。 仍然似乎我丢失了一些东西。

  $ export TERM = dumb 
 $ mc 
您的终端无法清除屏幕或定位光标。
    
 
 

从这里开始,看来 dumb 终端没有这两项功能,但是仍然希望拥有哪些功能? 是否有规范或事实上的标准?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dssqq82402
    dssqq82402 2016-08-17 20:18
    已采纳

    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:

    点赞 评论
  • dptdb84606
    dptdb84606 2016-08-17 16:18

    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 ...

    点赞 评论

相关推荐