Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
- improvement read from line
Browse files Browse the repository at this point in the history
- add arrow keys in search images panel
  • Loading branch information
skanehira committed Dec 25, 2018
1 parent d19255b commit f5c3d7f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $ bash build.sh
| all | change panel | <kbd>Tab</kbd> |
| all | quit | <kbd>Ctrl</kbd> + <kbd>q</kbd> |
| all | quit | <kbd>q</kbd> |
| list panels | next entry | <kbd>j</kbd> / <kbd>↓</kbd> |
| list panels | previous entry | <kbd>k</kbd> / <kbd>↑</kbd> |
| image list | pull image | <kbd>p</kbd> |
| image list | search images | <kbd>Ctrl</kbd> + <kbd>f</kbd> |
| image list | remove image | <kbd>d</kbd> |
Expand All @@ -70,15 +72,11 @@ $ bash build.sh
| image list | save image | <kbd>s</kbd> |
| image list | import image | <kbd>i</kbd> |
| image list | load image | <kbd>Ctrl</kbd> + <kbd>l</kbd> |
| image list | next image | <kbd>j</kbd> |
| image list | previous image | <kbd>k</kbd> |
| image list | remove dangling images | <kbd>Ctrl</kbd> + <kbd>d</kbd> |
| image list | refresh image list | <kbd>Ctrl</kbd> + <kbd>r</kbd> |
| image list | filter image | <kbd>f</kbd> |
| container list | inspect container | <kbd>Enter</kbd> / <kbd>o</kbd> |
| container list | remove container | <kbd>d</kbd> |
| container list | next container | <kbd>j</kbd> |
| container list | previous container | <kbd>k</kbd> |
| container list | start container | <kbd>u</kbd> |
| container list | stop container | <kbd>s</kbd> |
| container list | export container | <kbd>e</kbd> |
Expand All @@ -94,8 +92,6 @@ $ bash build.sh
| volume list | filter image | <kbd>f</kbd> |
| network list | inspect network | <kbd>Enter</kbd> / <kbd>o</kbd> |
| network list | remove network | <kbd>d</kbd> |
| network list | next netowrk | <kbd>j</kbd> |
| network list | previous network | <kbd>k</kbd> |
| pull image | pull image | <kbd>Enter</kbd> |
| pull image | close panel | <kbd>Esc</kbd> |
| create container | next input box | <kbd>↓</kbd> / <kbd>Tab</kbd> |
Expand All @@ -107,8 +103,8 @@ $ bash build.sh
| detail | page up | <kbd>u</kbd> |
| search images | search image | <kbd>Enter</kbd> |
| search images | close panel | <kbd>Esc</kbd> |
| images | next image | <kbd>j</kbd> |
| images | previous image | <kbd>k</kbd> |
| images | next image | <kbd>j</kbd> / <kbd>↓</kbd> |
| images | previous image | <kbd>k</kbd> / <kbd>↑</kbd> |
| images | pull image | <kbd>Enter</kbd> |
| images | close panel | <kbd>Esc</kbd> |
| create volume | close panel | <kbd>Esc</kbd> |
Expand Down
4 changes: 2 additions & 2 deletions panel/containerPanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *ContainerList) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Mo
return
}

c.filter = ReadLine(v, nil)
c.filter = ReadViewBuffer(v)

