code cleanup

This commit is contained in:
neon443
2025-09-01 14:42:22 +01:00
parent bcd52143cb
commit 4846831140
3 changed files with 21 additions and 73 deletions

View File

@@ -57,6 +57,7 @@ struct KeyImporterView: View {
} }
} }
.preferredColorScheme(.dark)
.overlay(alignment: .bottom) { .overlay(alignment: .bottom) {
Button() { Button() {
keyManager.importKey(type: keyType, priv: privkeyStr, name: keyName) keyManager.importKey(type: keyType, priv: privkeyStr, name: keyName)

View File

@@ -14,10 +14,16 @@ struct ShellTabView: View {
@ObservedObject var container = TerminalViewContainer.shared @ObservedObject var container = TerminalViewContainer.shared
@State var selectedID: UUID? @State var selectedID: UUID?
var selectedHandler: SSHHandler { var selectedHandler: SSHHandler {
container.sessions[selectedID ?? UUID()]?.handler ?? handler ?? SSHHandler(host: Host.blank, keyManager: nil) guard let selectedID, let contained = container.sessions[selectedID] else {
guard let handler else {
fatalError("selectedHandler: selectedID and handler are nil")
}
return handler
}
return contained.handler
} }
@State var showSnippetPicker: Bool = false @State private var showSnippetPicker: Bool = false
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
@@ -42,6 +48,18 @@ struct ShellTabView: View {
} }
var background: Color { hostsManager.selectedTheme.background.suiColor } var background: Color { hostsManager.selectedTheme.background.suiColor }
init(handler: SSHHandler? = nil, hostsManager: HostsManager, selectedID: UUID? = nil) {
self.selectedID = selectedID
self.handler = handler
if selectedID == nil, let handler {
self.selectedID = handler.sessionID
} else {
fatalError()
}
self.hostsManager = hostsManager
self.container = TerminalViewContainer.shared
}
var body: some View { var body: some View {
ZStack { ZStack {
background background
@@ -149,15 +167,6 @@ struct ShellTabView: View {
} }
} }
.frame(height: 30) .frame(height: 30)
.onAppear {
if selectedID == nil {
if let handler {
selectedID = handler.sessionID
} else {
dismiss()
}
}
}
} }
//the acc terminal lol //the acc terminal lol
@@ -194,11 +203,6 @@ struct ShellTabView: View {
handler: handler, handler: handler,
hostsManager: hostsManager hostsManager: hostsManager
) )
.onAppear {
if selectedID == nil {
selectedID = handler.sessionID
}
}
} else { } else {
Text("No Session") Text("No Session")
} }

View File

@@ -13,36 +13,6 @@ struct ShellView: View {
@ObservedObject var hostsManager: HostsManager @ObservedObject var hostsManager: HostsManager
@ObservedObject var container = TerminalViewContainer.shared @ObservedObject var container = TerminalViewContainer.shared
@State var cursorPos: (x: Int, y: Int) = (0, 0)
var jellyLoc: CGSize {
var offset = CGSize(width: cursorPos.x, height: cursorPos.y)
offset.width *= cellDimension.width
offset.height *= cellDimension.height
switch hostsManager.settings.cursorType.cursorShape {
case .block, .bar:
fallthrough
case .underline:
offset.height += cellDimension.height * 0.8
}
return offset
}
@State var cellDimension: CGSize = CGSize(width: 0, height: 0)
var jellySize: CGSize {
var cellDimension: CGSize = cellDimension
switch hostsManager.settings.cursorType.cursorShape {
case .block:
fallthrough
case .bar:
cellDimension.width *= 0.3
case .underline:
cellDimension.height *= 0.2
}
return cellDimension
}
@State var jellyShow: Bool = true
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
var body: some View { var body: some View {
@@ -54,33 +24,6 @@ struct ShellView: View {
ZStack(alignment: .topLeading) { ZStack(alignment: .topLeading) {
TerminalController(handler: handler, hostsManager: hostsManager) TerminalController(handler: handler, hostsManager: hostsManager)
.brightness(hostsManager.settings.filter == .crt ? 0.2 : 0.0) .brightness(hostsManager.settings.filter == .crt ? 0.2 : 0.0)
.onAppear {
let timer = Timer(timeInterval: 0.1, repeats: true) { timer in
DispatchQueue.main.async {
let terminalView = container.sessions[handler.sessionID ?? UUID()]?.terminalView
let delegate = terminalView?.terminalDelegate as? SSHTerminalDelegate
terminalView?.getTerminal().hideCursor()
cursorPos = terminalView?.getTerminal().getCursorLocation() ?? cursorPos
cellDimension = delegate?.computeFontDimensions() ?? cellDimension
// jellyShow = terminalView?.getTerminal().buffer.isCursorInViewPort ?? jellyShow
}
}
// RunLoop.main.add(timer, forMode: .common)
}
// Rectangle()
// .frame(width: jellySize.width, height: jellySize.height)
// .offset(
// x: jellyLoc.width,
// y: jellyLoc.height
// )
// .opacity(jellyShow ? 1 : 0)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: cursorPos.x)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: cursorPos.y)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: jellyLoc.width)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: jellyLoc.height)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: jellySize.width)
// .animation(.spring(duration: 0.2, bounce: 0.6), value: jellySize.height)
if hostsManager.settings.filter == .crt { if hostsManager.settings.filter == .crt {
CRTView() CRTView()