Skip to content

Commit

Permalink
Just chroma shell now
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Jul 2, 2024
1 parent 86c6848 commit ae1c458
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 67 deletions.
9 changes: 2 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.macOS("14.0")
],
products: [
.library(name: "ChromaShell", targets: ["Chroma", "ChromaShell"])
.library(name: "ChromaShell", targets: ["ChromaShell"])
],
dependencies: [
.package(
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions Sources/Chroma/Chroma.docc/Chroma.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum Color {
case `default`
}

public func wrap(
public func _wrap(
_ out: String,
_ foreground: Color = .default,
_ background: Color = .default
Expand Down Expand Up @@ -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"
}
}
File renamed without changes.
6 changes: 2 additions & 4 deletions Sources/ChromaShell/Rendering/ChromaFrame.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Chroma

/// Contains and represents the information needed to render one frame to the current Terminal.
public struct ChromaFrame {

Expand All @@ -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
Expand All @@ -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``
Expand Down
4 changes: 1 addition & 3 deletions Sources/ChromaShell/Rendering/VisibleNode.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions Sources/TestChromaClient/TestChromaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import Observation
@main
struct TestChromaClient: ChromaShell {
var main: some Block {
Group(.horizontal) {
"Hello"
" "
"World"
}
TestBlock()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Chroma
import ChromaShell
import XCTest

final class PublicChromaTests: XCTestCase {
Expand All @@ -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"
Expand Down

0 comments on commit ae1c458

Please sign in to comment.