Skip to content

Commit

Permalink
chore: try ayu colors for K
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Oct 17, 2023
1 parent 8727bf3 commit 1a6dcfe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Beacon/Utilities/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@ func tokenToColor(_ type: TokenType) -> Color {
}
}

func tokenToColorK(_ type: TokenType, _ isDarkTheme: Bool) -> Color {
let colorHex: String
switch type {
case .regC, .namC:
colorHex = isDarkTheme ? "39BAE6" : "000000"
case .comC, .endL:
colorHex = isDarkTheme ? "ACB6BF" : "6A737D"
case .digC:
colorHex = isDarkTheme ? "D2A6FF" : "005CC5"
case .parC:
colorHex = isDarkTheme ? "E6B673" : "000000"
case .dmdC:
colorHex = isDarkTheme ? "FFFF00" : "0000FF"
case .strC:
colorHex = isDarkTheme ? "AAD94C" : "032F62"
case .fnsC:
colorHex = isDarkTheme ? "F29668" : "D73A49"
case .mopC:
colorHex = isDarkTheme ? "39BAE6" : "ED5F00"
case .dfnC:
colorHex = isDarkTheme ? "FFB454" : "A906D4"
}
return Color(hex: colorHex)
}


extension Color {
init(hex: String) {
let scanner = Scanner(string: hex)
var rgb: UInt64 = 0

scanner.scanHexInt64(&rgb)

let red = Double((rgb & 0xFF0000) >> 16) / 255.0
let green = Double((rgb & 0x00FF00) >> 8) / 255.0
let blue = Double(rgb & 0x0000FF) / 255.0

self.init(red: red, green: green, blue: blue)
}
}


enum TokenType: String, Codable {
case regC = "0"
case fnsC = "1"
Expand Down
5 changes: 4 additions & 1 deletion Beacon/Views/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct HistoryView: View {
@Binding var ephemerals: [Int: [String]]
@Binding var editType: Behavior
@ObservedObject var viewModel: HistoryModel
@Environment(\.colorScheme) var scheme: ColorScheme

var body: some View {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -48,8 +49,10 @@ struct HistoryView: View {
ForEach(Array(historyItem.tokens.enumerated()), id: \.offset) { _, line in
HStack(spacing: 0) {
ForEach(line, id: \.id) { token in
let isDarkTheme = (scheme == .dark)
let col = historyItem.lang == Language.k ? tokenToColorK(token.type, isDarkTheme) : tokenToColor(token.type)
Text(token.value)
.foregroundColor(tokenToColor(token.type))
.foregroundColor(col)
.font(Font.custom("BQN386 Unicode", size: 18))
.onTapGesture {
self.input = historyItem.src
Expand Down

0 comments on commit 1a6dcfe

Please sign in to comment.