From 24bf52ff16dc065fec13e35f635115b885e49a30 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Mon, 30 Jun 2025 13:52:24 +0100 Subject: [PATCH] added textbox to make pretty textboxes with label updated connectionview to use nice textboxes with labels put disconnect and minimize on the left --- ShhShell.xcodeproj/project.pbxproj | 4 +++ ShhShell/Views/Hosts/ConnectionView.swift | 31 ++++++++--------------- ShhShell/Views/Misc/TextBox.swift | 31 +++++++++++++++++++++++ ShhShell/Views/Terminal/ShellView.swift | 17 ++++++------- 4 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 ShhShell/Views/Misc/TextBox.swift diff --git a/ShhShell.xcodeproj/project.pbxproj b/ShhShell.xcodeproj/project.pbxproj index 64db27e..fa7e8e0 100644 --- a/ShhShell.xcodeproj/project.pbxproj +++ b/ShhShell.xcodeproj/project.pbxproj @@ -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 = ""; }; A96C6AFF2E0C45FE00F377FE /* KeyDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyDetailView.swift; sourceTree = ""; }; A96C6B012E0C49E800F377FE /* CenteredLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenteredLabel.swift; sourceTree = ""; }; + A96C90A02E12B87900724253 /* TextBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBox.swift; sourceTree = ""; }; A98554542E05535F009051BD /* KeyManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagerView.swift; sourceTree = ""; }; A98554582E0553AA009051BD /* KeyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManager.swift; sourceTree = ""; }; A985545C2E055D4D009051BD /* ConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionView.swift; sourceTree = ""; }; @@ -334,6 +336,7 @@ A96C6B012E0C49E800F377FE /* CenteredLabel.swift */, A93143C52DF61FE300FCD5DB /* ViewModifiers.swift */, A9B15A992E0ABA0400F66E02 /* DialogView.swift */, + A96C90A02E12B87900724253 /* TextBox.swift */, ); path = Misc; sourceTree = ""; @@ -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 */, diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index 5898668..2f121f1 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -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() { diff --git a/ShhShell/Views/Misc/TextBox.swift b/ShhShell/Views/Misc/TextBox.swift new file mode 100644 index 0000000..52b230a --- /dev/null +++ b/ShhShell/Views/Misc/TextBox.swift @@ -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")) +} diff --git a/ShhShell/Views/Terminal/ShellView.swift b/ShhShell/Views/Terminal/ShellView.swift index e92ff40..015dbb6 100644 --- a/ShhShell/Views/Terminal/ShellView.swift +++ b/ShhShell/Views/Terminal/ShellView.swift @@ -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") + } + } } } }