Skip to content

tmux DCS passthrough 対応#22

Closed
flexphere wants to merge 3 commits into
mainfrom
feat/tmux-passthrough
Closed

tmux DCS passthrough 対応#22
flexphere wants to merge 3 commits into
mainfrom
feat/tmux-passthrough

Conversation

@flexphere

Copy link
Copy Markdown
Owner

概要

tmux 環境で Kitty Graphics Protocol の画像が表示されない問題を修正。すべての Kitty APC シーケンスを tmux DCS passthrough (\x1bPtmux;...\x1b\\) でラップし、外側のターミナル(WezTerm/Kitty/Ghostty等)に直接転送することで画像表示を実現する。

変更内容

  • KittyRenderer に Option パターン (WithTmuxMode) を導入
  • wrapDCSPassthrough 関数で ESC 文字を二重化し DCS passthrough 形式にラップ
  • buildUploadSequence / buildRGBAUploadSequence をメソッド化し、各チャンクを個別にラップ
  • Display, Clear, UploadMinimap, DisplayMinimap, ClearMinimap の全 APC 出力箇所でラッピングを適用
  • カーソル移動 (\x1b[H) は CSI シーケンスのため tmux が処理し、DCS で包まない
  • cmd/gaze/main.go$TMUX 環境変数を検出し自動的に tmux モードを有効化
  • README.md に tmux の設定手順 (set -g allow-passthrough on) を追記

テスト計画

  • 既存テスト全パス (make ci)
  • 新規テスト追加: internal/adapter/renderer/kitty_renderer_test.go
    • TestWrapDCSPassthrough: ESC 二重化と DCS フォーマットの検証
    • TestKittyRenderer_TmuxMode_Display: placement APC のラッピング
    • TestKittyRenderer_TmuxMode_DisplayMinimap: upload + placement の複数ラッピング
    • TestKittyRenderer_TmuxMode_DisplayMinimap_CacheHit: キャッシュヒット時もラッピング
    • TestKittyRenderer_TmuxMode_BuildRGBAUploadSequence: チャンク単位のラッピング
  • 手動確認: tmux + WezTerm 環境で gaze <image> を実行し画像が表示されることを確認

備考

  • tmuxMode=false(デフォルト)時は従来と完全同一動作のため、既存ユーザーに影響なし
  • RendererPort インターフェースの変更なし(内部実装のみ)
  • ネストされた tmux(tmux in tmux)は単一レベルのみ対応

🤖 Generated with Claude Code

flexphere and others added 3 commits March 25, 2026 14:41
Wrap all Kitty APC sequences in tmux DCS passthrough (\x1bPtmux;...\x1b\\)
when running inside tmux. This allows the outer terminal to receive and
render Kitty graphics directly as overlays, bypassing tmux's cell buffer.

- Add Option pattern with WithTmuxMode to KittyRenderer
- Add wrapDCSPassthrough function that doubles ESC chars for DCS encoding
- Convert buildUploadSequence/buildRGBAUploadSequence to methods for
  per-chunk wrapping
- Auto-detect tmux via TMUX environment variable in main.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add TestWrapDCSPassthrough for ESC doubling and DCS format
- Add TestKittyRenderer_TmuxMode_Display for wrapped placement output
- Add TestKittyRenderer_TmuxMode_DisplayMinimap for upload+placement wrapping
- Add TestKittyRenderer_TmuxMode_DisplayMinimap_CacheHit for cached placement
- Add TestKittyRenderer_TmuxMode_BuildRGBAUploadSequence for chunk wrapping
- Update existing buildRGBAUploadSequence tests for method syntax

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 05:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

tmux 環境下で Kitty Graphics Protocol の画像が表示できない問題に対し、Kitty の APC シーケンスを tmux の DCS passthrough でラップして外側ターミナルへ透過させることで表示を可能にする PR です。レンダラ側の出力生成に tmux 対応を組み込み、CLI 側で tmux 環境を自動検出して有効化します。

Changes:

  • KittyRenderer に Option パターン(WithTmuxMode)を導入し、tmux モード時に Kitty シーケンスを DCS passthrough でラップ
  • 画像アップロード/配置/削除の各 APC 出力箇所にラッピングを適用し、アップロードはチャンク単位でラップ
  • $TMUX 検出による自動有効化と、README に tmux 設定手順を追記(加えて tmux 対応のテストを追加)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/adapter/renderer/kitty_renderer.go tmux DCS passthrough ラッピングと Option パターン導入、各 APC 出力のラップ適用
internal/adapter/renderer/kitty_renderer_test.go tmux ラップの単体テスト追加、RGBA upload シーケンス生成の呼び出しをメソッド化に追従
cmd/gaze/main.go $TMUX に応じて WithTmuxMode(true) を自動適用
README.md tmux での利用手順(allow-passthrough on)を追記

Comment on lines +558 to +559
// In wrapped form, \x1b_ becomes \x1b\x1b_ inside the DCS payload
if strings.Contains(output, "\x1b_G") && !strings.Contains(output, "\x1b\x1b_G") {

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestKittyRenderer_TmuxMode_BuildRGBAUploadSequence の「unwrapped APC が含まれない」検証が弱く、出力に wrapped と unwrapped が混在しても検知できません(wrapped 形式自体が "\x1b_G" 部分文字列を含むため)。"\x1bPtmux;" の回数と対応付けて各チャンクが必ず DCS で始まることを確認する、または "\x1b\x1b_G" を除去した残りに "\x1b_G" が現れないことを確認する等、混在を確実に落とせる形にしてください。

Suggested change
// In wrapped form, \x1b_ becomes \x1b\x1b_ inside the DCS payload
if strings.Contains(output, "\x1b_G") && !strings.Contains(output, "\x1b\x1b_G") {
// In wrapped form, \x1b_ becomes \x1b\x1b_ inside the DCS payload.
// wrapped 由来の \x1b\x1b_G をすべて除去した残りに \x1b_G が含まれていないことを検証することで、
// wrapped/unwrapped の混在も確実に検出する。
clean := strings.ReplaceAll(output, "\x1b\x1b_G", "")
if strings.Contains(clean, "\x1b_G") {

Copilot uses AI. Check for mistakes.
@flexphere flexphere closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants