From 83284973ea156c779d52d7cc9cd12a72542e7847 Mon Sep 17 00:00:00 2001 From: zane <39070793+zaneenders@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:11:13 -0600 Subject: [PATCH] Started FileSystem example --- Package.swift | 8 ++++- README.md | 8 ++++- .../AsyncUpdate.swift} | 2 +- Sources/ChromaShell/ChromaShell.swift | 1 - Sources/FileSystem/FileSystem.swift | 29 +++++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) rename Sources/{TestChromaClient/TestChromaClient.swift => AsyncUpdate/AsyncUpdate.swift} (94%) create mode 100644 Sources/FileSystem/FileSystem.swift diff --git a/Package.swift b/Package.swift index 3bb0b6e..560e5ad 100644 --- a/Package.swift +++ b/Package.swift @@ -32,7 +32,13 @@ let package = Package( ], targets: [ .executableTarget( - name: "TestChromaClient", + name: "FileSystem", + dependencies: [ + "ChromaShell" + ], + swiftSettings: swiftSettings), + .executableTarget( + name: "AsyncUpdate", dependencies: [ "ChromaShell" ], diff --git a/README.md b/README.md index 7475a39..5d4098f 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,10 @@ Checkout the docs for more details about the project. ## More Examples [Shell Example](Sources/ShellExample/ShellExample.swift) -A simple example of running a shell command in the background \ No newline at end of file +A simple example of running a shell command in the background. + +[AsyncUpdate](Sources/AsyncUpdate/AsyncUpdate.swift) +Shows the ui updating from an external async source. + +[FileSystem](Sources/FileSystem/FileSystem.swift) +An example browsing the file system. \ No newline at end of file diff --git a/Sources/TestChromaClient/TestChromaClient.swift b/Sources/AsyncUpdate/AsyncUpdate.swift similarity index 94% rename from Sources/TestChromaClient/TestChromaClient.swift rename to Sources/AsyncUpdate/AsyncUpdate.swift index 3cb7095..13929d2 100644 --- a/Sources/TestChromaClient/TestChromaClient.swift +++ b/Sources/AsyncUpdate/AsyncUpdate.swift @@ -3,7 +3,7 @@ import Observation import ScribeCore @main -struct TestChromaClient: ChromaShell { +struct AsyncUpdate: ChromaShell { var main: some Block { TestBlock() } diff --git a/Sources/ChromaShell/ChromaShell.swift b/Sources/ChromaShell/ChromaShell.swift index 5ce1fae..abc4451 100644 --- a/Sources/ChromaShell/ChromaShell.swift +++ b/Sources/ChromaShell/ChromaShell.swift @@ -77,7 +77,6 @@ extension ChromaShell { } } - func draw(_ visible: VisibleNode, _ x: Int, _ y: Int) { let ascii = visible.drawVisible(x, y).0 ChromaFrame(ascii, .default, .default).render() diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift new file mode 100644 index 0000000..0761b48 --- /dev/null +++ b/Sources/FileSystem/FileSystem.swift @@ -0,0 +1,29 @@ +import ChromaShell +import Foundation +import Observation +import ScribeCore + +@Observable +final class FileSystemManager { + var cwd: String + init() { + self.cwd = FileManager.default.currentDirectoryPath + } +} + +struct FileSystemBlock: Block { + init() {} + let fileSystem = FileSystemManager() + var component: some Block { + "\(fileSystem.cwd)" + } +} + +@main +struct FileSystem: ChromaShell { + var main: some Block { + // Creates a new process and writes the output to test.txt in the + // current working directory + FileSystemBlock() + } +}