SPB Git

Repository Public

StatusBarView.swift 3.4 KB 84 lines swift

1import SwiftUI2import TerminalCore3import WorkspaceCore45struct StatusBarView: View {6    @Environment(WorkspaceController.self) private var controller7    let windowID: WindowID89    var body: some View {10        let session = controller.focusedSession(in: windowID)11        HStack(spacing: 14) {12            item("desktopcomputer", hostLabel(session), "Host")13            if let cwd = session?.currentDirectory ?? session?.profile.workingDirectory {14                item("folder", abbreviate(cwd), "Working directory")15            }16            item(kindSymbol(session), kindLabel(session), "Session kind")17            Spacer()18            if let session {19                item("squareshape.split.2x2", "\(session.gridColumns)×\(session.gridRows)", "Terminal size")20                item(NXStatusGlyph.symbol(alive: session.status.isAlive), session.status.label, "Process status")21                    .foregroundStyle(session.status.isAlive ? Color.primary : Color.secondary)22            }23            if controller.relocatedWindows.contains(windowID) {24                item("display.trianglebadge.exclamationmark", "moved to main display", "Window relocated because its saved display is missing")25            }26            if let error = controller.persistence?.lastError {27                item("exclamationmark.triangle", "not saved", "Persistence error: \(error)")28            }29            item("rectangle.3.group", "\(controller.registry.liveCount) live", "Live sessions")30        }31        .nxMonospacedCaption()32        .padding(.horizontal, 10)33        .frame(height: NXTokens.statusHeight)34        .background(NXTokens.chromeBackground)35    }3637    private func item(_ symbol: String, _ text: String, _ label: String) -> some View {38        HStack(spacing: 4) {39            Image(systemName: symbol).font(.system(size: 10)).accessibilityHidden(true)40            Text(text).lineLimit(1)41        }42        .accessibilityElement(children: .combine)43        .accessibilityLabel("\(label): \(text)")44    }4546    private func hostLabel(_ session: TerminalSession?) -> String {47        if case .ssh = session?.profile.kind { return "remote" }48        return LocalHost.shortName49    }5051    private func kindSymbol(_ session: TerminalSession?) -> String {52        switch session?.profile.kind {53        case .claude: return "sparkles"54        case .ssh: return "network"55        case .tmux: return "rectangle.stack"56        default: return "terminal"57        }58    }5960    private func kindLabel(_ session: TerminalSession?) -> String {61        switch session?.profile.kind {62        case .shell(let path): return ((path ?? ShellDiscovery.loginShell()) as NSString).lastPathComponent63        case .claude: return "claude"64        case .ssh: return "ssh"65        case .tmux(let name): return "tmux:\(name)"66        case .command(let exe, _): return (exe as NSString).lastPathComponent67        case nil: return "—"68        }69    }7071    private func abbreviate(_ path: String) -> String { TerminalSession.abbreviate(path) }72}7374/// `ProcessInfo.hostName` performs a synchronous reverse-DNS lookup that can block the main thread75/// for a long time (observed as a launch hang). `gethostname` is immediate.76enum LocalHost {77    static let shortName: String = {78        var buffer = [CChar](repeating: 0, count: 256)79        guard gethostname(&buffer, buffer.count) == 0 else { return "local" }80        let full = String(cString: buffer)81        return full.split(separator: ".").first.map(String.init) ?? full82    }()83}84
Files main
Menu

Theme