Skip to content

Commit

Permalink
breaking: input history and typeahead need to be enabled per module/p…
Browse files Browse the repository at this point in the history
…lugin
  • Loading branch information
abenz1267 committed Jul 23, 2024
1 parent 3c84509 commit 0c7a106
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 121 deletions.
10 changes: 5 additions & 5 deletions config/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"width": 400
},
"search": {
"typeahead": true,
"force_keyboard_focus": true,
"icons": true,
"history": true,
Expand All @@ -41,12 +40,13 @@
"switcher_only": true
},
"commands": { "switcher_only": true },
"emojis": { "switcher_only": true },
"custom_commands": {},
"emojis": { "switcher_only": true, "history": true, "typeahead": true },
"finder": { "switcher_only": true },
"hyprland": { "context_aware_history": true },
"runner": { "Excludes": null, "Includes": null },
"ssh": { "switcher_only": true },
"runner": { "typeahead": true, "history": true },
"ssh": { "switcher_only": true, "history": true },
"switcher": { "prefix": "/" },
"websearch": {}
"websearch": { "engines": ["google"] }
}
}
62 changes: 31 additions & 31 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ var noFoundErr viper.ConfigFileNotFoundError
var defaultConfig []byte

type Config struct {
Terminal string `mapstructure:"terminal"`
IgnoreMouse bool `mapstructure:"ignore_mouse"`
SpecialLabels map[string]string `mapstructure:"special_labels"`
UI UI `mapstructure:"ui"`
List List `mapstructure:"list"`
Search Search `mapstructure:"search"`
ActivationMode ActivationMode `mapstructure:"activation_mode"`
Builtins Builtins `mapstructure:"builtins"`
Disabled []string `mapstructure:"disabled"`
IgnoreMouse bool `mapstructure:"ignore_mouse"`
List List `mapstructure:"list"`
Plugins []Plugin `mapstructure:"plugins"`
Builtins Builtins `mapstructure:"builtins"`
Search Search `mapstructure:"search"`
SpecialLabels map[string]string `mapstructure:"special_labels"`
Terminal string `mapstructure:"terminal"`
UI UI `mapstructure:"ui"`

// internal
IsService bool `mapstructure:"-"`
Enabled []string `mapstructure:"-"`
IsService bool `mapstructure:"-"`
}

