M browser.go => browser.go +9 -4
@@ 614,10 614,10 @@ func (b *Browser) Input(prompt, input string, sensitive bool) (string, bool) {
return "", false
}
-func (b *Browser) FollowMode() {
+func (b *Browser) FollowMode() error {
text := b.tabs[b.tab].Text()
if text == nil {
- return
+ return nil
}
// Collect hints
@@ 637,12 637,16 @@ func (b *Browser) FollowMode() {
// Don't enter follow mode if there are no hints
if len(hints) == 0 {
- return
+ return nil
+ }
+
+ if len(b.config.Hints.Chars) == 0 {
+ return fmt.Errorf("no hint chars configured")
}
// Label hints
hintMap := map[string]Hint{}
- for i, label := range makeHintLabels("asdfjkl", len(hints)) {
+ for i, label := range makeHintLabels(b.config.Hints.Chars, len(hints)) {
hints[i].Label = label
hintMap[label] = hints[i]
}
@@ 651,6 655,7 @@ func (b *Browser) FollowMode() {
b.hints = hints
b.hintMap = hintMap
b.view.Invalidate()
+ return nil
}
// Based on Qutebrowser's 'scattered' hints algorithm.
M command.go => command.go +1 -2
@@ 170,7 170,6 @@ var commands = map[string]Command{
return nil
},
"follow": func(b *Browser, args ...string) error {
- b.FollowMode()
- return nil
+ return b.FollowMode()
},
}
M config.go => config.go +24 -0
@@ 11,6 11,7 @@ import (
type Config struct {
Display DisplayConfig
Search SearchConfig
+ Hints HintsConfig
Binds Binds
}
@@ 23,6 24,10 @@ type SearchConfig struct {
URL *url.URL
}
+type HintsConfig struct {
+ Chars string
+}
+
// Parse parses the settings from the given configuration.
func (c *Config) Parse(block scfg.Block) error {
for _, d := range block {
@@ 32,6 37,8 @@ func (c *Config) Parse(block scfg.Block) error {
err = c.Display.parse(d)
case "search":
err = c.Search.parse(d)
+ case "hints":
+ err = c.Hints.parse(d)
case "bind":
err = c.Binds.parse(d)
}
@@ 87,3 94,20 @@ func (c *SearchConfig) parse(d *scfg.Directive) error {
}
return nil
}
+
+func (c *HintsConfig) parse(d *scfg.Directive) error {
+ for _, d := range d.Children {
+ switch d.Name {
+ case "chars":
+ var chars string
+ if err := d.ParseParams(&chars); err != nil {
+ return err
+ }
+ if len(chars) < 2 {
+ return fmt.Errorf("directive %q: expected at least two chars", d.Name)
+ }
+ c.Chars = chars
+ }
+ }
+ return nil
+}
M config/astronaut.conf => config/astronaut.conf +4 -0
@@ 7,6 7,10 @@ search {
url gemini://geminispace.info/search
}
+hints {
+ chars asdfjkl
+}
+
bind : prompt
bind o prompt "open "
bind O newtab && prompt "open "