Skip to content

Commit

Permalink
Making a plan for drawVisible
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Jul 4, 2024
1 parent ee85fa1 commit 43040fe
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,87 @@ public func _wrap(
return bg
}

public enum Position {
case foreground
case background
}

public func yellow(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(226), position)
}

public func green(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(40), position)
}

public func blue(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(27), position)
}

public func pink(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(201), position)
}

public func red(_ str: String, _ position: Position = .foreground) -> ANSIString
{
wrap(str, .int(196), position)
}

public func orange(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(202), position)
}

public func purple(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(129), position)
}

public func white(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(231), position)
}

public func black(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(232), position)
}

public func teal(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .int(14), position)
}

public func defaultColor(_ str: String, _ position: Position = .foreground)
-> ANSIString
{
wrap(str, .reset, position)
}

func wrap(_ str: String, _ color: TerminalColor, _ position: Position)
-> ANSIString
{
switch position {
case .foreground:
return foreground(color, str)
case .background:
return background(color, str)
}
}

public func foreground(_ color: TerminalColor, _ str: String) -> ANSIString {
// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
let colorString: String
Expand Down
80 changes: 0 additions & 80 deletions Sources/ChromaShell/Chroma/PreMade.swift

This file was deleted.

44 changes: 43 additions & 1 deletion Sources/ChromaShell/TerminalRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,49 @@ public struct Consumed: Equatable {
}

extension VisibleNode {
/// Draw / render the VisibleNode consuming the max width and height given.
/// A this point we can assume that all or most of the ``VisibleNode``
/// passed to us Almost fit into the height and width we have provided. The
/// job of this function is to tile or materialize the nodes into ASCII
/// escape codes.
///
/// The following assumptions are being made for now. This is currently
/// serving as the outline for what I would like the algorithm to be. But
/// as there isn't something I know a lot about how to do correctly or
/// really know the best way to achieve this.
///
/// Scribe grantees something to be visual selected. This might sound
/// strange to some of you but if you think of your mouse or finger before
/// you actually click this is sort of a way of selecting. Obviously those
/// examples are more complicated and I have ideas to work on them in the
/// future but best to start with the simplest example which I think is
/// the terminal and ASCII escape codes. Now It may be best to traverse
/// the tree to the selected node and then "tile" out from there as I would
/// like to keep that element in the center of the screen give or take some
/// margin. Kinda to reflect similar behavior of vim letting you pad the
/// bottom of the text file.
/// The Next assumption is that text is to generally be centered in the
/// middle of the screen for now. Soon after I debug this algorithm I plan
/// to surface apis for suggesting the text to be left or right, top or
/// bottom. But I think a nice default is for the text to be centered.
///
/// I haven't really thought how to handle clipping or word wrapping yet.
/// For now I think it's best to just clip the text and allow the user to
/// pan around the graph. Which will mean I need to extend the
/// ``VisibleNode`` type to allow deeper selections with in lines/ words
/// This will also be needed to visualize selecting charters of a word in a
/// text editor which I am to build with this UI/UX framework.
///
/// I guess the last thing I should mentioned is text should consume the
/// amount of space possible. Until the size of all nodes is know and we
/// know how much space to fill in around the information needing to be
/// displayed.
///
/// Hopefully this helps other developers understanding what is going on
/// here or at least future Zane. I have a somewhat working example of what
/// i'm trying to do in the ScribeModel repo. But I made different
/// assumptions about the AST there so the problem is just different enough
/// here but it is possible.
#warning("This is very broken and buggy right now")
public func drawVisible(_ width: Int, _ height: Int) -> (
ANSIString, Consumed
) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/FileSystem/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ struct FileSystemBlock: Block {
@main
struct FileSystemMain: ChromaShell {
var main: some Block {
FileSystemBlock()
// FileSystemBlock()
"Hello Zane"
}
}

Expand Down

0 comments on commit 43040fe

Please sign in to comment.