forked from gluonfield/enchanted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:AugustDev/enchanted-ios-llm
- Loading branch information
Showing
27 changed files
with
334 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Enchanted/Extensions/SplashSyntaxHighlighter+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// SplashSyntaxHighlighter+Extension.swift | ||
// Enchanted | ||
// | ||
// Created by Augustinas Malinauskas on 12/03/2024. | ||
// | ||
|
||
import MarkdownUI | ||
import Splash | ||
import SwiftUI | ||
|
||
struct SplashCodeSyntaxHighlighter: CodeSyntaxHighlighter { | ||
private let syntaxHighlighter: SyntaxHighlighter<TextOutputFormat> | ||
|
||
init(theme: Splash.Theme) { | ||
self.syntaxHighlighter = SyntaxHighlighter(format: TextOutputFormat(theme: theme)) | ||
} | ||
|
||
func highlightCode(_ content: String, language: String?) -> Text { | ||
guard language != nil else { | ||
return Text(content) | ||
} | ||
|
||
return self.syntaxHighlighter.highlight(content) | ||
} | ||
} | ||
|
||
extension CodeSyntaxHighlighter where Self == SplashCodeSyntaxHighlighter { | ||
static func splash(theme: Splash.Theme) -> Self { | ||
SplashCodeSyntaxHighlighter(theme: theme) | ||
} | ||
} | ||
|
||
struct TextOutputFormat: OutputFormat { | ||
private let theme: Splash.Theme | ||
|
||
init(theme: Splash.Theme) { | ||
self.theme = theme | ||
} | ||
|
||
func makeBuilder() -> Builder { | ||
Builder(theme: self.theme) | ||
} | ||
} | ||
|
||
extension TextOutputFormat { | ||
struct Builder: OutputBuilder { | ||
private let theme: Splash.Theme | ||
private var accumulatedText: [Text] | ||
|
||
fileprivate init(theme: Splash.Theme) { | ||
self.theme = theme | ||
self.accumulatedText = [] | ||
} | ||
|
||
mutating func addToken(_ token: String, ofType type: TokenType) { | ||
let color = self.theme.tokenColors[type] ?? self.theme.plainTextColor | ||
self.accumulatedText.append(Text(token).foregroundColor(.init(color))) | ||
} | ||
|
||
mutating func addPlainText(_ text: String) { | ||
self.accumulatedText.append( | ||
Text(text).foregroundColor(.init(self.theme.plainTextColor)) | ||
) | ||
} | ||
|
||
mutating func addWhitespace(_ whitespace: String) { | ||
self.accumulatedText.append(Text(whitespace)) | ||
} | ||
|
||
func build() -> Text { | ||
self.accumulatedText.reduce(Text(""), +) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// NotificationMessage.swift | ||
// Enchanted | ||
// | ||
// Created by Augustinas Malinauskas on 12/03/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct NotificationMessage: Identifiable { | ||
var id = UUID() | ||
var message: String | ||
var status: Status | ||
var timestamp = Date() | ||
|
||
enum Status { | ||
case error | ||
case info | ||
} | ||
} | ||
|
||
// MARK: Sample data | ||
extension NotificationMessage { | ||
static let sample: [NotificationMessage] = [ | ||
.init(message: "Querying ollama", status: .info), | ||
.init(message: "Window changed. Stopping writing.", status: .info) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.