Skip to content

Commit 1d1df5d

Browse files
committed
Reformat long lines for readability in terminal code
Refactored several long lines in MainApp.swift, TerminalManager.swift, and TerminalTabBar.swift to improve readability and maintain consistent code style. No functional changes were made.
1 parent 6f610d8 commit 1d1df5d

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

CodeApp/Managers/MainApp.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import Combine
99
import CoreSpotlight
10-
import os.log
1110
import SwiftGit2
1211
import SwiftUI
1312
import UniformTypeIdentifiers
1413
import ios_system
14+
import os.log
1515

1616
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "Code", category: "MainApp")
1717

@@ -268,7 +268,9 @@ class MainApp: ObservableObject {
268268
if let terminal = self.terminalManager.remoteTerminal {
269269
terminal.write(data: data)
270270
} else {
271-
logger.warning("Remote terminal data dropped: no remote terminal available (\(data.count) bytes)")
271+
logger.warning(
272+
"Remote terminal data dropped: no remote terminal available (\(data.count) bytes)"
273+
)
272274
}
273275
}
274276
loadRepository(url: rootDir)

CodeApp/Managers/TerminalManager.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import SwiftUI
99
import os.log
1010

11-
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "Code", category: "TerminalManager")
11+
private let logger = Logger(
12+
subsystem: Bundle.main.bundleIdentifier ?? "Code", category: "TerminalManager")
1213

1314
/// Manages multiple terminal instances.
1415
/// - Important: Access this class only from the main thread. Debug builds will assert this.
@@ -35,8 +36,9 @@ class TerminalManager: ObservableObject {
3536
/// Useful during initialization when @AppStorage properties aren't yet accessible.
3637
static func readTerminalOptionsFromDefaults() -> TerminalOptions {
3738
if let rawValue = UserDefaults.standard.string(forKey: "terminalOptions"),
38-
let data = rawValue.data(using: .utf8),
39-
let decoded = try? JSONDecoder().decode(TerminalOptions.self, from: data) {
39+
let data = rawValue.data(using: .utf8),
40+
let decoded = try? JSONDecoder().decode(TerminalOptions.self, from: data)
41+
{
4042
return decoded
4143
}
4244
return TerminalOptions()
@@ -128,7 +130,8 @@ class TerminalManager: ObservableObject {
128130
while existingNames.contains(candidateName) && suffix < maxAttempts {
129131
suffix += 1
130132
candidateName = String(
131-
format: NSLocalizedString("%@ (%d)", comment: "Terminal name with duplicate suffix"),
133+
format: NSLocalizedString(
134+
"%@ (%d)", comment: "Terminal name with duplicate suffix"),
132135
baseName, suffix
133136
)
134137
}
@@ -151,26 +154,33 @@ class TerminalManager: ObservableObject {
151154
func createTerminal(name: String? = nil) -> TerminalInstance {
152155
assertMainThread()
153156
guard terminals.count < TerminalManager.maxTerminals else {
154-
logger.debug("create blocked: max reached (count: \(self.terminals.count, privacy: .public), max: \(TerminalManager.maxTerminals, privacy: .public))")
157+
logger.debug(
158+
"create blocked: max reached (count: \(self.terminals.count, privacy: .public), max: \(TerminalManager.maxTerminals, privacy: .public))"
159+
)
155160
// Return the active terminal if at max capacity
156161
// Invariant: terminals array is never empty after init (enforced by closeTerminal guard)
157-
precondition(!terminals.isEmpty, "TerminalManager must always have at least one terminal")
162+
precondition(
163+
!terminals.isEmpty, "TerminalManager must always have at least one terminal")
158164
return activeTerminal ?? terminals.first!
159165
}
160166

161167
let terminalName = name ?? generateUniqueTerminalName()
162168
let terminal = createTerminalInstance(name: terminalName)
163169
terminals.append(terminal)
164170
setActiveTerminalId(terminal.id)
165-
logger.info("created terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)")
171+
logger.info(
172+
"created terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)"
173+
)
166174
return terminal
167175
}
168176

169177
func closeTerminal(id: UUID) {
170178
assertMainThread()
171179
// Don't allow closing the last terminal
172180
guard terminals.count > 1 else {
173-
logger.debug("close blocked: last terminal (count: \(self.terminals.count, privacy: .public)) id: \(id, privacy: .public)")
181+
logger.debug(
182+
"close blocked: last terminal (count: \(self.terminals.count, privacy: .public)) id: \(id, privacy: .public)"
183+
)
174184
return
175185
}
176186

@@ -193,7 +203,9 @@ class TerminalManager: ObservableObject {
193203

194204
terminals.remove(at: index)
195205
syncRemoteTerminalId()
196-
logger.info("closed terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)")
206+
logger.info(
207+
"closed terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)"
208+
)
197209
}
198210

199211
/// Check if a terminal has a running process
@@ -209,7 +221,9 @@ class TerminalManager: ObservableObject {
209221
return
210222
}
211223
setActiveTerminalId(terminal.id)
212-
logger.info("switched terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)")
224+
logger.info(
225+
"switched terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)"
226+
)
213227
}
214228

215229
func renameTerminal(id: UUID, name: String) {
@@ -286,7 +300,8 @@ class TerminalManager: ObservableObject {
286300
}
287301

288302
if let currentId = remoteTerminalId,
289-
terminals.contains(where: { $0.id == currentId && $0.terminalServiceProvider != nil }) {
303+
terminals.contains(where: { $0.id == currentId && $0.terminalServiceProvider != nil })
304+
{
290305
return
291306
}
292307

CodeApp/Views/TerminalTabBar.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ struct TerminalTabRow: View {
8383
// Icon
8484
Image(systemName: "terminal")
8585
.font(.system(size: TerminalTabBarConstants.iconSize))
86-
.foregroundColor(isActive ? Color(id: "list.activeSelectionForeground") : Color(id: "foreground"))
86+
.foregroundColor(
87+
isActive ? Color(id: "list.activeSelectionForeground") : Color(id: "foreground")
88+
)
8789
.frame(width: 20, height: 20)
8890
Spacer()
8991
}
@@ -106,7 +108,11 @@ struct TerminalTabRow: View {
106108
.accessibilityElement(children: .ignore)
107109
.accessibilityLabel(accessibilityLabel)
108110
.accessibilityAddTraits(isActive ? [.isSelected, .isButton] : [.isButton])
109-
.accessibilityHint(NSLocalizedString("Double tap to switch to this terminal", comment: "Accessibility hint for terminal tab"))
111+
.accessibilityHint(
112+
NSLocalizedString(
113+
"Double tap to switch to this terminal",
114+
comment: "Accessibility hint for terminal tab")
115+
)
110116
.contextMenu {
111117
if canClose {
112118
Button(NSLocalizedString("Kill Terminal", comment: ""), role: .destructive) {
@@ -127,7 +133,10 @@ struct TerminalTabRow: View {
127133
onClose()
128134
}
129135
} message: {
130-
Text(NSLocalizedString("This terminal has a running process. Are you sure you want to kill it?", comment: ""))
136+
Text(
137+
NSLocalizedString(
138+
"This terminal has a running process. Are you sure you want to kill it?",
139+
comment: ""))
131140
}
132141
}
133142
}

0 commit comments

Comments
 (0)