Skip to content

Commit

Permalink
chore: more fixes and cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Oct 17, 2023
1 parent 42ed77d commit 173d331
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Beacon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 = "";
Expand Down
41 changes: 22 additions & 19 deletions Beacon/Components/ReplInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
27 changes: 17 additions & 10 deletions Beacon/Utilities/LexK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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])
}
2 changes: 1 addition & 1 deletion Beacon/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions Beacon/Views/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 173d331

Please sign in to comment.