if v, err := c.View(c.name); err == nil {
c.GetContainerList(v)
Expand Down Expand Up @@ -571,7 +571,7 @@ func (c *ContainerList) Filter(g *gocui.Gui, lv *gocui.View) error {
c.filter = ""
} else {
lv.SetCursor(0, 0)
c.filter = ReadLine(v, nil)
c.filter = ReadViewBuffer(v)
}
if v, err := c.View(c.name); err == nil {
c.GetContainerList(v)
Expand Down
21 changes: 13 additions & 8 deletions panel/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ func (gui *Gui) SetKeyBindingToPanel(panel string) {
if err := gui.SetKeybinding(panel, 'h', gocui.ModNone, gui.prePanel); err != nil {
panic(err)
}
if err := gui.SetKeybinding(panel, gocui.KeyArrowLeft, gocui.ModNone, gui.prePanel); err != nil {
panic(err)
}
if err := gui.SetKeybinding(panel, 'l', gocui.ModNone, gui.nextPanel); err != nil {
panic(err)
}
if err := gui.SetKeybinding(panel, gocui.KeyArrowRight, gocui.ModNone, gui.nextPanel); err != nil {
panic(err)
}
if err := gui.SetKeybinding(panel, gocui.KeyTab, gocui.ModNone, gui.nextPanel); err != nil {
panic(err)
}
Expand Down Expand Up @@ -369,7 +375,7 @@ func CursorDown(g *gocui.Gui, v *gocui.View) error {
cx, cy := v.Cursor()
nexty := cy + 1

line := ReadLine(v, &nexty)
line := ReadLineY(v, nexty)
if line == "" {
return nil
}
Expand Down Expand Up @@ -430,17 +436,16 @@ func PageUp(g *gocui.Gui, v *gocui.View) error {
return nil
}

func ReadLine(v *gocui.View, y *int) string {
if y == nil {
_, ny := v.Cursor()
y = &ny
}

str, err := v.Line(*y)
func ReadLineY(v *gocui.View, y int) string {
str, err := v.Line(y)

if err != nil {
return ""
}

return strings.Trim(str, " ")
}

func ReadViewBuffer(v *gocui.View) string {
return strings.Replace(v.ViewBuffer(), "\n", "", -1)
}
4 changes: 2 additions & 2 deletions panel/imagePanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (i *ImageList) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifi
return
}

i.filter = ReadLine(v, nil)
i.filter = ReadViewBuffer(v)

if v, err := i.View(i.name); err == nil {
i.GetImageList(v)
Expand Down Expand Up @@ -692,7 +692,7 @@ func (i *ImageList) Filter(g *gocui.Gui, lv *gocui.View) error {
i.filter = ""
} else {
lv.SetCursor(0, 0)
i.filter = ReadLine(v, nil)
i.filter = ReadViewBuffer(v)
}
if v, err := i.View(i.name); err == nil {
i.GetImageList(v)
Expand Down
4 changes: 2 additions & 2 deletions panel/networkPanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (n *NetworkList) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modi
return
}

n.filter = ReadLine(v, nil)
n.filter = ReadViewBuffer(v)

if v, err := n.View(n.name); err == nil {
n.GetNetworkList(v)
Expand Down Expand Up @@ -164,7 +164,7 @@ func (n *NetworkList) Filter(g *gocui.Gui, nv *gocui.View) error {
n.filter = ""
} else {
nv.SetCursor(0, 0)
n.filter = ReadLine(v, nil)
n.filter = ReadViewBuffer(v)
}
if v, err := n.View(n.name); err == nil {
n.GetNetworkList(v)
Expand Down
2 changes: 1 addition & 1 deletion panel/searchImagePanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *SearchImage) SwitchToResult(g *gocui.Gui, v *gocui.View) error {
}

func (s *SearchImage) SearchImage(g *gocui.Gui, v *gocui.View) error {
name := ReadLine(v, nil)
name := ReadViewBuffer(v)

if name != "" {
g.Update(func(g *gocui.Gui) error {
Expand Down
6 changes: 6 additions & 0 deletions panel/searchImageResultPanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ func (s *SearchImageResult) SetKeyBinding() {
if err := s.SetKeybinding(s.name, 'j', gocui.ModNone, CursorDown); err != nil {
panic(err)
}
if err := s.SetKeybinding(s.name, gocui.KeyArrowDown, gocui.ModNone, CursorDown); err != nil {
panic(err)
}
if err := s.SetKeybinding(s.name, 'k', gocui.ModNone, CursorUp); err != nil {
panic(err)
}
if err := s.SetKeybinding(s.name, gocui.KeyArrowUp, gocui.ModNone, CursorUp); err != nil {
panic(err)
}
}

func (s *SearchImageResult) SwitchToSearch(g *gocui.Gui, v *gocui.View) error {
Expand Down
4 changes: 2 additions & 2 deletions panel/volumePanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (vl *VolumeList) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modi
return
}

vl.filter = ReadLine(v, nil)
vl.filter = ReadViewBuffer(v)

if v, err := vl.View(vl.name); err == nil {
vl.GetVolumeList(v)
Expand Down Expand Up @@ -337,7 +337,7 @@ func (vl *VolumeList) Filter(g *gocui.Gui, lv *gocui.View) error {
vl.filter = ""
} else {
lv.SetCursor(0, 0)
vl.filter = ReadLine(v, nil)
vl.filter = ReadViewBuffer(v)
}
if v, err := vl.View(vl.name); err == nil {
vl.GetVolumeList(v)
Expand Down

0 comments on commit f5c3d7f

Please sign in to comment.