Skip to content

Commit

Permalink
Code cleanup, small UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Voronkov committed Mar 17, 2021
1 parent 1eed32c commit bf98522
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
17 changes: 0 additions & 17 deletions cmd/tui/main.go

This file was deleted.

11 changes: 8 additions & 3 deletions lib/tui/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import (
)

var listTemplates = &promptui.SelectTemplates{
Label: "{{ . }}",
Label: "Select container to mount/unmount. {{ \"(use ^C to exit)\" | faint }}",
Active: "\U0000261E {{ if .Mounted }}{{ .ShortId | blue | bold }} {{ .Name | blue | bold }} (mounted){{ else }}{{ .ShortId | bold }} {{ .Name | bold }}{{ end }}",
Inactive: " {{ if .Mounted }}{{ .ShortId | blue }} {{ .Name | blue }} (mounted){{else}}{{ .ShortId }} {{ .Name }}{{ end }}",
Selected: "\U0000261E {{ .Id | red | cyan }} (selected)",
Details: `
------ Container ------
Id: {{ .Id }}
Name: {{ .Names }}
Image: {{ .Image }}
Command: {{ .Command }}
MountPoint: {{ .MountPoint }}`,
{{ if .Mounted }}MountPoint: {{ .MountPoint }}{{ end }}`,
}

var confirmUnmountTemplates = &promptui.SelectTemplates{
Label: "{{ \"Unmount\" | red }} container {{ .Id | bold}} from {{ .Mp | bold }}",
Active: "\U0000261E {{ . | bold }}",
Inactive: " {{ . }}",
}
12 changes: 10 additions & 2 deletions lib/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (t *Tui) list() error {
}

sel := promptui.Select{
Label: "Select container to mount",
Label: "Label",
Items: cts,
Templates: listTemplates,
}
Expand All @@ -56,17 +56,25 @@ func (t *Tui) list() error {
if ct.Mounted {
// ask to unmount
sel := promptui.Select{
Label: fmt.Sprintf("Unmount container %v from %v?", ct.ShortId, ct.MountPoint),
Label: struct {
Id string
Mp string
}{
Id: ct.ShortId,
Mp: ct.MountPoint,
},
Items: []string{
"Yes",
"No",
},
Templates: confirmUnmountTemplates,
}
i, _, err := sel.Run()
if err != nil {
return err
}
if i == 1 {
// No
return nil
}
// unmounting
Expand Down

0 comments on commit bf98522

Please sign in to comment.