mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 05:19:13 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -54,11 +54,11 @@ final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency Termina
|
||||
}
|
||||
}
|
||||
|
||||
override func showCursor(source: Terminal) {
|
||||
super.showCursor(source: source)
|
||||
super.cursorStyleChanged(source: getTerminal(), newStyle: getTerminal().options.cursorStyle)
|
||||
print("showcursor called")
|
||||
}
|
||||
// override func showCursor(source: Terminal) {
|
||||
// super.showCursor(source: source)
|
||||
// super.cursorStyleChanged(source: getTerminal(), newStyle: getTerminal().options.cursorStyle)
|
||||
// print("showcursor called")
|
||||
// }
|
||||
|
||||
override func hideCursor(source: Terminal) {
|
||||
super.hideCursor(source: source)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
if fg.luminanceRatio(with: ansi) > bg.luminanceRatio(with: ansi) {
|
||||
result = fg
|
||||
} else {
|
||||
return foreground.suiColor
|
||||
result = bg
|
||||
}
|
||||
} else {
|
||||
if foreground.luminance > 0.5 {
|
||||
return foreground.suiColor
|
||||
} else {
|
||||
return background.suiColor
|
||||
|
||||
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,12 +175,14 @@ struct ShellTabView: View {
|
||||
}
|
||||
|
||||
//the acc terminal lol
|
||||
if let selectedID,
|
||||
let session = container.sessions[selectedID] {
|
||||
// Group {
|
||||
// if selectedID != nil {
|
||||
ShellView(
|
||||
handler: session.handler,
|
||||
handler: selectedHandler,
|
||||
hostsManager: hostsManager
|
||||
)
|
||||
// }
|
||||
// }
|
||||
.onAppear {
|
||||
UIApplication.shared.isIdleTimerDisabled = hostsManager.settings.caffeinate
|
||||
if hostsManager.settings.locationPersist {
|
||||
@@ -182,12 +197,6 @@ struct ShellTabView: View {
|
||||
}
|
||||
.id(selectedID)
|
||||
.transition(.opacity)
|
||||
} else {
|
||||
ShellView(
|
||||
handler: handler,
|
||||
hostsManager: hostsManager
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Submodule SwiftTerm updated: 66c513bf69...53d264186a
Reference in New Issue
Block a user