From 173d331737553f8891b312926a39cd7d6f859dcc Mon Sep 17 00:00:00 2001 From: x86y Date: Tue, 17 Oct 2023 12:39:00 +0400 Subject: [PATCH] chore: more fixes and cleaning up --- Beacon.xcodeproj/project.pbxproj | 4 +-- Beacon/Components/ReplInput.swift | 41 +++++++++++++++++-------------- Beacon/Utilities/LexK.swift | 27 ++++++++++++-------- Beacon/Views/ContentView.swift | 2 +- Beacon/Views/HistoryView.swift | 1 + 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Beacon.xcodeproj/project.pbxproj b/Beacon.xcodeproj/project.pbxproj index 5935e69..317d07a 100644 --- a/Beacon.xcodeproj/project.pbxproj +++ b/Beacon.xcodeproj/project.pbxproj @@ -750,7 +750,7 @@ "$(PROJECT_DIR)/Beacon/libs", "$(PROJECT_DIR)/Beacon/Libs", ); - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.1.5; PRODUCT_BUNDLE_IDENTIFIER = arrscience.Beacons; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -797,7 +797,7 @@ "$(PROJECT_DIR)/Beacon/libs", "$(PROJECT_DIR)/Beacon/Libs", ); - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.1.5; PRODUCT_BUNDLE_IDENTIFIER = arrscience.Beacons; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Beacon/Components/ReplInput.swift b/Beacon/Components/ReplInput.swift index 97bce99..a468619 100644 --- a/Beacon/Components/ReplInput.swift +++ b/Beacon/Components/ReplInput.swift @@ -13,51 +13,54 @@ struct ReplInput: View { } var body: some View { - HStack { - ScrollView(.horizontal) { - HStack { - ForEach(letters, id: \.self) { letter in - Button(letter) { - text.append(letter) + let toolbar = ToolbarItemGroup(placement: .keyboard) { + HStack { + ScrollView(.horizontal) { + HStack { + ForEach(letters, id: \.self) { letter in + Button(letter) { + text.append(letter) + } + .font(.custom("BQN386 Unicode", size: 16)) + .padding(8) + .background(.gray.opacity(0.1)) + .foregroundStyle(.primary) + .clipShape(RoundedRectangle(cornerRadius: 8)) } - .font(.custom("BQN386 Unicode", size: 16)) - .padding(8) - .background(.gray.opacity(0.1)) - .foregroundStyle(.primary) - .clipShape(RoundedRectangle(cornerRadius: 8)) } } - } - HStack { Button(action: { text = "" }) { Image(systemName: "arrow.left.square.fill") .resizable() - .frame(width: 24.0, height: 24.0) + .frame(width: 16.0, height: 16.0) } Button(action: { helpOpen.toggle() }) { Image(systemName: "questionmark.app.fill") .resizable() - .frame(width: 24.0, height: 24.0) + .frame(width: 16.0, height: 16.0) } Button(action: { buffersOpen.toggle() }) { Image(systemName: "list.bullet.rectangle.portrait.fill") .resizable() - .frame(width: 24.0, height: 24.0) + .frame(width: 16.0, height: 16.0) } Button(action: { settingsOpen.toggle() }) { Image(systemName: "command.square.fill") .resizable() - .frame(width: 24.0, height: 24.0) + .frame(width: 16.0, height: 16.0) } } } HStack { - TextField("Type some \(languageToString(l: lang)) code..", text: $text, axis: .vertical) + TextField("Type \(languageToString(l: lang))...", text: $text, axis: .vertical) .onSubmit { onSubmit?() } + .toolbar { + toolbar + } .lineLimit(1 ... 8) .keyboardType(.asciiCapable) .submitLabel(.done) @@ -84,7 +87,7 @@ struct EvalButton: ViewModifier { }) { Image(systemName: "restart.circle") .resizable() - .frame(width: 24.0, height: 24.0) + .frame(width: 32.0, height: 2.0) } .padding(8) } diff --git a/Beacon/Utilities/LexK.swift b/Beacon/Utilities/LexK.swift index 9c229af..93d75f1 100644 --- a/Beacon/Utilities/LexK.swift +++ b/Beacon/Utilities/LexK.swift @@ -28,22 +28,20 @@ func parseK(_ str: String) -> [String] { res[0] = regC var i = 0 - while i < str.count { - let p = i - 1 >= 0 ? String(str[str.index(str.startIndex, offsetBy: i - 1) ... str.index(str.startIndex, offsetBy: i - 1)]) : "\0" - let c = String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)]) - let n = i + 1 < str.count ? String(str[str.index(str.startIndex, offsetBy: i + 1) ... str.index(str.startIndex, offsetBy: i + 1)]) : "\0" + let p = charAt(str, i - 1) + let c = charAt(str, i) + let n = charAt(str, i + 1) if dig.contains(c) || (c == "." && dig.contains(n)) { res[i] = digC - while i < str.count, dig.contains(String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)])) || ".eEnNbiwW".contains(String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)])) { + while i < str.count, dig.contains(charAt(str, i)) || ".eEnNbiwW".contains(charAt(str, i)) { i += 1 } - continue } else if (c == " " && n == "/") || ((p == "\n" || p == "\0") && c == "/") { res[i] = comC - while i < str.count, str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)] != "\n" { + while i < str.count, charAt(str, i) != "\n" { i += 1 } } else if fns.contains(c) || c.unicodeScalars.first!.value >= 0x80 { @@ -62,15 +60,15 @@ func parseK(_ str: String) -> [String] { res[i] = dmdC } else if nam.contains(c) { res[i] = namC - while nam.contains(String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)])) || dig.contains(String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)])) { + while i < str.count, nam.contains(charAt(str, i)) || dig.contains(charAt(str, i)) { i += 1 } continue } else if c == "\"" { res[i] = strC i += 1 - while str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)] != "\"", str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)] != "\n" { - i += String(str[str.index(str.startIndex, offsetBy: i) ... str.index(str.startIndex, offsetBy: i)]) == "\\" ? 2 : 1 + while charAt(str, i) != "\"", charAt(str, i) != "\n" { + i += charAt(str, i) == "\\" ? 2 : 1 } } else if !" \t".contains(c) { res[i] = regC @@ -79,5 +77,14 @@ func parseK(_ str: String) -> [String] { } i += 1 } + return res } + +func charAt(_ str: String, _ i: Int) -> String { + if i < 0 || i >= str.count { + return "\0" + } + let index = str.index(str.startIndex, offsetBy: i) + return String(str[index]) +} diff --git a/Beacon/Views/ContentView.swift b/Beacon/Views/ContentView.swift index 052ee43..3bfa230 100644 --- a/Beacon/Views/ContentView.swift +++ b/Beacon/Views/ContentView.swift @@ -66,7 +66,7 @@ struct ContentView: View { ScrollViewReader { scrollView in VStack { ScrollView(.vertical) { - VStack { + VStack(spacing: 12) { if viewModel.history[curBuffer, default: []].isEmpty { VStack { Text("ngn/k, (c) 2019-2023") diff --git a/Beacon/Views/HistoryView.swift b/Beacon/Views/HistoryView.swift index 6139ab9..5f90941 100644 --- a/Beacon/Views/HistoryView.swift +++ b/Beacon/Views/HistoryView.swift @@ -63,6 +63,7 @@ struct HistoryView: View { } } Text("\(trimLongText(historyItem.out))") + .foregroundStyle(.primary.opacity(0.8)) .font(Font.custom("BQN386 Unicode", size: 18)) .foregroundColor(historyItem.out.starts(with: "Error:") || historyItem.out.starts(with: "\"Error:") ? .red : .primary) .multilineTextAlignment(.leading)