Include generic names in list
parent
afc162ef65
commit
7190fbb773
|
@ -25,5 +25,5 @@ sway/i3 + alacritty:
|
|||
|
||||
```
|
||||
bindsym $mod+d exec --no-startup-id alacritty --class gmenu --title gmenu --working-directory ~ -e gmenu
|
||||
for_window [app_id="gmenu"] floating enable; resize set 675 170
|
||||
for_window [app_id="gmenu"] floating enable; resize set 745 105
|
||||
```
|
||||
|
|
|
@ -31,7 +31,7 @@ func layout(g *gocui.Gui) error {
|
|||
if !hideAppDetails {
|
||||
listWidth = maxX / 2
|
||||
|
||||
if v, err := g.SetView("ex", maxX/2, 0, maxX, 2); err != nil {
|
||||
if v, err := g.SetView("ex", maxX/2, -1, maxX, 1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func layout(g *gocui.Gui) error {
|
|||
|
||||
updateEntries("")
|
||||
}
|
||||
if v, err := g.SetView("main", -1, -1, maxX, 1); err != nil {
|
||||
if v, err := g.SetView("main", -1, -1, listWidth, 1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -15,20 +15,26 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func updateEntries(buf string) {
|
||||
filteredEntries = nil
|
||||
type listEntry struct {
|
||||
*desktop.Entry
|
||||
|
||||
buf = strings.ToLower(strings.TrimSpace(buf))
|
||||
if buf == "" {
|
||||
if cap(filteredEntries) != len(desktopEntries) {
|
||||
filteredEntries = make([]*desktop.Entry, len(desktopEntries))
|
||||
originalIndex int
|
||||
label string
|
||||
}
|
||||
|
||||
func updateEntries(buf string) {
|
||||
buf = strings.TrimSpace(buf)
|
||||
emptyBuf := buf == ""
|
||||
|
||||
filteredEntries = nil
|
||||
if emptyBuf {
|
||||
for i, l := range desktopNames {
|
||||
filteredEntries = append(filteredEntries, &listEntry{originalIndex: i, label: l, Entry: desktopEntries[i]})
|
||||
}
|
||||
|
||||
copy(filteredEntries, desktopEntries)
|
||||
|
||||
sort.Slice(filteredEntries, func(i, j int) bool {
|
||||
ilower := strings.ToLower(filteredEntries[i].Name)
|
||||
jlower := strings.ToLower(filteredEntries[j].Name)
|
||||
ilower := strings.ToLower(filteredEntries[i].label)
|
||||
jlower := strings.ToLower(filteredEntries[j].label)
|
||||
|
||||
if ilower != jlower {
|
||||
return ilower < jlower
|
||||
|
@ -37,26 +43,24 @@ func updateEntries(buf string) {
|
|||
}
|
||||
})
|
||||
} else {
|
||||
matches := fuzzy.RankFindFold(buf, desktopNames)
|
||||
b := strings.ToLower(buf)
|
||||
|
||||
matches := fuzzy.RankFindFold(b, desktopNames)
|
||||
sort.Sort(matches)
|
||||
|
||||
if cap(filteredEntries) != len(matches) {
|
||||
filteredEntries = make([]*desktop.Entry, len(matches))
|
||||
}
|
||||
|
||||
for i, match := range matches {
|
||||
filteredEntries[i] = desktopEntries[match.OriginalIndex]
|
||||
filteredEntries = append(filteredEntries, &listEntry{originalIndex: i, label: desktopNames[match.OriginalIndex], Entry: desktopEntries[match.OriginalIndex]})
|
||||
}
|
||||
|
||||
sort.Slice(filteredEntries, func(i, j int) bool {
|
||||
ilower := strings.ToLower(filteredEntries[i].Name)
|
||||
jlower := strings.ToLower(filteredEntries[j].Name)
|
||||
ilower := strings.ToLower(filteredEntries[i].label)
|
||||
jlower := strings.ToLower(filteredEntries[j].label)
|
||||
|
||||
ipre := strings.HasPrefix(ilower, buf)
|
||||
jpre := strings.HasPrefix(jlower, buf)
|
||||
ipre := strings.HasPrefix(ilower, b)
|
||||
jpre := strings.HasPrefix(jlower, b)
|
||||
|
||||
icon := strings.Contains(ilower, buf)
|
||||
jcon := strings.Contains(jlower, buf)
|
||||
icon := strings.Contains(ilower, b)
|
||||
jcon := strings.Contains(jlower, b)
|
||||
|
||||
if ipre != jpre {
|
||||
return ipre && !jpre
|
||||
|
@ -75,35 +79,43 @@ func updateEntries(buf string) {
|
|||
list.SetCursor(0, 0)
|
||||
defer updateEntryInfo()
|
||||
|
||||
lastEntry := len(filteredEntries) - 1
|
||||
if buf != "" {
|
||||
lastEntry++
|
||||
}
|
||||
for i, entry := range filteredEntries {
|
||||
if i == lastEntry {
|
||||
fmt.Fprint(list, entry.Name)
|
||||
} else {
|
||||
fmt.Fprint(list, entry.Name+"\n")
|
||||
var printedEntry bool
|
||||
for _, entry := range filteredEntries {
|
||||
if printedEntry {
|
||||
fmt.Fprint(list, "\n")
|
||||
}
|
||||
|
||||
fmt.Fprint(list, entry.label)
|
||||
printedEntry = true
|
||||
}
|
||||
if buf != "" && len(filteredEntries) > 0 {
|
||||
fmt.Fprint(list, "exec "+buf)
|
||||
|
||||
if printedEntry && !emptyBuf {
|
||||
fmt.Fprint(list, "\n"+buf)
|
||||
}
|
||||
}
|
||||
|
||||
func selectedIndex() int {
|
||||
if list == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
_, selectedOrigin := list.Origin()
|
||||
_, selectedCursor := list.Cursor()
|
||||
|
||||
return selectedOrigin + selectedCursor
|
||||
}
|
||||
|
||||
func selectedEntry() *desktop.Entry {
|
||||
if list == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, selectedOrigin := list.Origin()
|
||||
_, selectedCursor := list.Cursor()
|
||||
selected := selectedOrigin + selectedCursor
|
||||
if len(filteredEntries) == 0 || selected < 0 || selected > len(filteredEntries)-1 {
|
||||
i := selectedIndex()
|
||||
if len(filteredEntries) == 0 || i < 0 || i > len(filteredEntries)-1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return filteredEntries[selected]
|
||||
return filteredEntries[i].Entry
|
||||
}
|
||||
|
||||
func updateEntryInfo() {
|
||||
|
@ -116,26 +128,32 @@ func updateEntryInfo() {
|
|||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
|
||||
var comLine, exLine string
|
||||
var exLine, comLine string
|
||||
entry := selectedEntry()
|
||||
if entry != nil {
|
||||
if entry.Type == desktop.Application {
|
||||
exLine = entry.Exec
|
||||
} else { // Type == desktop.Link
|
||||
exLine = config.BrowserCommand + " " + entry.URL
|
||||
}
|
||||
|
||||
comLine = entry.Comment
|
||||
exLine = entry.Exec
|
||||
} else {
|
||||
comLine = "Shell command"
|
||||
exLine = "bash -c "
|
||||
if input != nil {
|
||||
exLine += input.Buffer()
|
||||
strings.TrimSpace(input.Buffer())
|
||||
}
|
||||
|
||||
comLine = "Shell command"
|
||||
}
|
||||
|
||||
ex.Clear()
|
||||
fmt.Fprint(ex, exLine)
|
||||
comment.Clear()
|
||||
fmt.Fprint(comment, " "+comLine)
|
||||
fmt.Fprint(comment, comLine)
|
||||
}
|
||||
|
||||
func listSelect() error {
|
||||
|
|
|
@ -18,10 +18,11 @@ var (
|
|||
dataDirs string
|
||||
disableMouseSupport bool
|
||||
hideAppDetails bool
|
||||
hideGenericNames bool
|
||||
|
||||
desktopEntries []*desktop.Entry
|
||||
desktopNames []string
|
||||
filteredEntries []*desktop.Entry
|
||||
filteredEntries []*listEntry
|
||||
|
||||
gui *gocui.Gui
|
||||
input, comment, ex, list *gocui.View
|
||||
|
@ -36,6 +37,7 @@ func init() {
|
|||
flag.StringVar(&dataDirs, "data-dirs", "", "application data directories (default: $XDG_DATA_DIRS)")
|
||||
flag.BoolVar(&disableMouseSupport, "no-mouse", false, "disable mouse support")
|
||||
flag.BoolVar(&hideAppDetails, "no-details", false, "hide application details")
|
||||
flag.BoolVar(&hideGenericNames, "no-generic", false, "hide generic names")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -73,8 +75,14 @@ func main() {
|
|||
continue // Unsupported entry type
|
||||
}
|
||||
|
||||
desktopEntries = append(desktopEntries, entry)
|
||||
desktopNames = append(desktopNames, strings.ToLower(entry.Name))
|
||||
if entry.Name != "" {
|
||||
desktopEntries = append(desktopEntries, entry)
|
||||
desktopNames = append(desktopNames, entry.Name)
|
||||
}
|
||||
if !hideGenericNames && entry.GenericName != "" {
|
||||
desktopEntries = append(desktopEntries, entry)
|
||||
desktopNames = append(desktopNames, entry.GenericName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue