@@ -75,13 +75,12 @@ func (m getCollectionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7575}
7676
7777func (m getCollectionModel ) View () tea.View {
78- s := m .get .book .styles
79- t := m .get .book .tmpls
80-
81- if m .action == "list" && m .get .book .form .State == huh .StateCompleted {
82- return renderCompletedView (s , t , "collection-list" , m .get .shelf )
78+ if m .get .book .form .State == huh .StateCompleted || m .get .book .width <= 0 {
79+ return altScreenView ("" )
8380 }
8481
82+ s := m .get .book .styles
83+
8584 // Form (left side)
8685 v := strings .TrimSuffix (m .get .book .form .View (), "\n \n " )
8786 form := s .Form .Render (v )
@@ -100,13 +99,7 @@ func (m getCollectionModel) View() tea.View {
10099
101100 currentShelf = lipglossDimmer (s .StatusHeader , "Picked Shelf" , displayShelf )
102101
103- const statusWidth = 68
104- statusMarginLeft := m .get .book .width - statusWidth - lipgloss .Width (form ) - s .Status .GetMarginRight ()
105- status = s .Status .
106- Height (10 ).
107- Width (statusWidth ).
108- MarginLeft (statusMarginLeft ).
109- Render (currentShelf )
102+ status = m .get .book .statusPanel (form , currentShelf , 10 )
110103 }
111104
112105 errors := m .get .book .form .Errors ()
@@ -120,12 +113,21 @@ func (m getCollectionModel) View() tea.View {
120113 if len (errors ) > 0 {
121114 footer = m .get .book .appErrorBoundaryView ("" )
122115 }
123- return tea .NewView (s .Base .Render (header + "\n " + body + "\n \n " + footer ))
116+ return altScreenView (s .Base .Render (header + "\n " + body + "\n \n " + footer ))
117+ }
118+
119+ // ResultView returns the completion output for the caller to print after the
120+ // program exits.
121+ func (m getCollectionModel ) ResultView () string {
122+ if m .get .book .form .State != huh .StateCompleted || m .action != "list" {
123+ return ""
124+ }
125+ return renderCompletedView (m .get .book .styles , m .get .book .tmpls , "collection-list" , m .get .shelf ).Content
124126}
125127
126128// GetCollectionForm to be used for editing descriptions/names in future
127129func GetCollectionForm (bs * book.BookShelves , config * book.Config , action string ) getCollectionModel {
128- m := collectionModel {book : & Book {width : maxWidth }}
130+ m := collectionModel {book : & Book {width : 0 }}
129131 m .book .styles = NewStyles (config )
130132 m .book .tmpls = config .Templates
131133 m .book .shelves = bs
@@ -240,56 +242,57 @@ func (m editCollectionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
240242}
241243
242244func (m editCollectionModel ) View () tea.View {
245+ if m .editor .book .form .State == huh .StateCompleted || m .editor .book .width <= 0 {
246+ return altScreenView ("" )
247+ }
248+
243249 s := m .editor .book .styles
244- t := m .editor .book .tmpls
245-
246- switch m .editor .book .form .State {
247- case huh .StateCompleted :
248- return renderCompletedView (s , t , "collection-add" , m .editor .collection )
249- default :
250- // Form (left side)
251- v := strings .TrimSuffix (m .editor .book .form .View (), "\n \n " )
252- form := s .Form .Render (v )
253-
254- // Status (right side)
255- var status string
256- {
257- var (
258- editShelfName string
259- editCollectionName string
260- editCollectionDesc string
261- )
262-
263- editShelfName = s .StatusHeader .Render ("Picked Shelf" ) + "\n " + m .editor .shelf .Name + "\n \n "
264- editCollectionName = lipglossDimmer (s .StatusHeader , "Collection Name" , m .editor .collection .Name )
265- editCollectionDesc = lipglossDimmer (s .StatusHeader , "Collection Description" , m .editor .collection .Description )
266-
267- const statusWidth = 68
268- statusMarginLeft := m .editor .book .width - statusWidth - lipgloss .Width (form ) - s .Status .GetMarginRight ()
269- status = s .Status .
270- Height (10 ).
271- Width (statusWidth ).
272- MarginLeft (statusMarginLeft ).
273- Render (editShelfName + editCollectionName + editCollectionDesc )
274- }
275250
276- errors := m .editor .book .form .Errors ()
277- header := m .editor .book .appBoundaryView ("book collection editing system" )
278- if len (errors ) > 0 {
279- header = m .editor .book .appErrorBoundaryView (m .editor .book .errorView ())
280- }
281- body := lipgloss .JoinHorizontal (lipgloss .Left , form , status )
251+ // Form (left side)
252+ v := strings .TrimSuffix (m .editor .book .form .View (), "\n \n " )
253+ form := s .Form .Render (v )
282254
283- footer := m .editor .book .appBoundaryView (m .editor .book .form .Help ().ShortHelpView (m .editor .book .form .KeyBinds ()))
284- if len (errors ) > 0 {
285- footer = m .editor .book .appErrorBoundaryView ("" )
286- }
287- return tea .NewView (s .Base .Render (header + "\n " + body + "\n \n " + footer ))
255+ // Status (right side)
256+ var status string
257+ {
258+ var (
259+ editShelfName string
260+ editCollectionName string
261+ editCollectionDesc string
262+ )
263+
264+ editShelfName = s .StatusHeader .Render ("Picked Shelf" ) + "\n " + m .editor .shelf .Name + "\n \n "
265+ editCollectionName = lipglossDimmer (s .StatusHeader , "Collection Name" , m .editor .collection .Name )
266+ editCollectionDesc = lipglossDimmer (s .StatusHeader , "Collection Description" , m .editor .collection .Description )
267+
268+ status = m .editor .book .statusPanel (form , editShelfName + editCollectionName + editCollectionDesc , 10 )
269+ }
270+
271+ errors := m .editor .book .form .Errors ()
272+ header := m .editor .book .appBoundaryView ("book collection editing system" )
273+ if len (errors ) > 0 {
274+ header = m .editor .book .appErrorBoundaryView (m .editor .book .errorView ())
275+ }
276+ body := lipgloss .JoinHorizontal (lipgloss .Left , form , status )
277+
278+ footer := m .editor .book .appBoundaryView (m .editor .book .form .Help ().ShortHelpView (m .editor .book .form .KeyBinds ()))
279+ if len (errors ) > 0 {
280+ footer = m .editor .book .appErrorBoundaryView ("" )
281+ }
282+ return altScreenView (s .Base .Render (header + "\n " + body + "\n \n " + footer ))
283+ }
284+
285+ // ResultView returns the completion output for the caller to print after the
286+ // program exits.
287+ func (m editCollectionModel ) ResultView () string {
288+ if m .editor .book .form .State != huh .StateCompleted {
289+ return ""
288290 }
291+ return renderCompletedView (m .editor .book .styles , m .editor .book .tmpls , "collection-add" , m .editor .collection ).Content
289292}
290293
291294func editCollectionForm (bs * book.BookShelves , shelf * book.Shelf , config * book.Config , action string ) editCollectionModel {
292- m := collectionModel {book : & Book {width : maxWidth }}
295+ m := collectionModel {book : & Book {width : 0 }}
293296 m .book .styles = NewStyles (config )
294297 m .book .tmpls = config .Templates
295298 m .book .shelves = bs
0 commit comments