Skip to content

Commit

Permalink
feat: add ability to customize prompt location
Browse files Browse the repository at this point in the history
  • Loading branch information
kencx committed Jul 23, 2022
1 parent 4e836e0 commit 019f6ca
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ By default, the following options are included.
| `sort_keys` | `false` | Sort keys alphabetically |
| `title` | `""` | Title text |
| `prompt` | `"keys > "` | Search bar prompt text |
| `prompt_location` | `"top"` | Location of search bar: `top, bottom` |
| `placeholder` | `"..."` | Search bar placeholder text |
| `prefix_sep` | `";"` | Separator symbol between prefix and key |
| `sep_width` | `4` | Separation width between columns |
Expand Down
54 changes: 28 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ type Config struct {
}

type Settings struct {
KeybPath string `yaml:"keyb_path"`
Debug bool
Reverse bool
Mouse bool
SortKeys bool `yaml:"sort_keys"`
Title string
Prompt string
Placeholder string
PrefixSep string `yaml:"prefix_sep"`
SepWidth int `yaml:"sep_width"`
Margin int
Padding int
BorderStyle string `yaml:"border"`
KeybPath string `yaml:"keyb_path"`
Debug bool
Reverse bool
Mouse bool
SortKeys bool `yaml:"sort_keys"`
Title string
Prompt string
PromptLocation string `yaml:"prompt_location"`
Placeholder string
PrefixSep string `yaml:"prefix_sep"`
SepWidth int `yaml:"sep_width"`
Margin int
Padding int
BorderStyle string `yaml:"border"`
}

type Color struct {
Expand Down Expand Up @@ -163,19 +164,20 @@ func generateDefaultConfig() (*Config, error) {

return &Config{
Settings: Settings{
KeybPath: keybPath,
Debug: false,
Reverse: false,
Mouse: true,
SortKeys: false,
Title: "",
Prompt: "keys > ",
Placeholder: "...",
PrefixSep: ";",
SepWidth: 4,
Margin: 0,
Padding: 1,
BorderStyle: "hidden",
KeybPath: keybPath,
Debug: false,
Reverse: false,
Mouse: true,
SortKeys: false,
Title: "",
Prompt: "keys > ",
PromptLocation: "top",
Placeholder: "...",
PrefixSep: ";",
SepWidth: 4,
Margin: 0,
Padding: 1,
BorderStyle: "hidden",
},
Color: Color{
FilterFg: "#FFA066",
Expand Down
27 changes: 14 additions & 13 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ func TestCreateConfigDir(t *testing.T) {
func TestParse(t *testing.T) {
want := &Config{
Settings: Settings{
KeybPath: "./custom.yml",
Debug: true,
Reverse: true,
Mouse: false,
SortKeys: true,
Title: "",
Prompt: "keys > ",
Placeholder: "...",
PrefixSep: ";",
SepWidth: 4,
Margin: 1,
Padding: 1,
BorderStyle: "normal",
KeybPath: "./custom.yml",
Debug: true,
Reverse: true,
Mouse: false,
SortKeys: true,
Title: "",
Prompt: "keys > ",
PromptLocation: "bottom",
Placeholder: "...",
PrefixSep: ";",
SepWidth: 4,
Margin: 1,
Padding: 1,
BorderStyle: "normal",
},
Color: Color{
FilterFg: "#FFA066",
Expand Down
1 change: 1 addition & 0 deletions testdata/testconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ settings:
sort_keys: true
title: ""
prompt: 'keys > '
prompt_location: "bottom"
placeholder: '...'
prefix_sep: ;
sep_width: 4
Expand Down
12 changes: 7 additions & 5 deletions ui/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ type Model struct {
cursor int
maxRows int // max number of rows regardless of filterState

margin int
padding int
scrollOffset int
border lipgloss.Style
counterStyle lipgloss.Style
margin int
padding int
scrollOffset int
border lipgloss.Style
counterStyle lipgloss.Style
promptLocation string
}

func New(t *table.Model, config *config.Config) Model {
Expand Down Expand Up @@ -83,6 +84,7 @@ func (m *Model) configure(c *config.Config) {
m.title = c.Title
m.debug = c.Debug
m.keys = CreateKeyMap(c.Keys)
m.promptLocation = c.PromptLocation

m.margin = c.Margin
m.padding = c.Padding
Expand Down
23 changes: 17 additions & 6 deletions ui/list/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ func (m *Model) View() string {

counter := formCounter(m)

view := lipgloss.JoinVertical(
lipgloss.Left,
m.searchBar.View(),
counter,
m.viewport.View(),
)
var view string

if m.promptLocation == "bottom" {
view = lipgloss.JoinVertical(
lipgloss.Left,
m.viewport.View(),
counter,
m.searchBar.View(),
)
} else {
view = lipgloss.JoinVertical(
lipgloss.Left,
m.searchBar.View(),
counter,
m.viewport.View(),
)
}

style := m.border.
Margin(m.margin).
Expand Down

0 comments on commit 019f6ca

Please sign in to comment.