type Builtins struct {
Expand All @@ -54,18 +54,20 @@ type CustomCommands struct {
}

type CustomCommand struct {
Name string `mapstructure:"name"`
Cmd string `mapstructure:"cmd"`
CmdAlt string `mapstructure:"cmd_alt"`
Name string `mapstructure:"name"`
Terminal bool `mapstructure:"terminal"`
}

type GeneralModule struct {
IsSetup bool `mapstructure:"-"`
History bool `mapstructure:"history"`
Placeholder string `mapstructure:"placeholder"`
Prefix string `mapstructure:"prefix"`
SpecialLabel string `mapstructure:"special_label"`
SwitcherOnly bool `mapstructure:"switcher_only"`
Typeahead bool `mapstructure:"typeahead"`
}

type Finder struct {
Expand All @@ -86,8 +88,8 @@ type Emojis struct {

type SSH struct {
GeneralModule `mapstructure:",squash"`
HostFile string `mapstructure:"host_file"`
ConfigFile string `mapstructure:"config_file"`
HostFile string `mapstructure:"host_file"`
}

type Websearch struct {
Expand All @@ -102,13 +104,13 @@ type Hyprland struct {

type Applications struct {
GeneralModule `mapstructure:",squash"`
Cache bool `mapstructure:"cache"`
Actions bool `mapstructure:"actions"`
Cache bool `mapstructure:"cache"`
}

type ActivationMode struct {
UseAlt bool `mapstructure:"use_alt"`
Disabled bool `mapstructure:"disabled"`
UseAlt bool `mapstructure:"use_alt"`
UseFKeys bool `mapstructure:"use_f_keys"`
}

Expand All @@ -120,67 +122,65 @@ type Clipboard struct {

type Runner struct {
GeneralModule `mapstructure:",squash"`
ShellConfig string `mapstructure:"shell_config"`
Excludes []string `mapstructure:"excludes"`
Includes []string `mapstructure:"includes"`
ShellConfig string `mapstructure:"shell_config"`
}

type Plugin struct {
GeneralModule `mapstructure:",squash"`
Name string `mapstructure:"name"`
SrcOnce string `mapstructure:"src_once"`
SrcOnceRefresh bool `mapstructure:"src_once_refresh"`
Src string `mapstructure:"src"`
Cmd string `mapstructure:"cmd"`
CmdAlt string `mapstructure:"cmd_alt"`
Terminal bool `mapstructure:"terminal"`
KeepSort bool `mapstructure:"keep_sort"`
Matching util.MatchingType `mapstructure:"matching"`
Name string `mapstructure:"name"`
Src string `mapstructure:"src"`
SrcOnce string `mapstructure:"src_once"`
SrcOnceRefresh bool `mapstructure:"src_once_refresh"`
Terminal bool `mapstructure:"terminal"`
}

type Search struct {
Delay int `mapstructure:"delay"`
Typeahead bool `mapstructure:"typeahead"`
ForceKeyboardFocus bool `mapstructure:"force_keyboard_focus"`
Icons bool `mapstructure:"icons"`
Spinner bool `mapstructure:"spinner"`
History bool `mapstructure:"history"`
MarginSpinner int `mapstructure:"margin_spinner"`
Placeholder string `mapstructure:"placeholder"`
Spinner bool `mapstructure:"spinner"`
}

type Icons struct {
Hide bool `mapstructure:"hide"`
Size int `mapstructure:"size"`
ImageSize int `mapstructure:"image_size"`
Size int `mapstructure:"size"`
Theme string `mapstructure:"theme"`
}

type UI struct {
Icons Icons `mapstructure:"icons"`
Orientation string `mapstructure:"orientation"`
Anchors Anchors `mapstructure:"anchors"`
Fullscreen bool `mapstructure:"fullscreen"`
IgnoreExclusive bool `mapstructure:"ignore_exclusive"`
Height int `mapstructure:"height"`
Horizontal string `mapstructure:"horizontal"`
Icons Icons `mapstructure:"icons"`
IgnoreExclusive bool `mapstructure:"ignore_exclusive"`
Margins Margins `mapstructure:"margins"`
Orientation string `mapstructure:"orientation"`
Vertical string `mapstructure:"vertical"`
Width int `mapstructure:"width"`
Height int `mapstructure:"height"`
Margins Margins `mapstructure:"margins"`
Anchors Anchors `mapstructure:"anchors"`
}

type Anchors struct {
Top bool `mapstructure:"top"`
Bottom bool `mapstructure:"bottom"`
Left bool `mapstructure:"left"`
Right bool `mapstructure:"right"`
Bottom bool `mapstructure:"bottom"`
Top bool `mapstructure:"top"`
}

type Margins struct {
Top int `mapstructure:"top"`
Bottom int `mapstructure:"bottom"`
End int `mapstructure:"end"`
Start int `mapstructure:"start"`
Top int `mapstructure:"top"`
}

type List struct {
Expand Down
38 changes: 21 additions & 17 deletions history/inputhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@ package history

import (
"path/filepath"
"slices"

"github.com/abenz1267/walker/util"
)

type InputHistory []string
type InputHistory map[string][]string

func (h InputHistory) SaveToInputHistory(input string) InputHistory {
i := slices.Index(h, input)
var inputhstry InputHistory

if i != -1 {
h = append(h[:i], h[i+1:]...)
func SaveInputHistory(module string, input string) {
if inputhstry == nil {
inputhstry = make(InputHistory)
}

h = append([]string{input}, h...)

if len(h) > 50 {
h = h[:50]
if _, ok := inputhstry[module]; !ok {
inputhstry[module] = []string{}
}

util.ToGob(&h, filepath.Join(util.CacheDir(), "inputhistory.gob"))
inputhstry[module] = append([]string{input}, inputhstry[module]...)

return h
util.ToGob(&inputhstry, filepath.Join(util.CacheDir(), "inputhistory_0.3.8.gob"))
}

func GetInputHistory() InputHistory {
file := filepath.Join(util.CacheDir(), "inputhistory.gob")
func GetInputHistory(module string) []string {
if inputhstry != nil {
return inputhstry[module]
}

file := filepath.Join(util.CacheDir(), "inputhistory_0.3.8.gob")

if inputhstry == nil {
inputhstry = make(InputHistory)
}

h := InputHistory{}
_ = util.FromGob(file, &h)
_ = util.FromGob(file, &inputhstry)

return h
return inputhstry[module]
}
8 changes: 8 additions & 0 deletions modules/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ type Application struct {
Actions []Entry `json:"actions,omitempty"`
}

func (a Applications) History() bool {
return a.general.History
}

func (a Applications) Typeahead() bool {
return a.general.Typeahead
}

func (a Applications) Placeholder() string {
if a.general.Placeholder == "" {
return "applications"
Expand Down
8 changes: 8 additions & 0 deletions modules/clipboard/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type ClipboardItem struct {
IsImg bool `json:"is_img,omitempty"`
}

func (c Clipboard) Typeahead() bool {
return false
}

func (c Clipboard) History() bool {
return false
}

func (c Clipboard) Entries(ctx context.Context, term string) []modules.Entry {
entries := []modules.Entry{}

Expand Down
8 changes: 8 additions & 0 deletions modules/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ type Commands struct {
entries []Entry
}

func (c Commands) History() bool {
return c.general.History
}

func (c Commands) Typeahead() bool {
return c.general.Typeahead
}

func (c Commands) IsSetup() bool {
return c.general.IsSetup
}
Expand Down
8 changes: 8 additions & 0 deletions modules/customcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ type CustomCommands struct {
entries []Entry
}

func (c CustomCommands) History() bool {
return c.general.History
}

func (c CustomCommands) Typeahead() bool {
return c.general.Typeahead
}

func (c CustomCommands) Entries(ctx context.Context, term string) (_ []Entry) {
return c.entries
}
Expand Down
8 changes: 8 additions & 0 deletions modules/dmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (d *Dmenu) Setup(cfg *config.Config) bool {

func (d *Dmenu) SetupData(cfg *config.Config) {}

func (Dmenu) Typeahead() bool {
return false
}

func (Dmenu) History() bool {
return false
}

func (d Dmenu) Placeholder() string {
if d.Separator == "" {
return "dmenu"
Expand Down
8 changes: 8 additions & 0 deletions modules/emojis/emojis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ type Emojis struct {
entries []modules.Entry
}

func (e Emojis) History() bool {
return e.general.History
}

func (e Emojis) Typeahead() bool {
return e.general.Typeahead
}

func (Emojis) KeepSort() bool {
return false
}
Expand Down
8 changes: 8 additions & 0 deletions modules/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type Finder struct {
general config.GeneralModule
}

func (f Finder) History() bool {
return f.general.History
}

func (f Finder) Typeahead() bool {
return f.general.Typeahead
}

func (Finder) KeepSort() bool {
return false
}
Expand Down
8 changes: 8 additions & 0 deletions modules/hyprland.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ type Hyprland struct {
windows map[string]uint
}

func (h Hyprland) History() bool {
return h.general.History
}

func (h Hyprland) Typeahead() bool {
return h.general.Typeahead
}

func (Hyprland) KeepSort() bool {
return false
}
Expand Down
8 changes: 8 additions & 0 deletions modules/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ type Plugin struct {
cachedOutput []byte
}

func (p Plugin) History() bool {
return p.General.History
}

func (p Plugin) Typeahead() bool {
return p.General.Typeahead
}

func (p Plugin) KeepSort() bool {
return p.General.KeepSort
}
Expand Down
Loading

0 comments on commit 0c7a106

Please sign in to comment.