mirror of
https://github.com/neon443/ShhShell.git
synced 2026-11-30 12:44:51 +00:00
added a quick font manager/selector
added selectfont, savefont updated loadfonts fix swipeaction tint color for hosts
This commit is contained in:
6 files changed
+94
-17
No files matched your search
@@ -19,6 +19,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
@Published var selectedAnsi: Int = 1
|
||||
|
||||
@Published var fonts: [UIFont] = []
|
||||
@Published var selectedFont: String = "Menlo"
|
||||
|
||||
var tint: SwiftUI.Color {
|
||||
selectedTheme.ansi[selectedAnsi].suiColor
|
||||
@@ -34,15 +35,24 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
var customFonts: [UIFont] = []
|
||||
for family in UIFont.familyNames.sorted() {
|
||||
if FontFamilies.allCasesRaw.contains(family) {
|
||||
if let family = FontFamilies(rawValue: family) {
|
||||
if let customFont = UIFont(name: family.description, size: UIFont.systemFontSize) {
|
||||
customFonts.append(customFont)
|
||||
}
|
||||
}
|
||||
guard let family = FontFamilies(rawValue: family) else { return }
|
||||
guard let customFont = UIFont(name: family.description, size: UIFont.systemFontSize) else { return }
|
||||
customFonts.append(customFont)
|
||||
}
|
||||
}
|
||||
print(customFonts)
|
||||
self.fonts = customFonts
|
||||
|
||||
self.selectedFont = userDefaults.string(forKey: "selectedFontName") ?? "Menlo"
|
||||
}
|
||||
|
||||
func selectFont(_ fontName: String) {
|
||||
guard fonts.map({ $0.familyName }).contains(fontName) else { return }
|
||||
withAnimation { selectedFont = fontName }
|
||||
saveFonts()
|
||||
}
|
||||
|
||||
func saveFonts() {
|
||||
userDefaults.set(selectedFont, forKey: "selectedFontName")
|
||||
}
|
||||
|
||||
func loadThemes() {
|
||||
|
||||
@@ -30,6 +30,19 @@ struct ContentView: View {
|
||||
keyManager: keyManager
|
||||
)
|
||||
|
||||
Section() {
|
||||
NavigationLink {
|
||||
ThemeManagerView(hostsManager: hostsManager)
|
||||
} label: {
|
||||
Label("Themes", systemImage: "swatchpalette")
|
||||
}
|
||||
NavigationLink {
|
||||
FontManagerView(hostsManager: hostsManager)
|
||||
} label: {
|
||||
Label("Fonts", systemImage: "textformat")
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
KeyManagerView(hostsManager: hostsManager, keyManager: keyManager)
|
||||
} label: {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// FontManagerView.swift
|
||||
// ShhShell
|
||||
//
|
||||
// Created by neon443 on 06/07/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FontManagerView: View {
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
|
||||
@State var testLine: String = "the lazy bronw fox jumps over the lazy dog"
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
ForEach(FontFamilies.allCasesRaw, id: \.self) { fontName in
|
||||
let selected = hostsManager.selectedFont == fontName
|
||||
Button() {
|
||||
hostsManager.selectFont(fontName)
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text(fontName)
|
||||
.foregroundStyle(.gray)
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20)
|
||||
.opacity(selected ? 1 : 0)
|
||||
.foregroundStyle(.green)
|
||||
.animation(.spring, value: selected)
|
||||
.transition(.scale)
|
||||
Text("the lazy bronw fox jumps over the lazy dog")
|
||||
.font(.custom(fontName, size: 15))
|
||||
.bold(selected)
|
||||
.opacity(selected ? 1 : 0.8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section("Test String") {
|
||||
TextEditor(text: $testLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FontManagerView(hostsManager: HostsManager())
|
||||
}
|
||||
@@ -38,26 +38,19 @@ struct HostsView: View {
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
.tint(.red)
|
||||
Button() {
|
||||
hostsManager.duplicateHost(host)
|
||||
} label: {
|
||||
Label("Duplicate", systemImage: "square.filled.on.square")
|
||||
}
|
||||
.foregroundStyle(.blue)
|
||||
.tint(.blue)
|
||||
}
|
||||
}
|
||||
.onMove(perform: {
|
||||
hostsManager.moveHost(from: $0, to: $1)
|
||||
})
|
||||
}
|
||||
|
||||
Section() {
|
||||
NavigationLink {
|
||||
ThemeManagerView(hostsManager: hostsManager)
|
||||
} label: {
|
||||
Label("Themes", systemImage: "swatchpalette")
|
||||
}
|
||||
}
|
||||
.transition(.opacity)
|
||||
.navigationTitle("ShhShell")
|
||||
.toolbar {
|
||||
|
||||
@@ -26,8 +26,7 @@ final class SSHTerminalDelegate: TerminalView, Sendable, @preconcurrency Termina
|
||||
if window != nil {
|
||||
restoreScrollback()
|
||||
if let hostsManager {
|
||||
// font = hostsManager.fonts.randomElement() ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)
|
||||
font = UIFont(name: "JetBrainsMono Nerd Font Mono", size: UIFont.systemFontSize)!
|
||||
font = UIFont(name: hostsManager.selectedFont, size: UIFont.systemFontSize)!
|
||||
}
|
||||
applySelectedTheme()
|
||||
}
|
||||
|
||||