text
stringlengths 0
1.36k
|
---|
Therefore I decided to implement a separate tea.Cmd here, which is to say a function that returns a tea.Msg , to sleep for half a second and then use the latest terminal size values to render the user’s final report in a way that correctly takes up the full height and width of the current terminal.
|
It looks like this, and I return this command when the app reaches its displayingResults phase:
|
The delay is barely perceptible to the user, if at all, but the result is that the user’s final score report is rendered within the Viewport correctly — taking up the whole available height and width of the current terminal.
|
## Creating separate navigation functions
|
I mentioned above that, when I started working with Bubbletea, I ran into frequent crashes due to my mishandling of a slice data type that backed a collection the UI would iterate through.
|
For example, you can imagine rendering a simple list in a Bubbletea program, and allowing the user to move their “cursor” up and down the list to select an item.
|
Imagine the model’s cursor field is an int , and that it is incremented each time the user presses the up button or the letter k . Imagine that you have wired up the enter button to select the item in the backing slice at the index of whatever value cursor is currently set to.
|
In this scenario, it’s easy to accidentally advance the cursor beyond the bounds of the model’s backing slice, leading to a panic when you press enter, because you’re trying to access an index in the slice that is out of bounds.
|
I tackled this problem by creating separate methods on the model for each of the navigational directions: `
|
Within each of these directional helper methods, I encapsulate all of the logic to safely increment the internal value for cursor — including re-setting it to a reasonable value if it should somehow exceed the bounds of its backing slice:
|
Here’s the example implementation of SelectionCursorUp :
|
If we somehow end up with a cursor value that exceeds the actual length of the backing slice, we just set the cursor to 0. The inverse logic is implemented for all other directional navigation functionality.
|
## Split your View method into many sub-views
|
As you can see here in my View method, I’m returning several different sub-views depending on the “mode” my Bubbletea app is running in.
|
There are several boolean values the model has to represent whether a particular phase of the app is running or not, and all the toggling between event states happens in the Update function’s appropriate cases.
|
I found that when working with multiple views, it’s nice to have your sub-views split out into separate functions that you can then conditionally return depending on your own app’s requirements.
|
This would also work well with a switch statement.
|
That’s all for this post! Thanks for reading and keep an eye out for the next post in the series!
|
## Most developers don't understand git...
|
Yet everyone needs git. Learning git well is one of the best ways to differentiate yourself to hiring managers.
|
## Git is your save button!
|
Never lose work once you learn how to use git. While git has a lot of complex advanced features and configuration options, learning the basic workflow for being effective doesn't take long, and this course will show you everything you need to know with a hands-on project.
|
Git Going
|
start course
|
## Git configuration
|
Configuring git is important.
|
## Most developers don't know git well
|
And this is a great thing for you. You can differentiate yourself to hiring managers, potential teams considering you, and anyone else you collaborate with professionally by demonstrating a strong grasp of git.
|
Some day, you'll need to perform a complex git surgery, likely under pressure, in order to fix something or restore a service. You'll be glad then that you practiced and learned git well now.
|
## Why Version Control?
|
Version control is super important!
|
## Git vs GitHub
|
Git and GitHub are intertwined but different.
|
is
|
your
|
save
|
button
|
## Git is your save button
|
That's why it's so critical to learn the basics well. Git enables you to save your work, have multiple copies of your code distributed around to other machines, so that you can recover even if you spill tea all over your laptop, and professionally share code and collaborate with other develeopers.
|
## Learning git pays off
|
Learning git is very important.
|
## Get your first full stack app on your portfolio
|
Always wanted to build a complete web app but aren't sure how to get started? This course is for you.
|
Your first full stack app - start course
|
## Don't stick to the default terminal
|
Have you ever heard of ZSH? Alacrity? Butterfish?
|
In this course you'll learn to install, configure and leverage powerful custom shells to supercharge your command line skills.
|
Coming out of your shell - start course
|
## Cusomization makes it yours
|
By changing your shell, you not only make your computer more comfortable, but perhaps even more importantly, you learn about Unix, commands, tty, and more.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.