mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 01:32:33 +02:00
Init
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type DiffKeyMap struct {
|
||||
Clear key.Binding
|
||||
}
|
||||
|
||||
func newDiffKeyMap(cfg config.DiffKeys) DiffKeyMap {
|
||||
return DiffKeyMap{
|
||||
Clear: binding(cfg.Clear, "clear"),
|
||||
}
|
||||
}
|
||||
|
||||
func (d DiffKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{d.Clear}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type FindingsKeyMap struct {
|
||||
Dismiss key.Binding
|
||||
}
|
||||
|
||||
func newFindingsKeyMap(cfg config.FindingsKeys) FindingsKeyMap {
|
||||
return FindingsKeyMap{
|
||||
Dismiss: binding(cfg.Dismiss, "dismiss"),
|
||||
}
|
||||
}
|
||||
|
||||
func (f FindingsKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{f.Dismiss}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type GlobalKeyMap struct {
|
||||
Quit key.Binding
|
||||
OpenLogs key.Binding
|
||||
ToggleSidebar key.Binding
|
||||
Help key.Binding
|
||||
Up key.Binding
|
||||
Down key.Binding
|
||||
Left key.Binding
|
||||
Right key.Binding
|
||||
CycleFocus key.Binding
|
||||
CopyRequest key.Binding
|
||||
Escape key.Binding
|
||||
SendToReplay key.Binding
|
||||
ScrollUp key.Binding
|
||||
ScrollDown key.Binding
|
||||
SendToDiff key.Binding
|
||||
}
|
||||
|
||||
func newGlobalKeyMap(cfg config.GlobalKeys) GlobalKeyMap {
|
||||
return GlobalKeyMap{
|
||||
Quit: binding(cfg.Quit, "quit"),
|
||||
OpenLogs: binding(cfg.OpenLogs, "open logs"),
|
||||
ToggleSidebar: binding(cfg.ToggleSidebar, "toggle sidebar"),
|
||||
Help: binding(cfg.Help, "help"),
|
||||
Up: binding(cfg.Up, "up"),
|
||||
Down: binding(cfg.Down, "down"),
|
||||
Left: binding(cfg.Left, "scroll left"),
|
||||
Right: binding(cfg.Right, "scroll right"),
|
||||
CycleFocus: binding(cfg.CycleFocus, "cycle focus"),
|
||||
CopyRequest: binding(cfg.CopyRequest, "copy as..."),
|
||||
Escape: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
|
||||
SendToReplay: binding(cfg.SendToReplay, "send to replay"),
|
||||
ScrollUp: binding(cfg.ScrollUp, "scroll up"),
|
||||
ScrollDown: binding(cfg.ScrollDown, "scroll down"),
|
||||
SendToDiff: binding(cfg.SendToDiff, "send to diff"),
|
||||
}
|
||||
}
|
||||
|
||||
func (g GlobalKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{
|
||||
g.Up, g.Down, g.Left, g.Right, g.CycleFocus,
|
||||
g.Quit, g.Escape, g.Help,
|
||||
g.OpenLogs, g.ToggleSidebar, g.CopyRequest,
|
||||
g.SendToReplay, g.SendToDiff,
|
||||
g.ScrollUp, g.ScrollDown,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type HistoryKeyMap struct {
|
||||
DeleteEntry key.Binding
|
||||
DeleteAll key.Binding
|
||||
Filter key.Binding
|
||||
SqlQuery key.Binding
|
||||
}
|
||||
|
||||
func newHistoryKeyMap(cfg config.HistoryKeys) HistoryKeyMap {
|
||||
return HistoryKeyMap{
|
||||
DeleteEntry: binding(cfg.DeleteEntry, "delete entry"),
|
||||
DeleteAll: binding(cfg.DeleteAll, "delete all"),
|
||||
Filter: binding(cfg.Filter, "filter"),
|
||||
SqlQuery: binding(cfg.SqlQuery, "sql query"),
|
||||
}
|
||||
}
|
||||
|
||||
func (h HistoryKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{h.DeleteEntry, h.DeleteAll}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type HomeKeyMap struct {
|
||||
Open key.Binding
|
||||
Delete key.Binding
|
||||
Filter key.Binding
|
||||
}
|
||||
|
||||
func newHomeKeyMap(cfg config.HomeKeys) HomeKeyMap {
|
||||
return HomeKeyMap{
|
||||
Open: binding(cfg.Open, "open"),
|
||||
Delete: binding(cfg.Delete, "delete project"),
|
||||
Filter: binding(cfg.Filter, "filter"),
|
||||
}
|
||||
}
|
||||
|
||||
func (h HomeKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{h.Open, h.Delete, h.Filter}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type InterceptKeyMap struct {
|
||||
Forward key.Binding
|
||||
ForwardAll key.Binding
|
||||
Drop key.Binding
|
||||
DropAll key.Binding
|
||||
AutoForward key.Binding
|
||||
CaptureResponse key.Binding
|
||||
UndoEdits key.Binding
|
||||
Edit key.Binding
|
||||
EditExternal key.Binding
|
||||
}
|
||||
|
||||
func newInterceptKeyMap(cfg config.InterceptKeys) InterceptKeyMap {
|
||||
return InterceptKeyMap{
|
||||
Forward: binding(cfg.Forward, "forward"),
|
||||
ForwardAll: binding(cfg.ForwardAll, "forward all"),
|
||||
Drop: binding(cfg.Drop, "drop"),
|
||||
DropAll: binding(cfg.DropAll, "drop all"),
|
||||
AutoForward: binding(cfg.AutoForward, "auto forward"),
|
||||
CaptureResponse: binding(cfg.CaptureResponse, "capture response"),
|
||||
UndoEdits: binding(cfg.UndoEdits, "undo edits"),
|
||||
Edit: binding(cfg.Edit, "edit"),
|
||||
EditExternal: binding(cfg.EditExternal, "edit in $EDITOR"),
|
||||
}
|
||||
}
|
||||
|
||||
func (ic InterceptKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{
|
||||
ic.Forward, ic.ForwardAll,
|
||||
ic.Drop, ic.DropAll,
|
||||
ic.Edit, ic.EditExternal, ic.UndoEdits,
|
||||
ic.AutoForward, ic.CaptureResponse,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type KeyMap struct {
|
||||
Global GlobalKeyMap
|
||||
Intercept InterceptKeyMap
|
||||
Home HomeKeyMap
|
||||
History HistoryKeyMap
|
||||
Replay ReplayKeyMap
|
||||
Diff DiffKeyMap
|
||||
Findings FindingsKeyMap
|
||||
Plugins PluginsKeyMap
|
||||
}
|
||||
|
||||
var Keys *KeyMap
|
||||
|
||||
func Init(cfg *config.Config) {
|
||||
kb := cfg.Keybindings
|
||||
Keys = &KeyMap{
|
||||
Global: newGlobalKeyMap(kb.Global),
|
||||
Intercept: newInterceptKeyMap(kb.Intercept),
|
||||
Home: newHomeKeyMap(kb.Home),
|
||||
History: newHistoryKeyMap(kb.History),
|
||||
Replay: newReplayKeyMap(kb.Replay),
|
||||
Diff: newDiffKeyMap(kb.Diff),
|
||||
Findings: newFindingsKeyMap(kb.Findings),
|
||||
Plugins: newPluginsKeyMap(kb.Plugins),
|
||||
}
|
||||
}
|
||||
|
||||
func parseKeys(s string) []string {
|
||||
parts := strings.Split(s, ",")
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
if k := strings.TrimSpace(p); k != "" {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func binding(s, help string) key.Binding {
|
||||
keys := parseKeys(s)
|
||||
display := strings.Join(keys, "/")
|
||||
return key.NewBinding(key.WithKeys(keys...), key.WithHelp(display, help))
|
||||
}
|
||||
|
||||
// ChunkByWidth splits bindings into columns sized to fit the terminal width.
|
||||
func ChunkByWidth(bindings []key.Binding, termWidth int) [][]key.Binding {
|
||||
cols := termWidth / 26
|
||||
if cols < 2 {
|
||||
cols = 2
|
||||
} else if cols > 7 {
|
||||
cols = 7
|
||||
}
|
||||
perCol := (len(bindings) + cols - 1) / cols
|
||||
var out [][]key.Binding
|
||||
for i := 0; i < len(bindings); i += perCol {
|
||||
end := i + perCol
|
||||
if end > len(bindings) {
|
||||
end = len(bindings)
|
||||
}
|
||||
out = append(out, bindings[i:end])
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type PluginsKeyMap struct {
|
||||
Toggle key.Binding
|
||||
EditConfig key.Binding
|
||||
Filter key.Binding
|
||||
}
|
||||
|
||||
func newPluginsKeyMap(cfg config.PluginsKeys) PluginsKeyMap {
|
||||
return PluginsKeyMap{
|
||||
Toggle: binding(cfg.Toggle, "toggle"),
|
||||
EditConfig: binding(cfg.EditConfig, "edit config"),
|
||||
Filter: binding(cfg.Filter, "filter"),
|
||||
}
|
||||
}
|
||||
|
||||
func (p PluginsKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{p.Toggle, p.EditConfig, p.Filter}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"charm.land/bubbles/v2/key"
|
||||
"github.com/anotherhadi/spilltea/internal/config"
|
||||
)
|
||||
|
||||
type ReplayKeyMap struct {
|
||||
Send key.Binding
|
||||
Edit key.Binding
|
||||
EditExt key.Binding
|
||||
UndoEdits key.Binding
|
||||
Delete key.Binding
|
||||
DeleteAll key.Binding
|
||||
}
|
||||
|
||||
func newReplayKeyMap(cfg config.ReplayKeys) ReplayKeyMap {
|
||||
return ReplayKeyMap{
|
||||
Send: binding(cfg.Send, "send"),
|
||||
Edit: binding(cfg.Edit, "edit"),
|
||||
EditExt: binding(cfg.EditExt, "edit in $EDITOR"),
|
||||
UndoEdits: binding(cfg.UndoEdits, "undo edits"),
|
||||
Delete: binding(cfg.Delete, "delete"),
|
||||
DeleteAll: binding(cfg.DeleteAll, "delete all"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r ReplayKeyMap) Bindings() []key.Binding {
|
||||
return []key.Binding{r.Send, r.Edit, r.EditExt, r.UndoEdits, r.Delete, r.DeleteAll}
|
||||
}
|
||||
Reference in New Issue
Block a user