@@ -10,6 +10,7 @@ import (
1010 tea "github.com/charmbracelet/bubbletea"
1111 "github.com/charmbracelet/lipgloss"
1212 devlog "github.com/prime-run/go-typer/log"
13+ "github.com/prime-run/go-typer/utils"
1314 "github.com/spf13/cobra"
1415)
1516
@@ -25,7 +26,7 @@ type LoadingModel struct {
2526 progressBar progress.Model
2627}
2728
28- func NewLoadingModel () * LoadingModel {
29+ func NewLoadingModel (customText string ) * LoadingModel {
2930 p := progress .New (
3031 progress .WithDefaultGradient (),
3132 progress .WithWidth (60 ),
@@ -37,13 +38,14 @@ func NewLoadingModel() *LoadingModel {
3738 progress : 0.0 ,
3839 lastTick : time .Now (),
3940 progressBar : p ,
41+ text : customText ,
4042 }
4143}
4244
4345func (m * LoadingModel ) Init () tea.Cmd {
4446 return tea .Batch (
4547 InitGlobalTick (),
46- fetchTextCmd (),
48+ fetchTextCmd (m . text ),
4749 )
4850}
4951
@@ -96,7 +98,19 @@ func (m *LoadingModel) View() string {
9698 content )
9799}
98100
99- func fetchTextCmd () tea.Cmd {
101+ // fetchTextCmd fetches random text based on the current settings or uses a custom text if provided.
102+ func fetchTextCmd (customText string ) tea.Cmd {
103+ // If a custom text is provided, use it directly
104+ if customText != "" {
105+ return func () tea.Msg {
106+ if len (customText ) > 300 {
107+ customText = utils .FormatText (customText [:300 ]) // Limit to 300 characters
108+ }
109+ return textFetchedMsg (customText )
110+ }
111+ }
112+
113+ // Otherwise, fetch random text based on the current settings
100114 return func () tea.Msg {
101115 textCount := map [string ]int {
102116 TextLengthShort : 1 ,
@@ -111,7 +125,7 @@ func fetchTextCmd() tea.Cmd {
111125
112126 estimatedTotalLen := count * 200
113127
114- for i := 0 ; i < count ; i ++ {
128+ for range count {
115129 text := GetRandomText ()
116130 texts = append (texts , text )
117131 }
@@ -131,18 +145,18 @@ func fetchTextCmd() tea.Cmd {
131145}
132146
133147func StartLoading (cmd * cobra.Command , args []string ) {
134- StartLoadingWithOptions ("block" )
148+ StartLoadingWithOptions ("block" , "" )
135149}
136150
137- func StartLoadingWithOptions (cursorTypeStr string ) {
151+ func StartLoadingWithOptions (cursorTypeStr string , customText string ) {
138152 selectedCursorType := BlockCursor
139153 if cursorTypeStr == "underline" {
140154 selectedCursorType = UnderlineCursor
141155 }
142156
143157 DefaultCursorType = selectedCursorType
144158
145- model := NewLoadingModel ()
159+ model := NewLoadingModel (customText )
146160 p := tea .NewProgram (model , tea .WithAltScreen ())
147161 if _ , err := p .Run (); err != nil {
148162 fmt .Println ("Oh no!" , err )
0 commit comments