-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge: feat: add Frame type and remove cursor commands (#1295)
This commit introduces a new `Frame` type that represents a single frame of the program's output. The `Frame` type contains the frame's content and cursor settings. The cursor settings include the cursor's position, style, blink, and visibility. It also removes the cursor commands from the `tea` package. The cursor commands are now part of the `Frame` type. The cursor commands were removed because they were not idiomatic and were not flexible enough to support additional cursor settings. API: ```go // Model contains the program's state as well as its core functions. type Model interface { // Init is the first function that will be called. It returns an optional // initial command. To not perform an initial command return nil. Init() (Model, Cmd) // Update is called when a message is received. Use it to inspect messages // and, in response, update the model and/or send a command. Update(Msg) (Model, Cmd) // View renders the program's UI, which is just a [fmt.Stringer]. The view // is rendered after every Update. // The main model can return a [Frame] to set the cursor position and // style. View() fmt.Stringer } // Cursor represents a cursor on the terminal screen. type Cursor struct { // Position is a [Position] that determines the cursor's position on the // screen relative to the top left corner of the frame. Position Position // Color is a [color.Color] that determines the cursor's color. Color color.Color // Shape is a [CursorShape] that determines the cursor's style. Shape CursorShape // Blink is a boolean that determines whether the cursor should blink. Blink bool } // NewCursor returns a new cursor with the default settings and the given // position. func NewCursor(x, y int) *Cursor { return &Cursor{ Position: Position{X: x, Y: y}, Color: nil, Shape: CursorBlock, Blink: true, } } // Frame represents a single frame of the program's output. type Frame struct { // Content contains the frame's content. This is the only required field. // It should be a string of text and ANSI escape codes. Content string // Cursor contains cursor settings for the frame. If nil, the cursor will // be hidden. Cursor *Cursor } // NewFrame creates a new frame with the given content. func NewFrame(content string) Frame { return Frame{Content: content} } // String implements the fmt.Stringer interface for [Frame]. func (f Frame) String() string { return f.Content } ``` Supersedes: #1293
- Loading branch information
Showing
64 changed files
with
358 additions
and
260 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
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
Oops, something went wrong.