Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ターミナル出力の色付け / Terminal output coloring
Search
Yoichi NAKAYAMA
September 08, 2020
Programming
250
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ターミナル出力の色付け / Terminal output coloring
Yoichi NAKAYAMA
September 08, 2020
More Decks by Yoichi NAKAYAMA
See All by Yoichi NAKAYAMA
git-jumpを解放する / loosen editor dependency of git-jump
yoichi
0
1.5k
小さなOSS貢献の実践例 / A practical example of a small contribution to OSS
yoichi
0
190
パイプの話 / on pipe
yoichi
0
610
バイナリリーディング / Binary Reading
yoichi
0
450
OSS開発を楽しく続けてきた話
yoichi
0
940
Other Decks in Programming
See All in Programming
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
140
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
350
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5k
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
160
Family mrubyの進捗
kishima
1
130
Heart of Swift Concurrency
koher
0
960
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3.1k
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
5
4.4k
AWSに止められる覚悟してますか?
morizo_1984
0
140
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
320
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
500
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
190
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
580
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Optimizing for Happiness
mojombo
378
71k
What's in a price? How to price your products and services
michaelherold
247
13k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
710
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
260
GraphQLとの向き合い方2022年版
quramy
50
15k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
440
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
Speed Design
sergeychernyshev
33
2.1k
Embracing the Ebb and Flow
colly
88
5.2k
Transcript
ターミナル出力の色付け Yoichi Nakayama
ターミナル出力 プログラムが標準出力(stdout)や標準エラー出力(stderr)に書き込んだ内容はプログ ラムを実行したターミナル(terminal, 端末)上に出力される
ターミナル出力の例: ls ディレクトリ、実行権限が付いたファイルに色が付く
ターミナル出力の例: git diff ヘッダ、追加行、削除行に色が付く
ターミナル出力の例: git diff with delta シンタックスハイライト+行内の変更箇所にも色が付く https://github.com/dandavison/delta
ターミナル出力の例: emacs -nw モードに応じたシンタックスハイライト
色の付いた出力 普通に文字列を出力したときは単色だった プログラムによってはカラフルな出力がされていた →どうやったら色付けできるんだろう?
ls の出力を見てみる 出力をodにパイプしてバイナリダンプ 文字列と改行(0a)のみで特に変わったものは入ってない 改行?元々は一行の出力だったのに
感づかれてしまった パイプに気づいてlsは出力内容を変える→このままでは調べられない
回避 --color オプションを付けるとパイプしても色が付く→よさそう
色付き出力 色付き文字の手前に esc [ (CSI = Control Sequence Indicator)で始まる何か https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
試してみる • echo -e で \xNN をバイトの16進表現と解釈してくれる • \x1b =
esc • esc [ 30~37 m 文字色設定 • esc [ 0 m リセット
まとめ • CSI シーケンスを出力してターミナル出力を制御できる • esc [ 30~37 m で文字色を8色から選んで設定できた
• パイプを検出すると色付けをやめる理由:余計なものが付くから ◦ ls | grep ^dir1$ ターミナルの色付け完全に理解した!
色付けの例: emacs -nw M-x list-colors-display → 8色で終わりじゃない
256 colors • 0~7: standard colors (ESC [ 30~37 m
と同じ) • 8~15: high intensity colors (ESC [ 90~97 m と同じ) • 16~231: 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) • 232~255: grayscale
True Color (24bit) R(0~255), G(0~255), B(0~255) supported terminals: https://gist.github.com/XVilka/8346728#terminals--true-color
応用: longcat -pixterm ▄ (U+2584, LOWER HALF BLOCK) の文字色と背景色を指定している https://yoichi22.hatenablog.com/entry/2020/07/12/110838
おしまい ターミナル出力のさらなるトピック • DA1, DA2, DA3 • Sixel Graphics •
...