mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
add settingsview
add setting struct add export/importhosts fumction
This commit is contained in:
@@ -32,6 +32,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
|
||||
init(previews: Bool = false) {
|
||||
loadHosts()
|
||||
exportHosts()
|
||||
loadThemes()
|
||||
loadFonts()
|
||||
loadSnippets()
|
||||
@@ -306,6 +307,16 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
func exportHosts() {
|
||||
guard let encoded = try? JSONEncoder().encode(hosts) else { return }
|
||||
print(encoded.base64EncodedString())
|
||||
}
|
||||
|
||||
func importHosts(_ data: Data) {
|
||||
guard let decoedd = try? JSONDecoder().decode([Host].self, from: data) else { return }
|
||||
hosts = decoedd
|
||||
}
|
||||
|
||||
func removeHost(_ host: Host) {
|
||||
if let index = hosts.firstIndex(where: { $0.id == host.id }) {
|
||||
let _ = withAnimation { hosts.remove(at: index) }
|
||||
|
||||
@@ -381,16 +381,8 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
|
||||
let data = Data(bytes: buffer, count: Int(nbytes))
|
||||
if let string = String(data: data, encoding: .utf8) {
|
||||
#if DEBUG
|
||||
// print(String(data: Data(bytes: buffer, count: Int(nbytes)), encoding: .utf8)!)
|
||||
#endif
|
||||
Task { @MainActor in
|
||||
scrollback.append(string)
|
||||
// if scrollbackSize/1024/1024 > 10 {
|
||||
// scrollback.remove(at: 0)
|
||||
// } else {
|
||||
// scrollbackSize += Double(string.lengthOfBytes(using: .utf8))
|
||||
// }
|
||||
}
|
||||
return string
|
||||
}
|
||||
@@ -420,19 +412,8 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
|
||||
guard ssh_channel_is_eof(channel) == 0 else { throw .backendError("Channel is EOF") }
|
||||
|
||||
ssh_channel_change_pty_size(channel, Int32(toCols), Int32(toRows))
|
||||
// print("resized tty to \(toRows)rows and \(toCols)cols")
|
||||
}
|
||||
|
||||
// func prettyScrollbackSize() -> String {
|
||||
// if (scrollbackSize/1024/1024) > 1 {
|
||||
// return "\(scrollbackSize/1024/1024) MiB scrollback"
|
||||
// } else if scrollbackSize/1024 > 1 {
|
||||
// return "\(scrollbackSize/1024) KiB scrollback"
|
||||
// } else {
|
||||
// return "\(scrollbackSize) B scrollback"
|
||||
// }
|
||||
// }
|
||||
|
||||
private func logSshGetError() {
|
||||
guard var session = self.session else { return }
|
||||
logger.critical("\(String(cString: ssh_get_error(&session)))")
|
||||
|
||||
34
ShhShell/Settings/AppSettings.swift
Normal file
34
ShhShell/Settings/AppSettings.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// AppSettings.swift
|
||||
// ShhShell
|
||||
//
|
||||
// Created by neon443 on 19/08/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct AppSettings: Codable, Sendable {
|
||||
var scrollback: Int = 1_000
|
||||
var cursorStyle: CursorStyle = .block
|
||||
var locationPersist: Bool = false
|
||||
var bellSound: Bool = false
|
||||
var bellHaptic: Bool = true
|
||||
var caffeinate: Bool = false
|
||||
var filter: TerminalFilter = .none
|
||||
var appIcon: AppIcon = .regular
|
||||
}
|
||||
|
||||
enum CursorStyle: Codable {
|
||||
case block
|
||||
case bar
|
||||
}
|
||||
|
||||
enum TerminalFilter: Codable {
|
||||
case none
|
||||
case crt
|
||||
}
|
||||
|
||||
enum AppIcon: Codable {
|
||||
case regular
|
||||
case blueprint
|
||||
}
|
||||
@@ -69,6 +69,11 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
Section {
|
||||
NavigationLink {
|
||||
SettingsView(hostsManager: hostsManager, keyManager: keyManager)
|
||||
} label: {
|
||||
Label("Settings", systemImage: "gear")
|
||||
}
|
||||
NavigationLink {
|
||||
AboutView(hostsManager: hostsManager)
|
||||
} label: {
|
||||
|
||||
38
ShhShell/Views/Settings/SettingsView.swift
Normal file
38
ShhShell/Views/Settings/SettingsView.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// SettingsView.swift
|
||||
// ShhShell
|
||||
//
|
||||
// Created by neon443 on 19/08/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
@ObservedObject var keyManager: KeyManager
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
hostsManager.selectedTheme.background.suiColor.opacity(0.7)
|
||||
.ignoresSafeArea(.all)
|
||||
List {
|
||||
Section("Terminal") {
|
||||
Label("Scrollback", systemImage: "scroll")
|
||||
HStack {
|
||||
Slider(value: .constant(0), in: 1_000...50_000, step: 1_000)
|
||||
Text("\()")
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
.scrollContentBackground(.hidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SettingsView(
|
||||
hostsManager: HostsManager(),
|
||||
keyManager: KeyManager()
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user