SPB Git

Repository Public

InspectorView.swift 5.6 KB 100 lines swift

1import SwiftUI2import TerminalCore3import WorkspaceCore45/// Right-hand inspector: facts about the focused session. Everything shown here is verified6/// from the process/PTY, never inferred from terminal text.7struct InspectorView: View {8    @Environment(WorkspaceController.self) private var controller9    let windowID: WindowID10    @State private var labelDraft = ""11    @State private var tab: InspectorTab = .session1213    enum InspectorTab: String, CaseIterable, Identifiable { case session = "Session", git = "Git", claude = "Claude"; var id: String { rawValue } }1415    var body: some View {16        let paneID = controller.focusedPane(in: windowID)17        let session = paneID.flatMap { controller.session(for: $0) }18        let isClaude: Bool = { if case .claude = session?.profile.kind { return true }; return false }()19        VStack(spacing: 0) {20            Picker("Inspector section", selection: $tab) {21                ForEach(InspectorTab.allCases.filter { $0 != .claude || isClaude }) { Text($0.rawValue).tag($0) }22            }23            .pickerStyle(.segmented).labelsHidden().padding(8)24            Divider()25            ScrollView {26                switch tab {27                case .git:28                    GitPanelView(windowID: windowID).padding(12).frame(maxWidth: .infinity, alignment: .leading)29                case .claude:30                    if let paneID, case .claude(let id, let resume) = session?.profile.kind {31                        ClaudeInspectorSection(paneID: paneID, claudeSessionID: id, resume: resume).padding(12).frame(maxWidth: .infinity, alignment: .leading)32                    } else {33                        Text("Not a Claude session").foregroundStyle(.secondary).padding()34                    }35                case .session:36                    sessionFacts(session: session, paneID: paneID)37                }38            }39        }40        .background(NXTokens.chromeBackground)41        .onChange(of: isClaude) { _, now in if !now, tab == .claude { tab = .session } }42        .onChange(of: controller.inspectorTab, initial: true) { _, name in if let t = InspectorTab(rawValue: name) { tab = t } }43        .onChange(of: tab) { _, t in if controller.inspectorTab != t.rawValue { controller.inspectorTab = t.rawValue } }44    }4546    @ViewBuilder47    private func sessionFacts(session: TerminalSession?, paneID: PaneID?) -> some View {48            VStack(alignment: .leading, spacing: 14) {49                if let session, let paneID {50                    LabeledContent("Label") {51                        TextField("Optional label", text: $labelDraft, onCommit: { controller.setLabel(labelDraft, for: paneID) })52                            .textFieldStyle(.roundedBorder)53                    }54                    .onAppear { labelDraft = session.label ?? "" }55                    .onChange(of: paneID) { _, _ in labelDraft = session.label ?? "" }56                    fact("Status", session.status.label)57                    let d = session.view.diagnostics58                    fact("Renderer", "bytes \(d.bytesFed) · batches \(d.batches) · frames \(d.frames) · renders \(d.renders) · loop \(d.renderLoopFrames)")59                    fact("View", "frame \(Int(session.view.frame.width))×\(Int(session.view.frame.height)) · window \(session.view.window == nil ? "none" : "yes") · hidden \(session.view.isHiddenOrHasHiddenAncestor) · superview \(session.view.superview == nil ? "none" : "yes") · outputs \(session.outputBatches)")60                    fact("Kind", kindDescription(session.profile.kind))61                    fact("PID", session.processID.map(String.init) ?? "—")62                    fact("TTY", session.ttyPath ?? "—")63                    fact("Directory", session.currentDirectory ?? session.profile.workingDirectory ?? "—")64                    fact("Title", session.title.isEmpty ? "—" : session.title)65                    fact("Session ID", session.id.description)66                    fact("Pane ID", paneID.description)67                    fact("Started", session.startedAt.map { $0.formatted(date: .omitted, time: .standard) } ?? "—")68                    fact("Last output", session.lastOutputAt.map { $0.formatted(date: .omitted, time: .standard) } ?? "none yet")69                    fact("Foreground program", session.hasForegroundProcess ? "yes (verified via PTY)" : "no")70                    if let spec = session.launchSpec {71                        fact("Command", ([spec.executable] + spec.arguments).joined(separator: " "))72                    }7374                } else {75                    Text("No focused session").foregroundStyle(.secondary)76                }77            }78            .padding(12)79            .frame(maxWidth: .infinity, alignment: .leading)80    }8182    private func fact(_ name: String, _ value: String) -> some View {83        VStack(alignment: .leading, spacing: 2) {84            Text(name).font(.system(size: 10, weight: .medium)).foregroundStyle(.secondary)85            Text(value).font(.system(size: 11, design: .monospaced)).textSelection(.enabled)86        }87        .accessibilityElement(children: .combine)88    }8990    private func kindDescription(_ kind: SessionKind) -> String {91        switch kind {92        case .shell(let path): return "Local shell \(path ?? "(login shell)")"93        case .claude(let id, let resume): return "Claude Code session \(id.uuidString.prefix(8))\(resume ? " (resume)" : "")"94        case .ssh(let host, let tmux): return "SSH host \(host.shortString)\(tmux.map { ", tmux \($0)" } ?? "")"95        case .tmux(let name): return "Local tmux session \(name)"96        case .command(let exe, _): return "Command \(exe)"97        }98    }99}100
Files main
Menu

Theme