Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# cmux-owned Swift file length budget.
# Format: max_lines<TAB>relative path
# Reduce counts as files shrink. CI fails if tracked files exceed this budget.
19965 CLI/cmux.swift
16745 Sources/TerminalController.swift
15874 Sources/ContentView.swift
14157 Sources/AppDelegate.swift
20359 CLI/cmux.swift
17115 Sources/TerminalController.swift
15872 Sources/ContentView.swift
14164 Sources/AppDelegate.swift
13686 Sources/Workspace.swift
13354 Sources/GhosttyTerminalView.swift
10603 Sources/Panels/BrowserPanel.swift
8406 Sources/cmuxApp.swift
10600 Sources/Panels/BrowserPanel.swift
8412 Sources/cmuxApp.swift
7495 Sources/TabManager.swift
6811 Sources/Panels/BrowserPanelView.swift
5218 cmuxTests/AppDelegateShortcutRoutingTests.swift
Expand Down Expand Up @@ -62,7 +62,7 @@
752 cmuxUITests/CloseWorkspaceCmdDUITests.swift
719 cmuxUITests/BrowserOmnibarSuggestionsUITests.swift
714 Sources/AppleScriptSupport.swift
708 Sources/App/MenuBarExtraController.swift
720 Sources/App/MenuBarExtraController.swift
683 Sources/SocketControlSettings.swift
664 Sources/App/ShortcutRoutingSupport.swift
643 Sources/Panels/BrowserPopupWindowController.swift
Expand Down
75 changes: 75 additions & 0 deletions CLI/CMUXCLI+TopRendering.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Foundation

extension CMUXCLI {
func topLabelText(_ raw: String?) -> String {
guard let raw else { return "" }
let scalars = Array(raw.unicodeScalars)
var output = String.UnicodeScalarView()
var index = 0

while index < scalars.count {
let scalar = scalars[index]
let value = scalar.value

if value == 0x1B {
index = topIndexAfterEscapeSequence(in: scalars, from: index)
continue
}
if value == 0x9B {
index += 1
while index < scalars.count {
let final = scalars[index].value
index += 1
if final >= 0x40 && final <= 0x7E {
break
}
}
continue
}
if value == 0x09 || value == 0x0A || value == 0x0D {
output.append(UnicodeScalar(0x20)!)
} else if value >= 0x20 && value != 0x7F {
output.append(scalar)
}
index += 1
}

return String(output).trimmingCharacters(in: .whitespacesAndNewlines)
}

func topIndexAfterEscapeSequence(in scalars: [Unicode.Scalar], from startIndex: Int) -> Int {
var index = startIndex + 1
guard index < scalars.count else { return index }

let introducer = scalars[index].value
if introducer == 0x5B {
index += 1
while index < scalars.count {
let value = scalars[index].value
index += 1
if value >= 0x40 && value <= 0x7E {
break
}
}
return index
}

if introducer == 0x5D {
index += 1
while index < scalars.count {
if scalars[index].value == 0x07 {
return index + 1
}
if scalars[index].value == 0x1B,
index + 1 < scalars.count,
scalars[index + 1].value == 0x5C {
return index + 2
}
index += 1
}
return index
}

return index + 1
}
}
Loading