added textbox to make pretty textboxes with label

updated connectionview to use nice textboxes with labels
put disconnect and minimize on the left
This commit is contained in:
neon443
2025-06-30 13:52:24 +01:00
parent 9c32778d01
commit 24bf52ff16
4 changed files with 54 additions and 29 deletions

View File

@@ -47,6 +47,7 @@
A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C6AFD2E0C43B600F377FE /* Keypair.swift */; };
A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C6AFF2E0C45FE00F377FE /* KeyDetailView.swift */; };
A96C6B022E0C49E800F377FE /* CenteredLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C6B012E0C49E800F377FE /* CenteredLabel.swift */; };
A96C90A12E12B87A00724253 /* TextBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A96C90A02E12B87900724253 /* TextBox.swift */; };
A98554552E05535F009051BD /* KeyManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98554542E05535F009051BD /* KeyManagerView.swift */; };
A98554592E0553AA009051BD /* KeyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98554582E0553AA009051BD /* KeyManager.swift */; };
A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A985545C2E055D4D009051BD /* ConnectionView.swift */; };
@@ -143,6 +144,7 @@
A96C6AFD2E0C43B600F377FE /* Keypair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keypair.swift; sourceTree = "<group>"; };
A96C6AFF2E0C45FE00F377FE /* KeyDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyDetailView.swift; sourceTree = "<group>"; };
A96C6B012E0C49E800F377FE /* CenteredLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenteredLabel.swift; sourceTree = "<group>"; };
A96C90A02E12B87900724253 /* TextBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBox.swift; sourceTree = "<group>"; };
A98554542E05535F009051BD /* KeyManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagerView.swift; sourceTree = "<group>"; };
A98554582E0553AA009051BD /* KeyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManager.swift; sourceTree = "<group>"; };
A985545C2E055D4D009051BD /* ConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionView.swift; sourceTree = "<group>"; };
@@ -334,6 +336,7 @@
A96C6B012E0C49E800F377FE /* CenteredLabel.swift */,
A93143C52DF61FE300FCD5DB /* ViewModifiers.swift */,
A9B15A992E0ABA0400F66E02 /* DialogView.swift */,
A96C90A02E12B87900724253 /* TextBox.swift */,
);
path = Misc;
sourceTree = "<group>";
@@ -582,6 +585,7 @@
A96BE6AD2E11825800C0FEE9 /* SessionView.swift in Sources */,
A96C6B002E0C45FE00F377FE /* KeyDetailView.swift in Sources */,
A9DA97712E0D30ED00142DDC /* HostSymbol.swift in Sources */,
A96C90A12E12B87A00724253 /* TextBox.swift in Sources */,
A96BE6A82E116E2B00C0FEE9 /* SessionsListView.swift in Sources */,
A98554612E058433009051BD /* HostsManager.swift in Sources */,
A985545D2E055D4D009051BD /* ConnectionView.swift in Sources */,

View File

@@ -51,43 +51,34 @@ struct ConnectionView: View {
.id(handler.host)
.frame(width: 60, height: 60)
TextField("label", text: $handler.host.label)
.textFieldStyle(.roundedBorder)
TextBox(label: "Icon Text", text: $handler.host.label)
}
}
Section {
Text("\(handler.state)")
.foregroundStyle(handler.state.color)
TextField("name", text: $handler.host.name)
.textFieldStyle(.roundedBorder)
TextBox(label: "Name", text: $handler.host.name)
TextField("address", text: $handler.host.address)
.textFieldStyle(.roundedBorder)
TextBox(label: "Address", text: $handler.host.address)
TextField(
"port",
text: Binding(
TextBox(label: "Port", text: Binding(
get: { String(handler.host.port) },
set: {
if let input = Int($0) {
handler.host.port = input
}
}
)
}),
keyboardType: .numberPad
)
.keyboardType(.numberPad)
.textFieldStyle(.roundedBorder)
}
Section {
TextField("Username", text: $handler.host.username)
.textFieldStyle(.roundedBorder)
TextBox(label: "Username", text: $handler.host.username)
SecureField("Password", text: $handler.host.password)
.textFieldStyle(.roundedBorder)
TextBox(label: "Password", text: $handler.host.password, secure: true)
TextField("", text: $pubkeyStr, prompt: Text("Public Key"))
TextBox(label: "Publickey", text: $pubkeyStr)
.onChange(of: pubkeyStr) { _ in
let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "")
handler.host.publicKey = Data(newStr.utf8)
@@ -97,7 +88,7 @@ struct ConnectionView: View {
handler.host.publicKey = Data(newStr.utf8)
}
SecureField("", text: $privkeyStr, prompt: Text("Private Key"))
TextBox(label: "Privatekey", text: $privkeyStr, secure: true)
.onSubmit {
let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "")
handler.host.privateKey = Data(newStr.utf8)
@@ -107,7 +98,7 @@ struct ConnectionView: View {
handler.host.privateKey = Data(newStr.utf8)
}
TextField("", text: $handler.host.passphrase, prompt: Text("Passphrase (Optional)"))
TextBox(label: "Passphrase", text: $handler.host.passphrase)
}
Button() {

View File

@@ -0,0 +1,31 @@
//
// TextBoxWLabel.swift
// ShhShell
//
// Created by neon443 on 30/06/2025.
//
import SwiftUI
struct TextBox: View {
@State var label: String
@Binding var text: String
@State var secure: Bool = false
@State var keyboardType: UIKeyboardType = .default
var body: some View {
HStack {
Text(label)
Spacer()
if secure {
SecureField("", text: $text)
} else {
TextField("", text: $text)
}
}
}
}
#Preview {
TextBox(label: "Label", text: .constant("asdflkajsdl"))
}

View File

@@ -47,15 +47,6 @@ struct ShellView: View {
.navigationTitle(handler.title)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem {
Button() {
handler.disconnect()
if !handler.connected { dismiss() }
} label: {
Label("Disconnect", systemImage: "xmark.app.fill")
}
}
//TODO: FIX
ToolbarItem(placement: .cancellationAction) {
Button() {
dismiss()
@@ -63,6 +54,14 @@ struct ShellView: View {
Label("Close", systemImage: "arrow.down.right.and.arrow.up.left")
}
}
ToolbarItem(placement: .cancellationAction) {
Button() {
handler.disconnect()
if !handler.connected { dismiss() }
} label: {
Label("Disconnect", systemImage: "xmark.app.fill")
}
}
}
}
}