Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 5eeb1f3

Browse files
committed
Add confirmation message. Close #22
1 parent e80aee5 commit 5eeb1f3

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

actions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func actionViewPodsDelete(g *gocui.Gui, v *gocui.View) error {
7878
}
7979

8080
debug(g, "Delete pod: "+p)
81+
displayConfirmation(g, p+" pod deleted")
8182

8283
go viewPodsRefreshList(g)
8384

@@ -154,5 +155,6 @@ func actionViewNamespacesSelect(g *gocui.Gui, v *gocui.View) error {
154155
NAMESPACE = line
155156
go viewPodsRefreshList(g)
156157
actionGlobalToggleViewNamespaces(g, v)
158+
displayConfirmation(g, line+" namespace selected")
157159
return err
158160
}

main.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,32 @@ func hideError(g *gocui.Gui) {
301301
g.DeleteView("errors")
302302
}
303303

304-
// StringFormatBoth fg and bg colors
305-
// Thanks https://github.com/mephux/komanda-cli/blob/master/komanda/color/color.go
306-
func stringFormatBoth(fg, bg int, str string, args []string) string {
307-
return fmt.Sprintf("\x1b[48;5;%dm\x1b[38;5;%d;%sm%s\x1b[0m", bg, fg, strings.Join(args, ";"), str)
304+
// Display confirmation message
305+
func displayConfirmation(g *gocui.Gui, m string) error {
306+
lMaxX, lMaxY := g.Size()
307+
308+
if v, err := g.SetView("confirmation", -1, lMaxY-3, lMaxX, lMaxY-1); err != nil {
309+
if err != gocui.ErrUnknownView {
310+
return err
311+
}
312+
313+
// Settings
314+
v.Frame = false
315+
316+
// Content
317+
fmt.Fprintln(v, textPadCenter(m, lMaxX))
318+
319+
// Auto-hide message
320+
hide := func() {
321+
hideConfirmation(g)
322+
}
323+
time.AfterFunc(time.Duration(2)*time.Second, hide)
324+
}
325+
326+
return nil
308327
}
309328

310-
func frameText(text string) string {
311-
return stringFormatBoth(15, 0, text, []string{"1"})
329+
// Hide confirmation message
330+
func hideConfirmation(g *gocui.Gui) {
331+
g.DeleteView("confirmation")
312332
}

string.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
// Repeat string
9+
func timesString(str string, n int) (out string) {
10+
for i := 0; i < n; i++ {
11+
out += str
12+
}
13+
return
14+
}
15+
16+
// Text pad center
17+
func textPadCenter(s string, l int) string {
18+
pc := " "
19+
p := timesString(pc, (l/2)-len(s)/2)
20+
o := p + s + p
21+
if (len(s) < l) && (l < len(o)) {
22+
o = o[0:l]
23+
}
24+
return o
25+
}
26+
27+
// StringFormatBoth fg and bg colors
28+
// Thanks https://github.com/mephux/komanda-cli/blob/master/komanda/color/color.go
29+
func stringFormatBoth(fg, bg int, str string, args []string) string {
30+
return fmt.Sprintf("\x1b[48;5;%dm\x1b[38;5;%d;%sm%s\x1b[0m", bg, fg, strings.Join(args, ";"), str)
31+
}
32+
33+
// Frame text with colors
34+
func frameText(text string) string {
35+
return stringFormatBoth(15, 0, text, []string{"1"})
36+
}

views.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ func viewPodsAddLine(v *gocui.View, maxX int, name, ready, status, restarts, age
261261

262262
// View: Status bar
263263
func viewStatusBar(g *gocui.Gui, lMaxX int, lMaxY int) error {
264-
//-1, -1, lMaxX, 1
265264
if v, err := g.SetView("status", -1, lMaxY-2, lMaxX, lMaxY); err != nil {
266265
if err != gocui.ErrUnknownView {
267266
return err

0 commit comments

Comments
 (0)