0

What's the most straightforward way to print out a terminfo entry (e.g., for my current terminal: xterm-256color) that includes the short descriptions of each capname from the terminfo man page?

I know how to print out the terminfo entry for my terminal (with one capname per line) with:

infocmp -1

Generates:

#   Reconstructed via infocmp from file: /usr/share/terminfo/78/xterm-256color
xterm-256color|xterm with 256 colors,
    am,
    bce,
    ccc,
    km,
    mc5i

Etc.

And I can manually look up the descriptions of each capname in the terminfo man page (e.g., ccc represents "terminal can redefine existing colors"), but is there a way to display the descriptions for each capname without having to look each one up manually?

So, for example, I'd like to see something like this:

xterm-256color|xterm with 256 colors
am         terminal has automatic margins
bce        screen erased with background color
ccc        terminal can redefine existing colors
km         Has a meta key (i.e., sets 8th bit)
mc5i       printer will not echo on screen

Etc.

The output from infocmp is consistently delimited and relatively easy to parse, but the tables listing the terminal capabilities on the terminfo man page, with varying column widths and capname descriptions that span multiple lines, are not. If they were, generating the output I describe would be more straightforward. Perhaps there's an alternative source for the content from the terminfo man page that's programmatically easier to manipulate?

I'm running GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin18.0.0).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
jomoz
  • 19
  • 4

1 Answers1

0

Probably not. Actually, the manual page and other files are constructed using scripts from a data file, but that is not installed.

Since it is generated, you could write a script to extract the information, though you'd find it challenging to do this as a bash script (perl yes, awk yes, sed...maybe). Here is a small chunk of the text (which is installed on your system):

.TS H
center expand;
c l l c
c l l c
lw25 lw6 lw2 lw20.
\fBVariable     Cap-    TCap    Description\fR
\fBBooleans     name    Code\fR
auto_left_margin        bw      bw      T{
cub1 wraps from column 0 to last column
T}
auto_right_margin       am      am      T{
terminal has automatic margins
T}
back_color_erase        bce     ut      T{
screen erased with background color
T}
can_change      ccc     cc     

You can always list the long names using infocmp, and if the order were the same as for the (default) short names, you could combine those. But the listing for long-names is sorted alphabetically (in groups for boolean, numbers and strings, like the short names), while the short names are ordered by default to match the SVr4 terminfo data. You might see something like this:

xterm-256color|xterm with 256 colors
        am      auto_right_margin
        bce     back_color_erase
        ccc     backspaces_with_bs
        km      can_change
        mc5i    eat_newline_glitch
        mir     has_meta_key
        msgr    move_insert_mode
        npc     move_standout_mode
        xenl    no_pad_char
        colors  prtr_silent
        cols    columns 
        it      init_tabs 
        lines   lines
        pairs   max_colors
        acsc    max_pairs
        bel     acs_chars  
        blink   back_tab
        bold    bell

Actually ncurses has an option allowing the names to be sorted, so that you could (almost) match the order of the right-column using the -sl option. You might see something like this:

xterm-256color|xterm with 256 colors
        am      auto_right_margin
        bce     back_color_erase
        ccc     backspaces_with_bs
        xenl    can_change
        km      eat_newline_glitch
        mir     has_meta_key
        msgr    move_insert_mode
        npc     move_standout_mode
        mc5i    no_pad_char
        cols    prtr_silent
        it      columns
        lines   init_tabs
        colors  lines
        pairs   max_colors
        acsc    max_pairs
        cbt     acs_chars
        bel     back_tab
        cr      bell

That's "almost", because the columns do not line up xenl with eat_newline_glitch because ncurses has an internal name for backspaces_with_bs which normally is not shown. With a change to the ncurses source to show that:

xterm-256color|xterm with 256 colors
        am      auto_right_margin
        bce     back_color_erase
        OTbs    backspaces_with_bs
        ccc     can_change 
        xenl    eat_newline_glitch

Here's the perl script which I used to generate the examples:

#!/usr/bin/env perl
# $Id: infocmp2col,v 1.1 2018/12/20 22:35:57 tom Exp $

use strict;
use warnings;

sub infocmp($$) {
    my $term = shift;
    my $opts = shift;
    my @data;
    if ( open FP, "infocmp -1 $opts $term |" ) {
        @data = <FP>;
        close FP;
        for my $n ( 0 .. $#data ) {
            chomp $data[$n];
            $data[$n] =~ s/,\s*$//;
            $data[$n] =~ s/[#=].*//;
        }
    }
    return \@data;
}

sub doit($) {
    my $term       = shift;
    my @short_term = @{ &infocmp( $term, "-sl" ) };
    my @long_term  = @{ &infocmp( $term, "-L" ) };
    for my $n ( 0 .. $#short_term ) {
        if ( $short_term[$n] =~ /^\s/ ) {
            printf "%s%s\n", $short_term[$n], $long_term[$n];
        }
        else {
            printf "%s\n", $short_term[$n];
        }
    }
}

if ( $#ARGV >= 0 ) {
    while ( $#ARGV >= 0 ) {
        &doit( pop @ARGV );
    }
}
else {
    &doit( $ENV{TERM} );
}

1;

The minor fix that I mentioned is in ncurses 6.2 (see changes), so this "should work" for most users.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105