From 8a0e009c7a6e8fcb96145550fe6aecc8fd77d311 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 7 Jul 2025 14:45:16 +0100 Subject: [PATCH] added a themeeditor (really bugged rn) added a convenience init to make a swiftterm color from a swiftui color added a frame to make the terminalcontroller the optimalsize merged extensions --- ShhShell.xcodeproj/project.pbxproj | 4 ++ ShhShell/Themes/ColorCodable.swift | 16 ++++--- .../Views/Terminal/SSHTerminalDelegate.swift | 3 ++ ShhShell/Views/Terminal/ShellView.swift | 4 ++ ShhShell/Views/Themes/ThemeEditorView.swift | 43 +++++++++++++++++++ ShhShell/Views/Themes/ThemePreview.swift | 7 ++- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 ShhShell/Views/Themes/ThemeEditorView.swift diff --git a/ShhShell.xcodeproj/project.pbxproj b/ShhShell.xcodeproj/project.pbxproj index 6edd96a..2fb5549 100644 --- a/ShhShell.xcodeproj/project.pbxproj +++ b/ShhShell.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ A9485C722E1AECD000209824 /* JetBrainsMonoNerdFontMono-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A9485C6E2E1AECD000209824 /* JetBrainsMonoNerdFontMono-Bold.ttf */; }; A9485C732E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A9485C6F2E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf */; }; A9485C762E1AF59F00209824 /* FontManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9485C752E1AF59F00209824 /* FontManagerView.swift */; }; + A9485C782E1BFA5000209824 /* ThemeEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9485C772E1BFA5000209824 /* ThemeEditorView.swift */; }; A95FAA472DF3884B00DE2F5A /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = A95FAA462DF3884B00DE2F5A /* Config.xcconfig */; }; A95FAA542DF4B62900DE2F5A /* LibSSH.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */; }; A95FAA552DF4B62900DE2F5A /* LibSSH.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -154,6 +155,7 @@ A9485C6F2E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-BoldItalic.ttf"; sourceTree = ""; }; A9485C702E1AECD000209824 /* JetBrainsMonoNerdFontMono-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-Italic.ttf"; sourceTree = ""; }; A9485C752E1AF59F00209824 /* FontManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManagerView.swift; sourceTree = ""; }; + A9485C772E1BFA5000209824 /* ThemeEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeEditorView.swift; sourceTree = ""; }; A95FAA462DF3884B00DE2F5A /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = SOURCE_ROOT; }; A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = LibSSH.xcframework; path = Frameworks/LibSSH.xcframework; sourceTree = ""; }; A95FAA512DF4B62100DE2F5A /* openssl.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = openssl.xcframework; path = Frameworks/openssl.xcframework; sourceTree = ""; }; @@ -530,6 +532,7 @@ A9D8192C2E0E9EB500442D38 /* ThemeManagerView.swift */, A9D8192E2E0F1BEE00442D38 /* ThemePreview.swift */, A9FD376A2E16DABF005319A8 /* AnsiPickerView.swift */, + A9485C772E1BFA5000209824 /* ThemeEditorView.swift */, ); path = Themes; sourceTree = ""; @@ -719,6 +722,7 @@ A9D8192D2E0E9EB500442D38 /* ThemeManagerView.swift in Sources */, A9FD375D2E143D7E005319A8 /* KeyStoreError.swift in Sources */, A9835C3C2E17CCA500969508 /* TrafficLights.swift in Sources */, + A9485C782E1BFA5000209824 /* ThemeEditorView.swift in Sources */, A93143C62DF61FE300FCD5DB /* ViewModifiers.swift in Sources */, A98554632E0587DF009051BD /* HostsView.swift in Sources */, A96C6A8A2E0C0B1100F377FE /* SSHState.swift in Sources */, diff --git a/ShhShell/Themes/ColorCodable.swift b/ShhShell/Themes/ColorCodable.swift index a45f154..e661f78 100644 --- a/ShhShell/Themes/ColorCodable.swift +++ b/ShhShell/Themes/ColorCodable.swift @@ -28,6 +28,14 @@ extension ColorCodable { } extension SwiftTerm.Color { + convenience init(_ color: SwiftUI.Color) { + var r: CGFloat = 0; var g: CGFloat = 0; var b: CGFloat = 0; var a: CGFloat = 0 + let uiColor = UIColor(color) + uiColor.getRed(&r, green: &g, blue: &b, alpha: &a) + + self.init(red: UInt16(r*65535), green: UInt16(g*65535), blue: UInt16(b*65535)) + } + convenience init(_ colorCodable: ColorCodable) { let red = UInt16(colorCodable.red * 65535) let green = UInt16(colorCodable.green * 65535) @@ -41,9 +49,7 @@ extension SwiftTerm.Color { let blue = Double(self.blue)/65535 return ColorCodable(red: red, green: green, blue: blue) } -} - -extension SwiftTerm.Color { + var suiColor: SwiftUI.Color { return Color(uiColor: self.uiColor) } @@ -54,9 +60,7 @@ extension SwiftTerm.Color { let blue = CGFloat(self.blue)/65535 return UIColor(red: red, green: green, blue: blue, alpha: 1) } -} - -extension SwiftTerm.Color { + var luminance: Double { let r = Double(red)/65535 let g = Double(green)/65535 diff --git a/ShhShell/Views/Terminal/SSHTerminalDelegate.swift b/ShhShell/Views/Terminal/SSHTerminalDelegate.swift index 8d78d84..b9780f8 100644 --- a/ShhShell/Views/Terminal/SSHTerminalDelegate.swift +++ b/ShhShell/Views/Terminal/SSHTerminalDelegate.swift @@ -29,6 +29,9 @@ final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency Termina font = UIFont(name: hostsManager.selectedFont, size: UIFont.systemFontSize)! } applySelectedTheme() + +// self.frame.size = getOptimalFrameSize().size +// getOptimalFrameSize().width. } } diff --git a/ShhShell/Views/Terminal/ShellView.swift b/ShhShell/Views/Terminal/ShellView.swift index dd6a394..da2bda7 100644 --- a/ShhShell/Views/Terminal/ShellView.swift +++ b/ShhShell/Views/Terminal/ShellView.swift @@ -21,6 +21,10 @@ struct ShellView: View { hostsManager.selectedTheme.background.suiColor .ignoresSafeArea(.all) TerminalController(handler: handler, hostsManager: hostsManager) + .frame( + width: container.sessions[handler.sessionID ?? UUID()]?.terminalView.getOptimalFrameSize().width, + height: container.sessions[handler.sessionID ?? UUID()]?.terminalView.getOptimalFrameSize().width + ) Group { Color.gray.opacity(0.2) diff --git a/ShhShell/Views/Themes/ThemeEditorView.swift b/ShhShell/Views/Themes/ThemeEditorView.swift new file mode 100644 index 0000000..a5a0d61 --- /dev/null +++ b/ShhShell/Views/Themes/ThemeEditorView.swift @@ -0,0 +1,43 @@ +// +// ThemeEditorView.swift +// ShhShell +// +// Created by neon443 on 07/07/2025. +// + +import SwiftUI +import SwiftTerm + +struct ThemeEditorView: View { + @State var theme: Theme + + var body: some View { + NavigationStack { +// List { + ForEach(0...1, id: \.self) { row in + HStack { + ForEach(1...8, id: \.self) { col in + let index = (col + (row * 8)) - 1 + ColorPicker( + selection: Binding( + get: { theme.ansi[index].suiColor }, + set: { newValue in + let cc = SwiftTerm.Color(newValue).colorCodable + theme.ansi[index] = cc.stColor + } + ) + ) { + RoundedRectangle(cornerRadius: 5) + .fill(theme.ansi[index].suiColor) + } + } + } + } +// } + } + } +} + +#Preview { + ThemeEditorView(theme: Theme.defaultTheme) +} diff --git a/ShhShell/Views/Themes/ThemePreview.swift b/ShhShell/Views/Themes/ThemePreview.swift index 6340d81..0a20703 100644 --- a/ShhShell/Views/Themes/ThemePreview.swift +++ b/ShhShell/Views/Themes/ThemePreview.swift @@ -78,11 +78,16 @@ struct ThemePreview: View { .clipShape(RoundedRectangle(cornerRadius: outerR)) .contextMenu { if canModify { + NavigationLink { + ThemeEditorView(theme: theme) + } label: { + Label("Edit", systemImage: "pencil") + } Button() { rename = theme.name showRenameAlert.toggle() } label: { - Label("Rename", systemImage: "pencil") + Label("Rename", systemImage: "text.cursor") } Button(role: .destructive) { hostsManager.deleteTheme(theme)