-2

Is there a way to match terminal/console features with entries in terminfo database?

For example, to find a closest match to Windows console or other type of non-traditional terminal.

There are no online services, so I expect that the problem is non-trivial and it is interesting to know why.

UPDATE: Terminfo database gives a set of features for a known terminal type or name. I am trying to do the reverse task - match features of unknown terminal against existing terminfo entries.

UPDATE2: How it should work...

  1. I select my terminal capabilities from a long list
  2. Matcher finds profiles that are either
    • 2.1. implement all those capabilities exactly with no other capabilities
    • 2.2. implement almost all capabilities exactly with no other capabilities
    • 2.3. implement capabilities exactly with some other capabilities
    • 2.4. implement almost all capabilities and adds some other capabilities
anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140

3 Answers3

1

Thanks for your question. Try this, with ncurses package installed:

infocmp | grep _Cap_name_

or

infocmp _terminfo_name_ | grep _Cap_name_

and

infocmp [-d|-c|-n] _wanted_ _have_

infocmp compares the contents of two terminfo terminals, or displays the terminfo entry (binary) as termcap (human readable text)

On my system terminfo(s) are here:

/usr/share/terminfo
/lib/terminfo

I reference _Cap_name_ here at opengroup.org

Because you are on Windows (probably without Cygwin) you may have to manually check the capabilities of the TERMs you expect, and build in workarounds based on that pre-knowledge, but its Windows, so there can't be that many.

TERMINFO=/user/share/terminfo toe

This gets you a list of terminals. If you have control over the server, add a terminfo file yourself, write it as text in either termcap format then convert it or in terminfo info format and then compile it. That way you can start with dummy+linewrap. Or try ansi+idl.

NOTE: I agree with the other comment about using a VT100/VT102 library.

Paul Wratt
  • 51
  • 5
1

According to your revised OP, again using ncurses library, C you can query the terminal using tget. I am not aware of a way to iterate the capabilities without knowing what they might be before making a call to tget, however I know that it will return 0 for capabilities that return integer values and are not found, eg. cMax = tget("max_colors");.

According to terminfo, when compiling a terminal info configuration, it is possible to provide, (1st) over-rides, (2nd) included terminals, optionally (3rd) excluding included terminals with certain capabilities. This however still requires write access to the target server terminfo database directory, so your resulting terminfo file can be uploaded.

The terminfo database provides both a way for servers to provide a terminal, AND for programs (including remote ones) to interpret a provided terminal.

Paul Wratt
  • 51
  • 5
  • Does `tget` run actual tests to find features? – anatoly techtonik Sep 23 '17 at 09:23
  • Not a test of the capability, just the result of the terminal output. Not sure if it checks the terminfo db reference or just directly to the terminal. Both should return 0 if not set, but the terminal might reply "capability not supported". You will have to read the terminfo programming documentation to know for sure. – Paul Wratt Sep 24 '17 at 14:58
  • I have some code, and `MaxColors` or `colors` can return `0` according to that code. – Paul Wratt Sep 24 '17 at 15:00
0

So far the answer is http://man7.org/linux/man-pages/man5/terminfo.5.html so I will post better results when I get more time.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140