mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
added applyTheme() function
added SwiftTerm.Color.uiColor extension to get a UIColor from SwiftTerm.Color rename SSHTerminalView to SSHTerminalDelegate
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
A9083E402DF2226F0042906E /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A9083E3F2DF2225A0042906E /* libz.tbd */; };
|
A9083E402DF2226F0042906E /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A9083E3F2DF2225A0042906E /* libz.tbd */; };
|
||||||
A923172A2E07113100ECE1E6 /* TerminalController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92317292E07113100ECE1E6 /* TerminalController.swift */; };
|
A923172A2E07113100ECE1E6 /* TerminalController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92317292E07113100ECE1E6 /* TerminalController.swift */; };
|
||||||
A923172D2E07138000ECE1E6 /* SSHTerminalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A923172C2E07138000ECE1E6 /* SSHTerminalView.swift */; };
|
A923172D2E07138000ECE1E6 /* SSHTerminalDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A923172C2E07138000ECE1E6 /* SSHTerminalDelegate.swift */; };
|
||||||
A923172F2E08851200ECE1E6 /* ShellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A923172E2E08851200ECE1E6 /* ShellView.swift */; };
|
A923172F2E08851200ECE1E6 /* ShellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A923172E2E08851200ECE1E6 /* ShellView.swift */; };
|
||||||
A92538C82DEE0742007E0A18 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538C52DEE0742007E0A18 /* ContentView.swift */; };
|
A92538C82DEE0742007E0A18 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538C52DEE0742007E0A18 /* ContentView.swift */; };
|
||||||
A92538C92DEE0742007E0A18 /* ShhShellApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538C62DEE0742007E0A18 /* ShhShellApp.swift */; };
|
A92538C92DEE0742007E0A18 /* ShhShellApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92538C62DEE0742007E0A18 /* ShhShellApp.swift */; };
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
A9083E3F2DF2225A0042906E /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
A9083E3F2DF2225A0042906E /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||||
A92317292E07113100ECE1E6 /* TerminalController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalController.swift; sourceTree = "<group>"; };
|
A92317292E07113100ECE1E6 /* TerminalController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalController.swift; sourceTree = "<group>"; };
|
||||||
A923172C2E07138000ECE1E6 /* SSHTerminalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHTerminalView.swift; sourceTree = "<group>"; };
|
A923172C2E07138000ECE1E6 /* SSHTerminalDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHTerminalDelegate.swift; sourceTree = "<group>"; };
|
||||||
A923172E2E08851200ECE1E6 /* ShellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ShellView.swift; path = ShhShell/Views/Terminal/ShellView.swift; sourceTree = SOURCE_ROOT; };
|
A923172E2E08851200ECE1E6 /* ShellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ShellView.swift; path = ShhShell/Views/Terminal/ShellView.swift; sourceTree = SOURCE_ROOT; };
|
||||||
A925389A2DEE06DC007E0A18 /* ShhShell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShhShell.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
A925389A2DEE06DC007E0A18 /* ShhShell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShhShell.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
A92538A72DEE06DE007E0A18 /* ShhShellTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ShhShellTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
A92538A72DEE06DE007E0A18 /* ShhShellTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ShhShellTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -153,7 +153,7 @@
|
|||||||
children = (
|
children = (
|
||||||
A92317292E07113100ECE1E6 /* TerminalController.swift */,
|
A92317292E07113100ECE1E6 /* TerminalController.swift */,
|
||||||
A923172E2E08851200ECE1E6 /* ShellView.swift */,
|
A923172E2E08851200ECE1E6 /* ShellView.swift */,
|
||||||
A923172C2E07138000ECE1E6 /* SSHTerminalView.swift */,
|
A923172C2E07138000ECE1E6 /* SSHTerminalDelegate.swift */,
|
||||||
);
|
);
|
||||||
path = Terminal;
|
path = Terminal;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -482,7 +482,7 @@
|
|||||||
A98554592E0553AA009051BD /* KeyManager.swift in Sources */,
|
A98554592E0553AA009051BD /* KeyManager.swift in Sources */,
|
||||||
A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */,
|
A9C897EF2DF1A9A400EF9A5F /* SSHHandler.swift in Sources */,
|
||||||
A98554552E05535F009051BD /* KeyManagerView.swift in Sources */,
|
A98554552E05535F009051BD /* KeyManagerView.swift in Sources */,
|
||||||
A923172D2E07138000ECE1E6 /* SSHTerminalView.swift in Sources */,
|
A923172D2E07138000ECE1E6 /* SSHTerminalDelegate.swift in Sources */,
|
||||||
A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */,
|
A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */,
|
||||||
A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */,
|
A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */,
|
||||||
A923172A2E07113100ECE1E6 /* TerminalController.swift in Sources */,
|
A923172A2E07113100ECE1E6 /* TerminalController.swift in Sources */,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftTerm
|
import SwiftTerm
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
struct Theme: Hashable, Equatable {
|
struct Theme: Hashable, Equatable {
|
||||||
var name: String
|
var name: String
|
||||||
@@ -21,7 +22,6 @@ struct Theme: Hashable, Equatable {
|
|||||||
|
|
||||||
static func fromiTermColors(name: String, data: Data?) -> Theme? {
|
static func fromiTermColors(name: String, data: Data?) -> Theme? {
|
||||||
guard let data else { return nil }
|
guard let data else { return nil }
|
||||||
guard let string = String(data: data, encoding: .utf8) else { return nil }
|
|
||||||
|
|
||||||
let decoder = PropertyListDecoder()
|
let decoder = PropertyListDecoder()
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ struct ThemeCodable: Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension ThemeCodable {
|
extension ThemeCodable {
|
||||||
var ansi: [Color] {
|
var ansi: [SwiftTerm.Color] {
|
||||||
let arr = [ansi0, ansi1, ansi2, ansi3, ansi4, ansi5, ansi6, ansi7, ansi8, ansi9, ansi10, ansi11, ansi12, ansi13, ansi14, ansi15]
|
let arr = [ansi0, ansi1, ansi2, ansi3, ansi4, ansi5, ansi6, ansi7, ansi8, ansi9, ansi10, ansi11, ansi12, ansi13, ansi14, ansi15]
|
||||||
return arr.map(SwiftTerm.Color.init)
|
return arr.map(SwiftTerm.Color.init)
|
||||||
}
|
}
|
||||||
@@ -123,3 +123,12 @@ extension SwiftTerm.Color {
|
|||||||
self.init(red: red, green: green, blue: blue)
|
self.init(red: red, green: green, blue: blue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension SwiftTerm.Color {
|
||||||
|
var uiColor: UIColor {
|
||||||
|
let red = CGFloat(self.red/65535)
|
||||||
|
let green = CGFloat(self.green/65535)
|
||||||
|
let blue = CGFloat(self.blue/65535)
|
||||||
|
return UIColor(red: red, green: green, blue: blue, alpha: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import UIKit
|
|||||||
import SwiftTerm
|
import SwiftTerm
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalViewDelegate {
|
final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency TerminalViewDelegate {
|
||||||
var handler: SSHHandler?
|
var handler: SSHHandler?
|
||||||
|
|
||||||
public convenience init(frame: CGRect, handler: SSHHandler) {
|
public convenience init(frame: CGRect, handler: SSHHandler) {
|
||||||
@@ -48,6 +48,17 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyTheme(_ theme: Theme) {
|
||||||
|
getTerminal().installPalette(colors: theme.ansi)
|
||||||
|
getTerminal().foregroundColor = theme.foreground
|
||||||
|
getTerminal().backgroundColor = theme.background
|
||||||
|
|
||||||
|
caretColor = theme.cursor.uiColor
|
||||||
|
selectedTextBackgroundColor = theme.selection.uiColor
|
||||||
|
|
||||||
|
// TODO: selectedtext and cursor colors
|
||||||
|
}
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
terminalDelegate = self
|
terminalDelegate = self
|
||||||
@@ -14,7 +14,7 @@ struct TerminalController: UIViewRepresentable {
|
|||||||
@ObservedObject var handler: SSHHandler
|
@ObservedObject var handler: SSHHandler
|
||||||
|
|
||||||
final class TerminalViewContainer {
|
final class TerminalViewContainer {
|
||||||
@MainActor static var shared: SSHTerminalView?
|
@MainActor static var shared: SSHTerminalDelegate?
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeUIView(context: Context) -> TerminalView {
|
func makeUIView(context: Context) -> TerminalView {
|
||||||
@@ -22,7 +22,7 @@ struct TerminalController: UIViewRepresentable {
|
|||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
|
|
||||||
let tv = SSHTerminalView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: .zero), handler: handler)
|
let tv = SSHTerminalDelegate(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: .zero), handler: handler)
|
||||||
tv.translatesAutoresizingMaskIntoConstraints = false
|
tv.translatesAutoresizingMaskIntoConstraints = false
|
||||||
tv.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
tv.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user