Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/TNK-Studio/lazykube into main
Browse files Browse the repository at this point in the history
  • Loading branch information
elfgzp committed Nov 26, 2020
2 parents 8842dbc + c40d565 commit 13b4d59
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
10 changes: 4 additions & 6 deletions pkg/app/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
)

var (
cyclicViews = []string{clusterInfoViewName, namespaceViewName, serviceViewName, deploymentViewName, podViewName}

nextCyclicView = &guilib.Action{
Name: nextCyclicViewAction,
Keys: keyMap[nextCyclicViewAction],
Handler: nextCyclicViewHandler,
nextFunctionView = &guilib.Action{
Name: nextFunctionViewAction,
Keys: keyMap[nextFunctionViewAction],
Handler: nextFunctionViewHandler,
Mod: gocui.ModNone,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/app/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func newFilterDialog(
Title: title,
CanNotReturn: true,
AlwaysOnTop: true,
ZIndex: 0,
ZIndex: 10,
Clickable: true,
Editable: true,
MouseDisable: true,
Expand Down Expand Up @@ -260,7 +260,7 @@ func newFilterDialog(
}
filtered := &guilib.View{
Name: filteredViewName,
ZIndex: 1,
ZIndex: 20,
Clickable: true,
CanNotReturn: true,
AlwaysOnTop: true,
Expand Down
13 changes: 8 additions & 5 deletions pkg/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ const (
defaultCommand = "/bin/sh"
)

func nextCyclicViewHandler(gui *guilib.Gui, _ *guilib.View) error {
func nextFunctionViewHandler(gui *guilib.Gui, _ *guilib.View) error {
currentView := gui.CurrentView()
if currentView == nil {
return nil
}

var nextViewName string
for index, viewName := range cyclicViews {
for index, viewName := range functionViews {
if currentView.Name == viewName {
nextIndex := index + 1
if nextIndex >= len(cyclicViews) {
if nextIndex >= len(functionViews) {
nextIndex = 0
}
nextViewName = cyclicViews[nextIndex]
log.Logger.Debugf("nextCyclicViewHandler - nextViewName: %s", nextViewName)
nextViewName = functionViews[nextIndex]
log.Logger.Debugf("nextFunctionViewHandler - nextViewName: %s", nextViewName)
break
}
}
Expand Down Expand Up @@ -598,6 +598,7 @@ func runPodCommandInput(gui *guilib.Gui, namespace, podName, image string) error
return err
}
gui.Config.Mouse = false
gui.Config.Cursor = true
gui.Configure()
_ = termbox.Flush()

Expand Down Expand Up @@ -625,6 +626,8 @@ func runPodCommandInput(gui *guilib.Gui, namespace, podName, image string) error
return err
}
gui.Config.Mouse = true
gui.Config.Cursor = false
gui.Configure()
gui.Configure()
if err := gui.ReturnPreviousView(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
// All common actions name
nextCyclicViewAction = "nextCyclicView"
nextFunctionViewAction = "nextFunctionView"
backToPreviousViewAction = "backToPreviousView"
toNavigationAction = "toNavigation"
navigationArrowLeft = "navigationArrowLeft"
Expand Down Expand Up @@ -54,7 +54,7 @@ const (
var (
// All common actions key map.
keyMap = map[string][]interface{}{
nextCyclicViewAction: {gocui.KeyTab},
nextFunctionViewAction: {gocui.KeyTab},
backToPreviousViewAction: {gocui.KeyEsc},
toNavigationAction: {gocui.KeyEnter, gocui.KeyArrowRight, 'l'},
navigationArrowLeft: {gocui.KeyArrowLeft, 'k'},
Expand Down
12 changes: 6 additions & 6 deletions pkg/app/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
OnRender: renderClusterInfo,
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
changeContext,
newMoreActions(moreActionsMap[clusterInfoViewName]),
}),
Expand Down Expand Up @@ -66,7 +66,7 @@ var (
),
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
previousLine,
nextLine,
copySelectedLine,
Expand Down Expand Up @@ -198,7 +198,7 @@ var (
),
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
previousLine,
nextLine,
copySelectedLine,
Expand Down Expand Up @@ -263,7 +263,7 @@ var (
},
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
previousLine,
nextLine,
copySelectedLine,
Expand Down Expand Up @@ -297,7 +297,7 @@ var (
),
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
previousLine,
nextLine,
copySelectedLine,
Expand Down Expand Up @@ -366,7 +366,7 @@ func newCustomResourcePanel(resource string) *guilib.View {
},
Actions: guilib.ToActionInterfaceArr([]*guilib.Action{
toNavigation,
nextCyclicView,
nextFunctionView,
previousLine,
nextLine,
filterResource,
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func resourceListRender(_ *guilib.Gui, view *guilib.View) error {
}

func showPleaseSelected(view io.Writer, name string) {
_, err := fmt.Fprintf(view, "Please select a %s. ", name)
_, err := fmt.Fprintf(view, "Please select a %s.\n ", name)
if err != nil {
log.Logger.Warningf("showPleaseSelected - error %s", err)
}
Expand Down
33 changes: 26 additions & 7 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewGui(config config.GuiConfig, views ...*View) *Gui {

// ReRenderAll ReRenderAll
func (gui *Gui) ReRenderAll() {
gui.renderTimes += 1
gui.renderTimes++
for _, view := range gui.views {
view.ReRender()
}
Expand All @@ -79,7 +79,6 @@ func (gui *Gui) layout(*gocui.Gui) error {
}
gui.ReRenderAll()
gui.SortViewsByZIndex()
gui.SetAlwaysOnTopViews()
}

if err := gui.Clear(); err != nil {
Expand All @@ -105,7 +104,7 @@ func (gui *Gui) layout(*gocui.Gui) error {
return err
}

if gui.renderTimes < 0 {
if gui.renderTimes > 0 {
if err := gui.onRender(); err != nil {
return err
}
Expand All @@ -115,13 +114,16 @@ func (gui *Gui) layout(*gocui.Gui) error {
return err
}

gui.SetAlwaysOnTopViews()
return nil
}

func (gui *Gui) onRender() error {
if gui.OnRender != nil && gui.renderTimes < 0 {
gui.renderTimes--

if gui.OnRender != nil {
if err := gui.OnRender(gui); err != nil {
return nil
return err
}
}

Expand All @@ -131,7 +133,6 @@ func (gui *Gui) onRender() error {
return err
}
}
gui.renderTimes += 1
return nil
}

Expand Down Expand Up @@ -531,7 +532,25 @@ func (gui *Gui) SetViewOnTop(name string) (*View, error) {
if _, err := gui.g.SetViewOnTop(name); err != nil {
return nil, err
}
return gui.getView(name), nil

for i, view := range gui.views {
if view.Name == name {
s := append(gui.views[:i], gui.views[i+1:]...)
gui.views = append(s, view)
return view, nil
}
}

return nil, gocui.ErrUnknownView
}

func (gui *Gui) GetTopView() *View {
length := len(gui.views) - 1
if length < 1 {
return nil
}

return gui.views[length-1]
}

func (gui *Gui) getView(name string) *View {
Expand Down

0 comments on commit 13b4d59

Please sign in to comment.