@@ -10,7 +10,6 @@ import (
1010 "github.com/jr-k/d4s/internal/ui/common"
1111 "github.com/jr-k/d4s/internal/ui/components/view"
1212 "github.com/jr-k/d4s/internal/ui/dialogs"
13- "github.com/jr-k/d4s/internal/ui/styles"
1413)
1514
1615func (a * App ) PerformAction (action func (id string ) error , actionName string , color tcell.Color ) {
@@ -37,7 +36,7 @@ func (a *App) PerformAction(action func(id string) error, actionName string, col
3736 if len (ids ) == 1 {
3837 plural = ""
3938 }
40- a .SetFlashMessage (fmt .Sprintf (" [red] %s %d item%s..." , actionName , len (ids ), plural ), 10 * time . Minute )
39+ a .AppendFlashPending (fmt .Sprintf ("%s %d item%s..." , actionName , len (ids ), plural ))
4140
4241 a .RunInBackground (func () {
4342 var errs []string
@@ -58,15 +57,15 @@ func (a *App) PerformAction(action func(id string) error, actionName string, col
5857 a .StartAutoRefresh ()
5958
6059 if len (errs ) > 0 {
61- a .SetFlashMessage (fmt .Sprintf (" [red] %s completed with errors" , actionName ), 3 * time . Second )
60+ a .AppendFlashError (fmt .Sprintf ("%s completed with errors" , actionName ))
6261 dialogs .ShowResultModal (a , actionName , len (ids )- len (errs ), errs )
6362 } else {
6463 plural := "s"
6564 if len (ids ) == 1 {
6665 plural = ""
6766 }
6867 // Show success message for 3 seconds
69- a .SetFlashMessage (fmt .Sprintf (" [#50fa7b] %s %d item%s done" , actionName , len (ids ), plural ), 1 * time . Second )
68+ a .AppendFlashSuccess (fmt .Sprintf ("%s %d item%s done" , actionName , len (ids ), plural ))
7069
7170 // Clear selection on success?
7271 view .SelectedIDs = make (map [string ]bool )
@@ -118,78 +117,6 @@ func (a *App) getSelectedID(v *view.ResourceView) (string, error) {
118117 return v .Data [dataIndex ].GetID (), nil
119118}
120119
121- func (a * App ) PerformDelete () {
122- page , _ := a .Pages .GetFrontPage ()
123- view , ok := a .Views [page ]
124-
125- if ! ok || view .RemoveFunc == nil {
126- return
127- }
128-
129- action := view .RemoveFunc
130-
131- ids , err := a .getTargetIDs (view )
132- if err != nil {
133- return
134- }
135-
136- label := ids [0 ]
137- if len (ids ) == 1 {
138- row , _ := view .Table .GetSelection ()
139- if row > 0 && row <= len (view .Data ) {
140- item := view .Data [row - 1 ]
141- if item .GetID () == ids [0 ] {
142- cells := item .GetCells ()
143- if len (cells ) > 1 {
144- label = fmt .Sprintf ("%s ([#00ffff]%s[yellow])" , label , cells [1 ])
145- }
146- }
147- }
148- } else if len (ids ) > 1 {
149- label = fmt .Sprintf ("%d items" , len (ids ))
150- }
151-
152- dialogs .ShowConfirmation (a , "DELETE" , label , func (force bool ) {
153- simpleAction := func (id string ) error {
154- return action (id , force , a )
155- }
156- // view.HighlightIDs(ids, styles.ColorStatusRed, styles.ColorStatusRedDarkBg, time.Second)
157- // view.DeferRefresh(time.Second)
158- a .PerformAction (simpleAction , "Deleting" , styles .ColorStatusRed )
159- })
160- a .UpdateShortcuts ()
161- }
162-
163- func (a * App ) PerformPrune () {
164- page , _ := a .Pages .GetFrontPage ()
165- view , ok := a .Views [page ]
166-
167- if ! ok || view .PruneFunc == nil {
168- a .Flash .SetText (fmt .Sprintf ("[yellow]Prune not available for %s" , page ))
169- return
170- }
171-
172- action := view .PruneFunc
173- // Capitalize page name for display (e.g. "images" -> "Images")
174- name := strings .Title (page )
175-
176- dialogs .ShowConfirmation (a , "PRUNE" , name , func (force bool ) {
177- a .Flash .SetText (fmt .Sprintf ("[yellow]Pruning %s..." , name ))
178- a .RunInBackground (func () {
179- err := action (a )
180- a .TviewApp .QueueUpdateDraw (func () {
181- if err != nil {
182- a .Flash .SetText (fmt .Sprintf ("[red]Prune Error: %v" , err ))
183- } else {
184- a .Flash .SetText (fmt .Sprintf ("[green]Pruned %s" , name ))
185- a .RefreshCurrentView ()
186- }
187- })
188- })
189- })
190- a .UpdateShortcuts ()
191- }
192-
193120func (a * App ) PerformCopy () {
194121 page , _ := a .Pages .GetFrontPage ()
195122 view , ok := a .Views [page ]
@@ -253,13 +180,13 @@ func (a *App) PerformCopy() {
253180
254181 // 5. Copy
255182 if err := a .CopyToClipboard (value ); err != nil {
256- a .AppendFlash (fmt .Sprintf ("[red]Copy error: %v" , err ))
183+ a .AppendFlashError (fmt .Sprintf ("%v" , err ))
257184 } else {
258185 preview := value
259186 if len (preview ) > 60 {
260187 preview = preview [:60 ] + "..."
261188 }
262- a .AppendFlash (fmt .Sprintf ("[black:#50fa7b] < copied: %s>[-] " , preview ))
189+ a .AppendFlashSuccess (fmt .Sprintf ("copied %s" , preview ))
263190 }
264191 a .UpdateShortcuts ()
265192}
0 commit comments