-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from ymtdzzz/feature/keymaps_for_each_panes
Display keymaps corresponding to focused pane, not page
- Loading branch information
Showing
8 changed files
with
289 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package component | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
) | ||
|
||
var keyMapRegex = regexp.MustCompile(`Rune|\[|\]`) | ||
|
||
type KeyMap struct { | ||
key *tcell.EventKey | ||
description string | ||
} | ||
|
||
type KeyMaps []*KeyMap | ||
|
||
func (m KeyMaps) keyTexts() string { | ||
keytexts := []string{} | ||
for _, v := range m { | ||
keytexts = append(keytexts, fmt.Sprintf(" [yellow]%s[white]: %s", | ||
keyMapRegex.ReplaceAllString(v.key.Name(), ""), | ||
v.description, | ||
)) | ||
} | ||
return strings.Join(keytexts, " | ") | ||
} | ||
|
||
type Focusable interface { | ||
SetFocusFunc(func()) *tview.Box | ||
} | ||
|
||
func newCommandList() *tview.TextView { | ||
return tview.NewTextView(). | ||
SetDynamicColors(true) | ||
} | ||
|
||
func attatchCommandList(commands *tview.TextView, p tview.Primitive) *tview.Flex { | ||
base := tview.NewFlex().SetDirection(tview.FlexRow) | ||
|
||
if commands == nil { | ||
return base | ||
} | ||
|
||
base.AddItem(p, 0, 1, true). | ||
AddItem(commands, 1, 1, false) | ||
|
||
return base | ||
} | ||
|
||
func registerCommandList(commands *tview.TextView, c Focusable, origFocusFn func(), keys KeyMaps) { | ||
if commands == nil { | ||
return | ||
} | ||
|
||
c.SetFocusFunc(func() { | ||
commands.SetText(keys.keyTexts()) | ||
|
||
if origFocusFn != nil { | ||
origFocusFn() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.