feat(tickertape): implement ticker tape model and functionality#687
feat(tickertape): implement ticker tape model and functionality#687nick-popovic wants to merge 2 commits intocharmbracelet:masterfrom
Conversation
|
|
||
| // View renders the ticker tape view. | ||
| func (m *Model) View() string { | ||
| ticker := m.Text[m.Position:] + m.Text[:m.Position] |
There was a problem hiding this comment.
should probably use ansi.Truncate and ansi.TruncateLeft here 🤔
There was a problem hiding this comment.
Yeah I was building an app to manage stock portfolios on the CLI and I thought this was an interesting addition
I'll have a look at your recommendation in more detail when I'm back from work (still learning how to use this framework 😅)
There was a problem hiding this comment.
cool!
to clarify, ansi is from here: https://pkg.go.dev/github.com/charmbracelet/x/ansi
There was a problem hiding this comment.
sorry, accidentally re-requested review XD - disregard
|
this looks fun! |
|
Agreed, this is a fun one. @nick-popovic do you have any example code we can use to help get a feel for this one? The URL above is returning a 404. |
|
@meowgorithm thanks for the catch! I edited the link in my main comment above. Here is the link to the following: |
| type Model struct { | ||
| Text string // The Text to be displayed in the ticker tape. | ||
| Position int // The current Position of the ticker tape. | ||
| TickerWidth int // The TickerWidth of the ticker tape display. |
There was a problem hiding this comment.
I'd make this private, rename it to width, and put getter and setters over it called Width and SetWidth.
| } | ||
|
|
||
| // UpdateText updates the Text of the ticker tape. | ||
| func (m *Model) UpdateText(newText string) { |
There was a problem hiding this comment.
I'd also make this a getter and setter: Text, SetText.
| } | ||
|
|
||
| // UpdateWidth updates the TickerWidth of the ticker tape. | ||
| func (m *Model) UpdateWidth(newWidth int) { |
There was a problem hiding this comment.
Per my comment about getters and setters, I'd change this function to a setter.
|
Thanks for your patient with this one, @nick-popovic. I think it's generally good and just needs a few final things to keep ticking from ticking out of control. I'd look at
|
Ticker Tape Model in Bubble Tea
Overview
The
tickertape.Modelis used in a Bubble Tea application to create a scrolling ticker tape effect. Here's a summary of its usage:Initialization
Modelstruct is initialized with text, position, and ticker width.Initmethod starts the ticking process by returning a command that triggers periodic updates.Updating
Updatemethod handles incoming messages:WindowSizeMsgupdates the ticker width.tickMsgupdates the position of the ticker tape and schedules the next tick.UpdateTextmethod allows updating the text of the ticker tape.UpdateWidthmethod allows updating the width of the ticker tape.Rendering
Viewmethod generates the current view of the ticker tape based on the position and width.Integration
tickertape.Modelis created and managed.Updatemethod delegates relevant messages to the ticker tape model'sUpdatemethod.Viewmethod includes the ticker tape's view.Initmethod. Example can be found here https://gist.github.com/nick-popovic/2f2dd4f94f5daff52b54edbbcd41164aExample
demo:
https://github.com/user-attachments/assets/9709d089-f7dd-45be-96d3-7bb96ec0c7b7
This setup allows the ticker tape to scroll text across the screen, updating its position at regular intervals.