From 7e0a02fad3807c8deef87860e6c5552a28cf5186 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Wed, 3 Sep 2025 20:33:19 +0100 Subject: [PATCH] redid logic on the shellview selection fixed the colours being unreadable sometimes on title bar of the shellview luminance ratio func forcedismissdisconnectedalert is now in handler --- ShhShell/SSH/SSHHandler.swift | 2 +- ShhShell/Terminal/SSHTerminalDelegate.swift | 2 +- ShhShell/Themes/SwiftTerm.Color.swift | 8 ++ ShhShell/Views/Sessions/SessionView.swift | 2 +- ShhShell/Views/Terminal/ShellTabView.swift | 93 +++++++++++---------- ShhShell/Views/Terminal/ShellView.swift | 8 +- SwiftTerm | 2 +- 7 files changed, 66 insertions(+), 51 deletions(-) diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 64adeb5..7f388fd 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -23,7 +23,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject { var sessionID: UUID? var scrollback: [String] = [] -// var scrollbackSize = 0.0 @Published var title: String = "" @Published var state: SSHState = .idle @@ -32,6 +31,7 @@ class SSHHandler: @unchecked Sendable, ObservableObject { } @Published var testSuceeded: Bool? = nil + @Published var forceDismissDisconnectedAlert: Bool = false @Published var bell: Bool = false diff --git a/ShhShell/Terminal/SSHTerminalDelegate.swift b/ShhShell/Terminal/SSHTerminalDelegate.swift index 29414bb..5bc914c 100644 --- a/ShhShell/Terminal/SSHTerminalDelegate.swift +++ b/ShhShell/Terminal/SSHTerminalDelegate.swift @@ -34,7 +34,7 @@ final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency Termina applyScrollbackLength() applyCursorType() getTerminal().registerOscHandler(code: 133, handler: { _ in }) - getTerminal().setCursorAnimations(CursorAnimations(type: .stretchAndMove)) + getTerminal().setCursorAnimations(CursorAnimations(type: .stretchAndMove, length: 0.2)) self.startFeedLoop() let _ = self.becomeFirstResponder() } diff --git a/ShhShell/Themes/SwiftTerm.Color.swift b/ShhShell/Themes/SwiftTerm.Color.swift index 2b02856..a56b8ce 100644 --- a/ShhShell/Themes/SwiftTerm.Color.swift +++ b/ShhShell/Themes/SwiftTerm.Color.swift @@ -80,4 +80,12 @@ extension SwiftTerm.Color { let b = Double(blue)/65535 return (0.2126*r + 0.7152*g + 0.0722*b) } + + func luminanceRatio(with other: SwiftTerm.Color) -> Double { + if self.luminance > other.luminance { + return (self.luminance + 0.05) / (other.luminance + 0.05) + } else { + return (other.luminance + 0.05) / (self.luminance + 0.05) + } + } } diff --git a/ShhShell/Views/Sessions/SessionView.swift b/ShhShell/Views/Sessions/SessionView.swift index 0162e9e..032cced 100644 --- a/ShhShell/Views/Sessions/SessionView.swift +++ b/ShhShell/Views/Sessions/SessionView.swift @@ -36,7 +36,7 @@ struct SessionView: View { .fullScreenCover(isPresented: $shellPresented) { //instancing handler here cos its non optional ShellTabView( - handler: SSHHandler(host: Host.blank, keyManager: keyManager), + handler: nil, hostsManager: hostsManager, selectedID: key ) diff --git a/ShhShell/Views/Terminal/ShellTabView.swift b/ShhShell/Views/Terminal/ShellTabView.swift index 3637106..bef9e01 100644 --- a/ShhShell/Views/Terminal/ShellTabView.swift +++ b/ShhShell/Views/Terminal/ShellTabView.swift @@ -6,16 +6,17 @@ // import SwiftUI +import SwiftTerm struct ShellTabView: View { - @State var handler: SSHHandler + @State var handler: SSHHandler? @ObservedObject var hostsManager: HostsManager @ObservedObject var container = TerminalViewContainer.shared @State var selectedID: UUID? var selectedHandler: SSHHandler { guard let selectedID, let contained = container.sessions[selectedID] else { - return handler + return handler! } return contained.handler } @@ -24,26 +25,25 @@ struct ShellTabView: View { @Environment(\.dismiss) var dismiss - var foreground: Color { + var foreground: SwiftUI.Color { let selectedTheme = hostsManager.selectedTheme - let foreground = selectedTheme.foreground - let background = selectedTheme.background + let fg = selectedTheme.foreground + let bg = selectedTheme.background + let ansi = selectedTheme.ansi[hostsManager.selectedAnsi] + var result: SwiftTerm.Color - if selectedTheme.ansi[hostsManager.selectedAnsi].luminance > 0.5 { - if foreground.luminance > 0.5 { - return background.suiColor - } else { - return foreground.suiColor - } + if fg.luminanceRatio(with: ansi) > bg.luminanceRatio(with: ansi) { + result = fg } else { - if foreground.luminance > 0.5 { - return foreground.suiColor - } else { - return background.suiColor - } + result = bg } + + guard result.luminanceRatio(with: ansi) > 4.5 else { + return ansi.luminance > 0.5 ? .black : .white + } + return result.suiColor } - var background: Color { hostsManager.selectedTheme.background.suiColor } + var background: SwiftUI.Color { hostsManager.selectedTheme.background.suiColor } var body: some View { ZStack { @@ -84,6 +84,19 @@ struct ShellTabView: View { } } Spacer() + + if selectedHandler.state != .shellOpen { + Button() { + withAnimation { selectedHandler.forceDismissDisconnectedAlert = false } + } label: { + Image(systemName: "wifi.exclamationmark") + .resizable().scaledToFit() + .frame(width: 20, height: 20) + } + .foregroundStyle(foreground) + .id(selectedID) + } + Button() { showSnippetPicker.toggle() } label: { @@ -124,7 +137,7 @@ struct ShellTabView: View { let oneTabWidth: CGFloat = max(100, (UIScreen.main.bounds.width)/CGFloat(container.sessionIDs.count)) HStack(spacing: 0) { ForEach(container.sessionIDs, id: \.self) { id in - let selected: Bool = selectedID == id || (selectedID == nil && handler.sessionID == id) + let selected: Bool = id == selectedHandler.sessionID ?? UUID() let thisHandler: SSHHandler = container.sessions[id]!.handler ZStack { Rectangle() @@ -162,32 +175,28 @@ struct ShellTabView: View { } //the acc terminal lol - if let selectedID, - let session = container.sessions[selectedID] { - ShellView( - handler: session.handler, - hostsManager: hostsManager - ) - .onAppear { - UIApplication.shared.isIdleTimerDisabled = hostsManager.settings.caffeinate - if hostsManager.settings.locationPersist { - Backgrounder.shared.startBgTracking() - } +// Group { +// if selectedID != nil { + ShellView( + handler: selectedHandler, + hostsManager: hostsManager + ) +// } +// } + .onAppear { + UIApplication.shared.isIdleTimerDisabled = hostsManager.settings.caffeinate + if hostsManager.settings.locationPersist { + Backgrounder.shared.startBgTracking() } - .onDisappear { - UIApplication.shared.isIdleTimerDisabled = false - if container.sessions.isEmpty { - Backgrounder.shared.stopBgTracking() - } - } - .id(selectedID) - .transition(.opacity) - } else { - ShellView( - handler: handler, - hostsManager: hostsManager - ) } + .onDisappear { + UIApplication.shared.isIdleTimerDisabled = false + if container.sessions.isEmpty { + Backgrounder.shared.stopBgTracking() + } + } + .id(selectedID) + .transition(.opacity) } } } diff --git a/ShhShell/Views/Terminal/ShellView.swift b/ShhShell/Views/Terminal/ShellView.swift index 74868ce..b6617d1 100644 --- a/ShhShell/Views/Terminal/ShellView.swift +++ b/ShhShell/Views/Terminal/ShellView.swift @@ -13,8 +13,6 @@ struct ShellView: View { @ObservedObject var hostsManager: HostsManager @ObservedObject var container = TerminalViewContainer.shared - @State private var forceDismissDisconnectAlert: Bool = false - @Environment(\.dismiss) var dismiss var body: some View { @@ -36,7 +34,7 @@ struct ShellView: View { } } .onAppear { - forceDismissDisconnectAlert = false + withAnimation { handler.forceDismissDisconnectedAlert = false } } Group { @@ -61,7 +59,7 @@ struct ShellView: View { } } - if handler.state != .shellOpen && !forceDismissDisconnectAlert { + if handler.state != .shellOpen && !handler.forceDismissDisconnectedAlert { ZStack { RoundedRectangle(cornerRadius: 25) .fill(hostsManager.selectedTheme.foreground.suiColor) @@ -89,7 +87,7 @@ struct ShellView: View { .clipShape(RoundedRectangle(cornerRadius: 15)) } Button { - forceDismissDisconnectAlert = true + withAnimation { handler.forceDismissDisconnectedAlert = true } } label: { Text("Cancel") .foregroundStyle(hostsManager.selectedTheme.background.suiColor) diff --git a/SwiftTerm b/SwiftTerm index 66c513b..53d2641 160000 --- a/SwiftTerm +++ b/SwiftTerm @@ -1 +1 @@ -Subproject commit 66c513bf69b6268de25f6f0b83ad2999c1cc8936 +Subproject commit 53d264186ac0196f8e2a322380b51629e23b272a