Skip to content

Commit

Permalink
WIP Proof of concept to show a help dialog.
Browse files Browse the repository at this point in the history
'H' shows a dialog with the shortcuts
  • Loading branch information
ialbors committed Apr 6, 2016
1 parent 04f7ad4 commit 53cf16c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ui/simple/cui_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
Right string = "Right"
OpenCloseFolder string = "OpenCloseFolder"
ArtistAlbums string = "ArtistAlbums"
Help string = "Help"
)

var multipleKeysBuffer []rune
Expand Down Expand Up @@ -129,6 +130,9 @@ func (keyboard *Keyboard) defaultValues() {
if !keyboard.UsedFunctions[ArtistAlbums] {
keyboard.addKey("i", ArtistAlbums)
}
if !keyboard.UsedFunctions[Help] {
keyboard.addKey("H", Help)
}
}

func (keyboard *Keyboard) loadKeyFunctions() {
Expand Down Expand Up @@ -247,6 +251,10 @@ func keybindings() error {
keyboard.configureKey(playSelectedTrack, PlaySelectedTrack, VIEW_TRACKS)

addKeyBinding(&keyboard.Keys, newKeyMapping(gocui.KeyEnter, VIEW_STATUS, searchCommand))

// Help Keybinding
keyboard.configureKey(showHelp, Help, "")

keyboard.configureKey(mainNextViewLeft, Left, VIEW_TRACKS)
keyboard.configureKey(nextView, Left, VIEW_QUEUE)
keyboard.configureKey(nextView, Right, VIEW_PLAYLISTS)
Expand Down Expand Up @@ -463,6 +471,38 @@ func enableSearchInputCommand(g *gocui.Gui, v *gocui.View) error {
return nil
}

func showHelp(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size()
v2, _ := g.SetView("help_view", maxX/2-maxX/3, maxY/2-maxY/3,
maxX/2+maxX/3, maxY/2+maxY/3)
keyboard.configureKey(cursorUp, Up, v2.Name())
keyboard.configureKey(cursorDown, Down, v2.Name())

fmt.Fprintln(v2, "Shortcuts")
fmt.Fprintln(v2, "---------")
currentView := g.CurrentView()
g.SetCurrentView("help_view")

for k, v := range keyboard.ConfiguredKeys {
fmt.Fprintln(v2, k, ":", v)
}

/*for k,v := range keyboard.SequentialKeys {
fmt.Fprintln(v2, k,":", v)
}*/

if err := g.SetKeybinding("help_view", rune('q'), gocui.ModNone,
func(g *gocui.Gui, v3 *gocui.View) error {
g.DeleteView(v3.Name())
g.SetCurrentView(currentView.Name())
return nil
}); err != nil {
fmt.Println(err)
// handle error
}
return nil
}

func searchCommand(g *gocui.Gui, v *gocui.View) error {
// after user hit Enter, the typed command is at position -1
query, _ := gui.statusView.Line(-1)
Expand Down

0 comments on commit 53cf16c

Please sign in to comment.