-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tickertape): implement ticker tape model and functionality #687
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably use ansi.Truncate
and ansi.TruncateLeft
here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
to clarify, ansi is from here: https://pkg.go.dev/github.com/charmbracelet/x/ansi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
Ticker Tape Model in Bubble Tea
Overview
The
tickertape.Model
is used in a Bubble Tea application to create a scrolling ticker tape effect. Here's a summary of its usage:Initialization
Model
struct is initialized with text, position, and ticker width.Init
method starts the ticking process by returning a command that triggers periodic updates.Updating
Update
method handles incoming messages:WindowSizeMsg
updates the ticker width.tickMsg
updates the position of the ticker tape and schedules the next tick.UpdateText
method allows updating the text of the ticker tape.UpdateWidth
method allows updating the width of the ticker tape.Rendering
View
method generates the current view of the ticker tape based on the position and width.Integration
tickertape.Model
is created and managed.Update
method delegates relevant messages to the ticker tape model'sUpdate
method.View
method includes the ticker tape's view.Init
method. 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.