
実行環境
• Windows7 x64
• ConEmu 150813g + CMD.exe(普通のコマンドプロンプトのシェル)
• PostgreSQL 9.5.3(Windowsネイティブ。psqlも一緒)
エスケープシーケンスによる文字色変更のテスト
2# \t on \\ \pset format unaligned # select e'\x1b[38;2;255;0;0m' || repeat('■', 32) || e'\n' || e'\x1b[38;2;0;255;0m' || repeat('▲', 32) || e'\n' || e'\x1b[38;2;0;0;255m' || repeat('●', 32) || e'\n' || e'\x1b[38;2;255;255;255m';

最初にメタコマンド
上の画像は、ConEmu


RGB の HEX 形式をエスケープシーケンスに変えるテスト
最初から# \t on \\ \pset format unaligned # select concat(e'\x1b[38;2;', concat('x', ary[1]) :: bit(8) :: int, ';', concat('x', ary[2]) :: bit(8) :: int, ';', concat('x', ary[3]) :: bit(8) :: int, 'm■', e'\x1b[38;2;255;255;255m') from ( values ('fabfab')-- input HEX color as you want ) as foo (rgb), regexp_matches(rgb, '(.{2})(.{2})(.{2})') as ary;

最終形、いろんなカラー設定での結果
昨日、抽出したビットマップを# with lines (nrow, hex, tr) as ( select nrow, regexp_split_to_table(pixel_lines, ''), regexp_split_to_table(trans_lines, '') from icon_pixels natural join icon_trans ) select *, row_number() over(partition by nrow) as ncol from lines natural join icon_colors; +-----+------+----+--------+------+ | hex | nrow | tr | rgb | ncol | +-----+------+----+--------+------+ | 0 | 1 | 1 | 000000 | 1 | | 0 | 1 | 1 | 000000 | 2 | | 0 | 1 | 1 | 000000 | 3 | | 0 | 1 | 1 | 000000 | 4 | | 0 | 1 | 1 | 000000 | 5 | | 0 | 1 | 1 | 000000 | 6 | ... | 0 | 6 | 0 | 000000 | 27 | | 7 | 6 | 0 | c0c0c0 | 28 | | 7 | 6 | 0 | c0c0c0 | 29 | | 0 | 6 | 0 | 000000 | 30 | | 8 | 6 | 0 | 808080 | 31 | | 0 | 6 | 0 | 000000 | 32 | | 8 | 7 | 0 | 808080 | 1 | | 7 | 7 | 0 | c0c0c0 | 2 | | 4 | 7 | 0 | 000080 | 3 | | 4 | 7 | 0 | 000080 | 4 | ...
↓ というわけで最終形。途中で切れないようページャを
# \t on \\ \pset format unaligned \\ \pset pager off # with lines (nrow, hex, tr) as ( select nrow, regexp_split_to_table(pixel_lines, ''), regexp_split_to_table(trans_lines, '') :: int from icon_pixels natural join icon_trans order by nrow ), pixels (nrow, ncol, chr) as ( select nrow, row_number() over(partition by nrow), case tr when 0 then concat(e'\x1b[38;2;', concat('x', ary[1]) :: bit(8) :: int, ';', concat('x', ary[2]) :: bit(8) :: int, ';', concat('x', ary[3]) :: bit(8) :: int, 'm■' ) else '□' end, rgb from lines natural join icon_colors, regexp_matches(case rgb when '000000' then 'ffffff' when 'ffffff' then '000000' else rgb end, '(.{2})(.{2})(.{2})') as ary ) (select string_agg(chr, '' order by ncol) from pixels group by nrow order by nrow) union all select e'\x1b[38;2;255;255;255m';
↓ 実行した様子。クエリ結果(カラービットマップ)は冒頭の画像と同じです。

この先はおまけ。ConEmu
結果、プリセット先頭の

↓

↓

↓

↓

↓

↓

↓

↓

↓

↓
.png)
↓
.png)
↓

↓

↓

↓

↓

↓

↓

↓

↓

↓

↓

↓

↓
