From ae1c458061dd5e79fc3e7658df01fa08d3ea730a Mon Sep 17 00:00:00 2001 From: zane <39070793+zaneenders@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:53:48 -0600 Subject: [PATCH] Just chroma shell now --- Package.swift | 9 +--- Sources/Chroma/Chroma.docc/Chroma.md | 5 --- Sources/{ => ChromaShell}/Chroma/Chroma.swift | 41 +------------------ .../{ => ChromaShell}/Chroma/PreMade.swift | 0 .../ChromaShell/Rendering/ChromaFrame.swift | 6 +-- .../ChromaShell/Rendering/VisibleNode.swift | 4 +- .../TestChromaClient/TestChromaClient.swift | 6 +-- .../PublicChromaTests.swift | 6 +-- 8 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 Sources/Chroma/Chroma.docc/Chroma.md rename Sources/{ => ChromaShell}/Chroma/Chroma.swift (78%) rename Sources/{ => ChromaShell}/Chroma/PreMade.swift (100%) rename Tests/{ChromaTests => ChromaShellTests}/PublicChromaTests.swift (86%) diff --git a/Package.swift b/Package.swift index 7330eac..b178fb2 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package( .macOS("14.0") ], products: [ - .library(name: "ChromaShell", targets: ["Chroma", "ChromaShell"]) + .library(name: "ChromaShell", targets: ["ChromaShell"]) ], dependencies: [ .package( @@ -42,12 +42,7 @@ let package = Package( ], swiftSettings: swiftSettings), .target( - name: "ChromaShell", - dependencies: ["Chroma"]), - .target(name: "Chroma"), - .testTarget( - name: "ChromaTests", - dependencies: ["Chroma"]), + name: "ChromaShell"), .testTarget( name: "ChromaShellTests", dependencies: ["ChromaShell"]), .plugin( diff --git a/Sources/Chroma/Chroma.docc/Chroma.md b/Sources/Chroma/Chroma.docc/Chroma.md deleted file mode 100644 index 356348f..0000000 --- a/Sources/Chroma/Chroma.docc/Chroma.md +++ /dev/null @@ -1,5 +0,0 @@ -# ``Chroma`` - -A package to add more Chroma to your Swift terminal life. - - diff --git a/Sources/Chroma/Chroma.swift b/Sources/ChromaShell/Chroma/Chroma.swift similarity index 78% rename from Sources/Chroma/Chroma.swift rename to Sources/ChromaShell/Chroma/Chroma.swift index be3d88c..84263dd 100644 --- a/Sources/Chroma/Chroma.swift +++ b/Sources/ChromaShell/Chroma/Chroma.swift @@ -32,7 +32,7 @@ public enum Color { case `default` } -public func wrap( +public func _wrap( _ out: String, _ foreground: Color = .default, _ background: Color = .default @@ -192,42 +192,3 @@ public func background(_ color: TerminalColor, _ str: String) -> ANSIString { } return colorString + str + AnsiEscapeCode.reset.rawValue } - -/// Ansi Codes -/// This is only used as a output translation. -/// [](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) -//!!!: Can we turn this into a DSL -enum AnsiEscapeCode: String { - - case esc = "\u{001b}[" - case reset = "\u{001b}[0m" - case home = "\u{001b}[H" // moves cursor to home position (0, 0) - case eraseScreen = "\u{001b}[2J" - case eraseSaved = "\u{001b}[3J" - case defaultColor = "\u{001b}[1;39m" - // ESC[{line};{column}H - // ESC[{line};{column}f moves cursor to line #, column # - // ESC[J erase in display (same as ESC[0J) - // ESC[0J erase from cursor until end of screen - // ESC[1J erase from cursor to beginning of screen - // ESC[2J erase entire screen - // ESC[3J erase saved lines - // ESC[K erase in line (same as ESC[0K) - // ESC[0K erase from cursor to end of line - // ESC[1K erase start of line to the cursor - // ESC[2K erase the entire line - - enum Style: String { - case bold = "\u{001b}[1m" - case underline = "\u{001b}[4m" - case reversed = "\u{001b}[7m" - } - - static func foregroundColor(_ value: Int) -> String { - "\u{001b}[38;5;\(value)m" - } - - static func backgroundColor(_ value: Int) -> String { - "\u{001b}[48;5;\(value)m" - } -} diff --git a/Sources/Chroma/PreMade.swift b/Sources/ChromaShell/Chroma/PreMade.swift similarity index 100% rename from Sources/Chroma/PreMade.swift rename to Sources/ChromaShell/Chroma/PreMade.swift diff --git a/Sources/ChromaShell/Rendering/ChromaFrame.swift b/Sources/ChromaShell/Rendering/ChromaFrame.swift index 86c16d6..5e2e73b 100644 --- a/Sources/ChromaShell/Rendering/ChromaFrame.swift +++ b/Sources/ChromaShell/Rendering/ChromaFrame.swift @@ -1,5 +1,3 @@ -import Chroma - /// Contains and represents the information needed to render one frame to the current Terminal. public struct ChromaFrame { @@ -10,7 +8,7 @@ public struct ChromaFrame { _ foreground: Color = .default, _ background: Color = .default ) { - self.contents = wrap(raw, foreground, background) + self.contents = _wrap(raw, foreground, background) } /// Creates a frame of the current size filled with the given char @@ -31,7 +29,7 @@ public struct ChromaFrame { out += "\n" } } - self.contents = wrap(out, foreground, background) + self.contents = _wrap(out, foreground, background) } /// provides an ``ANSIString`` view of the ``ChromaFrame`` diff --git a/Sources/ChromaShell/Rendering/VisibleNode.swift b/Sources/ChromaShell/Rendering/VisibleNode.swift index 9988f56..e2e2404 100644 --- a/Sources/ChromaShell/Rendering/VisibleNode.swift +++ b/Sources/ChromaShell/Rendering/VisibleNode.swift @@ -1,5 +1,3 @@ -import Chroma - indirect enum VisibleNode { // NOTE Maybe replace with .style rendering doesn't care whats selected // just what and where things go @@ -104,7 +102,7 @@ extension VisibleNode { } case let .selected(child): // Apply Style? let (s, c) = child.drawVisible(width, height) - return (wrap(s, .black, .pink), c) + return (_wrap(s, .black, .pink), c) } } } diff --git a/Sources/TestChromaClient/TestChromaClient.swift b/Sources/TestChromaClient/TestChromaClient.swift index 24962d2..abcb77e 100644 --- a/Sources/TestChromaClient/TestChromaClient.swift +++ b/Sources/TestChromaClient/TestChromaClient.swift @@ -4,11 +4,7 @@ import Observation @main struct TestChromaClient: ChromaShell { var main: some Block { - Group(.horizontal) { - "Hello" - " " - "World" - } + TestBlock() } } diff --git a/Tests/ChromaTests/PublicChromaTests.swift b/Tests/ChromaShellTests/PublicChromaTests.swift similarity index 86% rename from Tests/ChromaTests/PublicChromaTests.swift rename to Tests/ChromaShellTests/PublicChromaTests.swift index 407362d..ace1e0f 100644 --- a/Tests/ChromaTests/PublicChromaTests.swift +++ b/Tests/ChromaShellTests/PublicChromaTests.swift @@ -1,4 +1,4 @@ -import Chroma +import ChromaShell import XCTest final class PublicChromaTests: XCTestCase { @@ -10,8 +10,8 @@ final class PublicChromaTests: XCTestCase { func testWrap() async { // TODO test these, this might be a better Test for Chroma - let a = wrap("#", .black, .white) - let b = wrap("$", .green, .orange) + let a = _wrap("#", .black, .white) + let b = _wrap("$", .green, .orange) let reset = "\u{001b}[0m" let white = "\u{001b}[48;5;\(231)m" let black = "\u{001b}[38;5;\(232)m"