2017-03-11 11 views
2

私はterminfoデータベースを使用して色を印刷しようとしており、各端末に存在する端末データベースファイルを正常に解析しました。私の場合は、間違いなく色をサポートするgnome端末を持っています。 terminfoを使用して端末で色を設定する方法

set_foreground 
set_background 
set_a_foreground 
set_a_background 

私は前景色を設定したいので

が、私はそれがANSIの配列との互換性があると言う set_a_foregroundを選んだ -

は、今のようなterminfoのデータベース内にいくつかのコマンドがあります。しかし、私は実際にそれらのいずれかで色を印刷する方法はまだ分かりません。

両方とも、このようなことを言う - Set foreground color #1説明にあり、実際の文字列は端末で - ESC[3%p1%dmのようになります。

私の質問は、set_a_またはset_バージョンを使用する必要があります。どのように色を印刷するかです。

答えて

1

set_foregroundset_a_foregroundの区別(およびバックグラウンド機能)はColor Handling sectionterminfo(5)マニュアルページにあります。長い名前が頻繁に使用されていることを覚えておいてください、あなたはsetfsetaf対を探しているべきであること:ただのterminfo(やない呪い)を使用して

The setaf/setab and setf/setb capabilities take a single 
    numeric argument each. Argument values 0-7 of setaf/setab 
    are portably defined as follows (the middle column is the 
    symboliC#define available in the header for the curses or 
    ncurses libraries). The terminal hardware is free to map 
    these as it likes, but the RGB values indicate normal 
    locations in color space. 

     Color  #define  Value  RGB 
     black  COLOR_BLACK  0  0, 0, 0 
     red  COLOR_RED   1  max,0,0 
     green  COLOR_GREEN  2  0,max,0 
     yellow COLOR_YELLOW  3  max,max,0 
     blue  COLOR_BLUE  4  0,0,max 
     magenta COLOR_MAGENTA  5  max,0,max 
     cyan  COLOR_CYAN  6  0,max,max 
     white  COLOR_WHITE  7  max,max,max 

    The argument values of setf/setb historically correspond 
    to a different mapping, i.e., 

     Color  #define  Value  RGB 
     black  COLOR_BLACK  0  0, 0, 0 
     blue  COLOR_BLUE  1  0,0,max 
     green  COLOR_GREEN  2  0,max,0 
     cyan  COLOR_CYAN  3  0,max,max 
     red  COLOR_RED   4  max,0,0 
     magenta COLOR_MAGENTA  5  max,0,max 
     yellow COLOR_YELLOW  6  max,max,0 
     white  COLOR_WHITE  7  max,max,max 

    It is important to not confuse the two sets of color capa- 
    bilities; otherwise red/blue will be interchanged on the 
    display. 

ほとんどのアプリケーションで置き換えて、文字列をフォーマットするtparm機能を使用(数値)パラメーターを使用して、結果の文字列にtputsを使用して実際に書き込みます。 2つはパディングと遅延を考慮しています(一般にの色の機能にはありませんが、一般的にはterminfoにあります)。

ncurses-examplesプログラムdotsは、これらの機能を使用して、色付きのセルを画面上にランダムに描画します。 (この例では、tparm2tparm3は、tparmプロトタイプが必要とする余分なパラメータを提供するマクロです)。

-2

まあまず、あなたはそれらの定義を使用して、すべての異なる端末の色の間のあなたの解析された情報とスイッチを使用するスイッチでそれらを使用するとdefine header file like I've done on my printf project

のいくつかの種類を行う必要があります:)

関連する問題