diff --git a/Sources/Core/Helpers/Loger.swift b/Sources/Core/Helpers/Loger.swift index 29c0473..f2c65a2 100644 --- a/Sources/Core/Helpers/Loger.swift +++ b/Sources/Core/Helpers/Loger.swift @@ -49,12 +49,13 @@ public struct Logger { ) { guard let desktopDir = NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true).last else { return } let string = event.icon + " \(Date()): " + messages.map { "\($0) " }.joined() - try? string.write(toFile: desktopDir + "//log.txt", atomically: true, encoding: .utf8) - } - - public func log(_ str: String) { + guard let desktopUrl = URL(string: desktopDir) else { return } + let fileContent = (try? String(contentsOf: desktopUrl.appendingPathComponent("log.txt"))) ?? "" + let finalLog = fileContent.appending("\n " + string) + try? finalLog.write(toFile: desktopDir + "//log.txt", atomically: true, encoding: .utf8) } + } diff --git a/Sources/Core/Highligher/Highlighter.swift b/Sources/Core/Highligher/Highlighter.swift index e230b82..83dac93 100644 --- a/Sources/Core/Highligher/Highlighter.swift +++ b/Sources/Core/Highligher/Highlighter.swift @@ -17,10 +17,10 @@ public struct Highlighter { .map { $0.kind.rawValue + " \($0.range.lowerBound) \($0.range.upperBound)" } .joined(separator: " ") Logger.log(event: .debug, destination: .disk, messages: log) - tokens.forEach({ token in + tokens.forEach { token in let color = self.color(for: token.kind) code.highlight(token.text, with: color, at: token.range) - }) + } Logger.log(event: .debug, destination: .disk, messages: code) return code @@ -28,8 +28,8 @@ public struct Highlighter { } private extension Highlighter { - func color(for key: TokenType) -> Color { - config.theme.highlights[key] ?? Color(r: 250, g: 141, b: 87) + func color(for token: TokenType) -> Color { + config.theme.highlights[token] ?? Color(r: 250, g: 141, b: 87) } }