-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add helps
- Loading branch information
Showing
13 changed files
with
438 additions
and
171 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
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,69 @@ | ||
package models | ||
|
||
import "github.com/charmbracelet/bubbles/key" | ||
|
||
// keyMap defines a set of keybindings. To work for help it must satisfy | ||
// key.Map. It could also very easily be a map[string]key.Binding. | ||
type orgKeyMap struct { | ||
Up key.Binding | ||
Down key.Binding | ||
Left key.Binding | ||
Right key.Binding | ||
Enter key.Binding | ||
Esc key.Binding | ||
Help key.Binding | ||
Quit key.Binding | ||
} | ||
|
||
// ShortHelp returns keybindings to be shown in the mini help view. It's part | ||
// of the key.Map interface. | ||
func (k orgKeyMap) ShortHelp() []key.Binding { | ||
k.Help.SetEnabled(true) | ||
return []key.Binding{k.Up, k.Down, k.Enter, k.Esc, k.Quit} | ||
} | ||
|
||
// FullHelp returns keybindings for the expanded help view. It's part of the | ||
// key.Map interface. | ||
func (k orgKeyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.Up, k.Down, k.Left, k.Right}, // first column | ||
{k.Enter, k.Esc, k.Help, k.Quit}, // second column | ||
} | ||
} | ||
|
||
func NewKeyMap() orgKeyMap { | ||
return orgKeyMap{ | ||
Up: key.NewBinding( | ||
key.WithKeys("up", "k"), | ||
key.WithHelp("↑/k", "up"), | ||
), | ||
Down: key.NewBinding( | ||
key.WithKeys("down", "j"), | ||
key.WithHelp("↓/j", "down"), | ||
), | ||
Left: key.NewBinding( | ||
key.WithKeys("left", "h"), | ||
key.WithHelp("←/h", "move left"), | ||
), | ||
Right: key.NewBinding( | ||
key.WithKeys("right", "l"), | ||
key.WithHelp("→/l", "move right"), | ||
), | ||
Enter: key.NewBinding( | ||
key.WithKeys("enter"), | ||
key.WithHelp("enter", "select"), | ||
), | ||
Esc: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "back"), | ||
), | ||
Help: key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "toggle help"), | ||
), | ||
Quit: key.NewBinding( | ||
key.WithKeys("q"), | ||
key.WithHelp("q", "quit"), | ||
), | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package models | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
func TestOrgModel_Update(t *testing.T) { | ||
type args struct { | ||
msg tea.Msg | ||
} | ||
tests := []struct { | ||
name string | ||
m OrgModel | ||
args args | ||
wantModel tea.Model | ||
wantCmd tea.Cmd | ||
}{ | ||
// TODO: Add more test cases. | ||
{"Quit KeyMsg", OrgModel{}, args{tea.KeyMsg{Type: tea.KeyCtrlC}}, OrgModel{}, tea.Quit}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotModel, gotCmd := tt.m.Update(tt.args.msg) | ||
if !reflect.DeepEqual(gotModel, tt.wantModel) { | ||
t.Errorf("OrganisationModel.Update() gotModel = %v, want %v", gotModel, tt.wantModel) | ||
} | ||
if reflect.ValueOf(gotCmd) != reflect.ValueOf(tt.wantCmd) { | ||
t.Errorf("OrganisationModel.Update() gotCmd = %v, want %v", gotCmd, tt.wantCmd) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOrgModel_NewOrgModel(t *testing.T) { | ||
type args struct { | ||
title string | ||
width int | ||
height int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{name: "Test NewOrgModel", args: args{title: "hub-bub", width: 1024, height: 768}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := NewOrgModel(tt.args.title, tt.args.width, tt.args.height) | ||
if got.Title != tt.args.title { | ||
t.Errorf("NewOrgModel title got = %v, want %v", got.Title, tt.args.title) | ||
} | ||
if got.width != tt.args.width { | ||
t.Errorf("NewOrgModel width got = %v, want %v", got.width, tt.args.width) | ||
} | ||
if got.height != tt.args.height { | ||
t.Errorf("NewOrgModel height got = %v, want %v", got.height, tt.args.height) | ||
} | ||
if got.keys.Enter.Enabled() != true { | ||
t.Errorf("NewOrgModel keys.Enter got = %v, want %v", got.keys.Enter.Enabled(), true) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
package models | ||
|
||
import "github.com/charmbracelet/bubbles/key" | ||
|
||
// keyMap defines a set of keybindings. To work for help it must satisfy | ||
// key.Map. It could also very easily be a map[string]key.Binding. | ||
type repoKeyMap struct { | ||
Up key.Binding | ||
Down key.Binding | ||
Left key.Binding | ||
Right key.Binding | ||
Filter key.Binding | ||
Esc key.Binding | ||
Quit key.Binding | ||
} | ||
|
||
// ShortHelp returns keybindings to be shown in the mini help view. It's part | ||
// of the key.Map interface. | ||
func (k repoKeyMap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.Left, k.Right, k.Esc, k.Quit} | ||
} | ||
|
||
// FullHelp returns keybindings for the expanded help view. It's part of the | ||
// key.Map interface. | ||
func (k repoKeyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.Up, k.Down, k.Left, k.Right}, // first column | ||
{k.Filter, k.Esc, k.Quit}, // second column | ||
} | ||
} | ||
|
||
func NewRepoKeyMap() repoKeyMap { | ||
return repoKeyMap{ | ||
Up: key.NewBinding( | ||
key.WithKeys("up", "k"), | ||
key.WithHelp("↑/k", "up"), | ||
), | ||
Down: key.NewBinding( | ||
key.WithKeys("down", "j"), | ||
key.WithHelp("↓/j", "down"), | ||
), | ||
Left: key.NewBinding( | ||
key.WithKeys("left", "h"), | ||
key.WithHelp("←/h", "prev tab"), | ||
), | ||
Right: key.NewBinding( | ||
key.WithKeys("right", "l"), | ||
key.WithHelp("→/l", "next tab"), | ||
), | ||
Filter: key.NewBinding( | ||
key.WithKeys("/"), | ||
key.WithHelp("/", "filter"), | ||
), | ||
Esc: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "back"), | ||
), | ||
Quit: key.NewBinding( | ||
key.WithKeys("q"), | ||
key.WithHelp("q", "quit"), | ||
), | ||
} | ||
} |
Oops, something went wrong.