# tmux スタイル仕様まとめ(文字色 fg と背景色 bg) 出典(一次情報): tmux 公式 man page `tmux.1` の **STYLES** セクション (`raw.githubusercontent.com/tmux/tmux/master/tmux.1`)。 本書は cc-tmux(`cc-tmux/tmux/cc-tmux.tmux`)の色指定が「文字色(前景)」を正しく扱っているかを 確認・記録するためのまとめ。 --- ## 1. スタイルとは / 埋め込みスタイル `#[...]` > *tmux offers various options to specify the colour and attributes of aspects of the interface ... > In addition, embedded styles may be specified in format options, such as `status-left`, > by enclosing them in `#[` and `]`.* - `status-style` のような**オプション**で UI 各部の色・属性を指定する。 - フォーマット文字列(`window-status-format` 等)の中では `#[ ... ]` で**埋め込みスタイル**を書ける。 - スタイルは `default` 単独、またはスペース/カンマ区切りの項目リスト。 ## 2. スタイル項目(STYLES セクション逐語の要点) | 項目 | 意味 | 備考 | |------|------|------| | **`fg=colour`** | **Set the foreground colour.(前景色=文字の色)** | ★「文字を赤」はこれ | | **`bg=colour`** | **Set the background colour.(背景色)** | セル背景。文字色ではない | | `us=colour` | 下線の色 | | | `none` | 全属性オフ | | | 属性 | `bright`(=`bold`), `dim`, `underscore`, `blink`, `reverse`, `hidden`, `italics`, `overline`, `strikethrough`, `double-underscore`, `curly/dotted/dashed-underscore`, `acs` | 各属性は `no` 接頭辞で解除(例 `noreverse`) | | `align=left|centre|right` | 整列 | | | `fill=colour` | 余白を背景色で塗る | | | `dim=percentage` | 前景・背景を暗くする | | | `width=N` | 幅指定 | | | `list=...` | ウィンドウ一覧の位置マーカー | `status-format` 用 | | `noattr` / `noattr` | 既定スタイルから属性を引き継がない | | | `push-default` / `pop-default` | 「既定」を一時保存/復元 | §4 の挙動の鍵 | | `range=...` / `norange` | マウスイベント範囲 | | ### 色の形式(`fg=` / `bg=` に使える値) > *The colour is one of: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`; > if supported the bright variants `brightblack`, `brightred`, ...; `colour0` to `colour255` > from the 256-colour set; `default` for the default colour; `terminal` for the terminal default > colour; or a hexadecimal RGB string such as `#ffffff`.* - 名前: `black red green yellow blue magenta cyan white` + `brightX` - 256 色: `colour0`〜`colour255` - `default`(オプション既定)/ `terminal`(端末既定)/ `#ffffff`(RGB 16 進) ### 結論(fg と bg) - **`fg` = foreground = 文字(前景)の色。** 「busy のとき文字を赤」は **`fg=red`** が正しい。 - `bg` = background = セル背景の色。文字色を変えたいなら `bg` は使わない。 --- ## 3. window-status 系オプションの関係 | オプション | 役割 | |------------|------| | `window-status-format` | 非アクティブなウィンドウのタブ**文字列**フォーマット | | `window-status-current-format` | アクティブ(現在)ウィンドウのタブ文字列フォーマット | | `window-status-style` | 非アクティブタブの**ベーススタイル**(色・属性) | | `window-status-current-style` | アクティブタブのベーススタイル | `status-format[0]`(tmux 内部の既定)が各タブを描画する際、 **ベーススタイル(`window-status-current-style` 等)を `push-default` で適用してから**、 `window-status-current-format` の中身(`#[...]` 含む)を描画し、`pop-default` で戻す。 → つまり「ベーススタイルの上に、フォーマット内 `#[...]` の指定が上書き」される。 `#[fg=red]` は前景だけを赤に変え、**背景はベーススタイルのまま**残る。 --- ## 4. cc-tmux の実装は「文字色(前景)」を正しく使っているか `cc-tmux/tmux/cc-tmux.tmux`: ```tmux set -g window-status-format "...#{?#{==:#{@cc_state},busy},#[fg=brightred],}#I:#W#[default]" set -g window-status-current-format "...#{?#{==:#{@cc_state},busy},#[fg=brightred bold],}#I:#W#[default]" ``` - 使っているのは **`fg=brightred`(前景=文字色)only**。`bg=` は**一切使っていない** (format 行に `bg=` 0 件)。 - よって busy 時は**タブ文字が明るい赤**になる。仕様どおりで正しい(文字色を赤にしている)。 - `brightred` を選ぶ理由: アクティブタブはテーマの `window-status-current-style` で背景色が付くことがあり (例: 緑)、通常 `red` より明るい `brightred` の方がその上で視認しやすいため。背景は変更しない。 ## 5. 「アクティブタブの背景が色付いて見える」原因(テーマ由来) 実環境(このマシン)の設定例: ``` window-status-style = fg=#888888,bg=default # 非アクティブ: 灰文字 / 既定背景 window-status-current-style = fg=#1a1a1a,bg=#33cc33,bold # アクティブ: 濃い文字 / 緑背景 ★ status-style = fg=#888888,bg=#1a1a1a ``` - **アクティブタブの緑背景 `bg=#33cc33` は、ユーザーのテーマ(`window-status-current-style`)由来**で、 cc-tmux は関与していない。 - busy 時のアクティブタブ = 「緑背景(テーマ)+ 赤文字(cc-tmux の `fg=red`)」になる。 緑背景が目立つため「背景が変/色を間違えた?」と見えることがあるが、**赤くしているのは文字(前景)**で正しい。 - 非アクティブタブ(`bg=default`)では busy 時に「暗い背景+赤文字」となり、赤文字がはっきり見える。 確認コマンド: ```sh tmux show-options -gv window-status-current-style # アクティブタブのベース色(bg がテーマ由来か確認) tmux show-options -gv window-status-format # cc-tmux が fg=red のみ使うことを確認 ``` ## 6. 見え方を変えたい場合の選択肢(任意・要望次第) 要望は「**文字色**を赤」なので前景のみを変更する(背景は触らない)。 **現状の実装は `fg=brightred`(明るい赤の文字)を採用**。アクティブタブのテーマ背景色(緑など)の上でも 通常 `red` より見やすい。さらに調整したい場合の案(採用は任意): 1. **現状(推奨・仕様どおり)**: `fg=brightred` の文字のみ。背景はテーマのまま。 2. もっと地味で良いなら `fg=red` に戻す(前景のみ)。 3. テーマ側 `window-status-current-style` の `bg` を控えめにする(ユーザーのテーマ設定の調整)。 4. (非推奨・要望と異なる)背景を赤にしたい場合は `#[bg=red]` だが、これは「文字色」ではなく背景色になる。 > まとめ: **「文字を赤」=`fg`(前景)**。cc-tmux は `fg=red` のみで実装しており、文字色を赤にしている。 > 背景は一切変更していない。アクティブタブの色味はテーマの `window-status-current-style` による。