【问题标题】:Print out a terminfo entry including capname descriptions?打印一个 terminfo 条目,包括 capname 描述?
【发布时间】:2018-12-20 06:20:35
【问题描述】:

打印出包含 terminfo 手册页中每个 capname 的简短描述的 terminfo 条目(例如,对于我当前的终端:xterm-256color)最直接的方法是什么?

我知道如何打印终端的 terminfo 条目(每行一个名称):

infocmp -1

生成:

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

Etc.

我可以在 terminfo 手册页中手动查找每个 capname 的描述(例如,ccc 表示“终端可以重新定义现有颜色”),但是有没有一种方法可以显示每个 capname 的描述而无需查看每个手动一个?

因此,例如,我希望看到这样的内容:

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.

infocmp 的输出是一致的,并且相对容易解析,但在 terminfo 手册页上列出终端功能的表格,具有不同的列宽和跨越多行的 capname 描述,则不是。如果是这样,生成我描述的输出会更直接。或许 terminfo 手册页中的内容还有其他来源,它以编程方式更容易操作?

我正在运行 GNU bash,版本 4.4.23(1)-release (x86_64-apple-darwin18.0.0)。

【问题讨论】:

    标签: terminal terminfo


    【解决方案1】:

    可能不会。实际上,manual page 和其他文件是使用来自data filescripts 构建的,但这不是安装

    生成后,您可以编写一个脚本来提取信息,尽管您会发现将其作为 bash 脚本执行此操作具有挑战性(perl yes, awk yes, sed. ..也许)。这是文本的一小部分(安装在您的系统上):

    .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     
    

    您始终可以使用 infocmp 列出 long 名称,并且如果顺序与(默认)short 相同名字,你可以把它们结合起来。但是长名称的列表是按字母顺序排序的(按布尔值、数字和字符串分组,就像短名称一样),而短名称默认排序以匹配 SVr4 terminfo 数据。您可能会看到如下内容:

    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
    

    实际上 ncurses 有一个选项允许对名称进行排序,因此您可以(几乎)使用 -sl 选项匹配右列的顺序。您可能会看到如下内容:

    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
    

    那是“几乎”,因为列没有将 xenleat_newline_glitch 对齐,因为 ncurses 有一个内部名称backspaces_with_bs 通常不显示。更改 ncurses 源以显示:

    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
    

    这是我用来生成示例的 perl 脚本:

    #!/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;
    

    我提到的小修复在 ncurses 6.2 中(请参阅 changes),因此这对大多数用户“应该有效”。

    【讨论】:

      猜你喜欢
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多