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
This commit is contained in:
neon443
2025-07-07 14:45:16 +01:00
parent 74b81877a9
commit 8a0e009c7a
6 changed files with 70 additions and 7 deletions

View File

@@ -34,6 +34,7 @@
A9485C722E1AECD000209824 /* JetBrainsMonoNerdFontMono-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A9485C6E2E1AECD000209824 /* JetBrainsMonoNerdFontMono-Bold.ttf */; }; 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 */; }; A9485C732E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A9485C6F2E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf */; };
A9485C762E1AF59F00209824 /* FontManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9485C752E1AF59F00209824 /* FontManagerView.swift */; }; 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 */; }; A95FAA472DF3884B00DE2F5A /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = A95FAA462DF3884B00DE2F5A /* Config.xcconfig */; };
A95FAA542DF4B62900DE2F5A /* LibSSH.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */; }; 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, ); }; }; 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 = "<group>"; }; A9485C6F2E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-BoldItalic.ttf"; sourceTree = "<group>"; };
A9485C702E1AECD000209824 /* JetBrainsMonoNerdFontMono-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-Italic.ttf"; sourceTree = "<group>"; }; A9485C702E1AECD000209824 /* JetBrainsMonoNerdFontMono-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-Italic.ttf"; sourceTree = "<group>"; };
A9485C752E1AF59F00209824 /* FontManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManagerView.swift; sourceTree = "<group>"; }; A9485C752E1AF59F00209824 /* FontManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManagerView.swift; sourceTree = "<group>"; };
A9485C772E1BFA5000209824 /* ThemeEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeEditorView.swift; sourceTree = "<group>"; };
A95FAA462DF3884B00DE2F5A /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = SOURCE_ROOT; }; 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 = "<group>"; }; A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = LibSSH.xcframework; path = Frameworks/LibSSH.xcframework; sourceTree = "<group>"; };
A95FAA512DF4B62100DE2F5A /* openssl.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = openssl.xcframework; path = Frameworks/openssl.xcframework; sourceTree = "<group>"; }; A95FAA512DF4B62100DE2F5A /* openssl.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = openssl.xcframework; path = Frameworks/openssl.xcframework; sourceTree = "<group>"; };
@@ -530,6 +532,7 @@
A9D8192C2E0E9EB500442D38 /* ThemeManagerView.swift */, A9D8192C2E0E9EB500442D38 /* ThemeManagerView.swift */,
A9D8192E2E0F1BEE00442D38 /* ThemePreview.swift */, A9D8192E2E0F1BEE00442D38 /* ThemePreview.swift */,
A9FD376A2E16DABF005319A8 /* AnsiPickerView.swift */, A9FD376A2E16DABF005319A8 /* AnsiPickerView.swift */,
A9485C772E1BFA5000209824 /* ThemeEditorView.swift */,
); );
path = Themes; path = Themes;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -719,6 +722,7 @@
A9D8192D2E0E9EB500442D38 /* ThemeManagerView.swift in Sources */, A9D8192D2E0E9EB500442D38 /* ThemeManagerView.swift in Sources */,
A9FD375D2E143D7E005319A8 /* KeyStoreError.swift in Sources */, A9FD375D2E143D7E005319A8 /* KeyStoreError.swift in Sources */,
A9835C3C2E17CCA500969508 /* TrafficLights.swift in Sources */, A9835C3C2E17CCA500969508 /* TrafficLights.swift in Sources */,
A9485C782E1BFA5000209824 /* ThemeEditorView.swift in Sources */,
A93143C62DF61FE300FCD5DB /* ViewModifiers.swift in Sources */, A93143C62DF61FE300FCD5DB /* ViewModifiers.swift in Sources */,
A98554632E0587DF009051BD /* HostsView.swift in Sources */, A98554632E0587DF009051BD /* HostsView.swift in Sources */,
A96C6A8A2E0C0B1100F377FE /* SSHState.swift in Sources */, A96C6A8A2E0C0B1100F377FE /* SSHState.swift in Sources */,

View File

@@ -28,6 +28,14 @@ extension ColorCodable {
} }
extension SwiftTerm.Color { 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) { convenience init(_ colorCodable: ColorCodable) {
let red = UInt16(colorCodable.red * 65535) let red = UInt16(colorCodable.red * 65535)
let green = UInt16(colorCodable.green * 65535) let green = UInt16(colorCodable.green * 65535)
@@ -41,9 +49,7 @@ extension SwiftTerm.Color {
let blue = Double(self.blue)/65535 let blue = Double(self.blue)/65535
return ColorCodable(red: red, green: green, blue: blue) return ColorCodable(red: red, green: green, blue: blue)
} }
}
extension SwiftTerm.Color {
var suiColor: SwiftUI.Color { var suiColor: SwiftUI.Color {
return Color(uiColor: self.uiColor) return Color(uiColor: self.uiColor)
} }
@@ -54,9 +60,7 @@ extension SwiftTerm.Color {
let blue = CGFloat(self.blue)/65535 let blue = CGFloat(self.blue)/65535
return UIColor(red: red, green: green, blue: blue, alpha: 1) return UIColor(red: red, green: green, blue: blue, alpha: 1)
} }
}
extension SwiftTerm.Color {
var luminance: Double { var luminance: Double {
let r = Double(red)/65535 let r = Double(red)/65535
let g = Double(green)/65535 let g = Double(green)/65535

View File

@@ -29,6 +29,9 @@ final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency Termina
font = UIFont(name: hostsManager.selectedFont, size: UIFont.systemFontSize)! font = UIFont(name: hostsManager.selectedFont, size: UIFont.systemFontSize)!
} }
applySelectedTheme() applySelectedTheme()
// self.frame.size = getOptimalFrameSize().size
// getOptimalFrameSize().width.
} }
} }

View File

@@ -21,6 +21,10 @@ struct ShellView: View {
hostsManager.selectedTheme.background.suiColor hostsManager.selectedTheme.background.suiColor
.ignoresSafeArea(.all) .ignoresSafeArea(.all)
TerminalController(handler: handler, hostsManager: hostsManager) 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 { Group {
Color.gray.opacity(0.2) Color.gray.opacity(0.2)

View File

@@ -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)
}

View File

@@ -78,11 +78,16 @@ struct ThemePreview: View {
.clipShape(RoundedRectangle(cornerRadius: outerR)) .clipShape(RoundedRectangle(cornerRadius: outerR))
.contextMenu { .contextMenu {
if canModify { if canModify {
NavigationLink {
ThemeEditorView(theme: theme)
} label: {
Label("Edit", systemImage: "pencil")
}
Button() { Button() {
rename = theme.name rename = theme.name
showRenameAlert.toggle() showRenameAlert.toggle()
} label: { } label: {
Label("Rename", systemImage: "pencil") Label("Rename", systemImage: "text.cursor")
} }
Button(role: .destructive) { Button(role: .destructive) {
hostsManager.deleteTheme(theme) hostsManager.deleteTheme(theme)