Update CI script
parent
a83eaef916
commit
23f1cfa9ca
|
@ -1,9 +1,42 @@
|
|||
stages:
|
||||
- test
|
||||
image: golang:latest
|
||||
|
||||
test:
|
||||
image: golang:latest
|
||||
stage: test
|
||||
stages:
|
||||
- validate
|
||||
- build
|
||||
|
||||
fmt:
|
||||
stage: validate
|
||||
script:
|
||||
- gofmt -l -s -e .
|
||||
- exit $(gofmt -l -s -e . | wc -l)
|
||||
|
||||
lint:
|
||||
stage: validate
|
||||
script:
|
||||
- go get -u golang.org/x/lint/golint
|
||||
- golint -set_exit_status
|
||||
|
||||
vet:
|
||||
stage: validate
|
||||
script:
|
||||
- apt-get update && apt-get install -y libgtk-3-dev
|
||||
- go test -v ./...
|
||||
- go vet -composites=false ./...
|
||||
|
||||
test:
|
||||
stage: validate
|
||||
script:
|
||||
- apt-get update && apt-get install -y libgtk-3-dev
|
||||
- go test -race -v ./...
|
||||
|
||||
build-tui:
|
||||
stage: build
|
||||
script:
|
||||
- cd cmd/gmenu
|
||||
- go build
|
||||
|
||||
build-gui:
|
||||
stage: build
|
||||
script:
|
||||
- apt-get update && apt-get install -y libgtk-3-dev
|
||||
- cd cmd/gtkmenu
|
||||
- go build
|
||||
|
|
|
@ -3,21 +3,21 @@ package main
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"gitlab.com/tslocum/cview"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
var (
|
||||
app *cview.Application
|
||||
inputView *cview.InputField
|
||||
optionsList *OptionsList
|
||||
entryList *optionsList
|
||||
appDetailsView *cview.TextView
|
||||
|
||||
closedGUI bool
|
||||
)
|
||||
|
||||
type OptionsList struct {
|
||||
type optionsList struct {
|
||||
*cview.TextView
|
||||
options []string
|
||||
origin int
|
||||
|
@ -25,8 +25,8 @@ type OptionsList struct {
|
|||
shown int
|
||||
}
|
||||
|
||||
func NewOptionsList(options []string) *OptionsList {
|
||||
opts := OptionsList{
|
||||
func newOptionsList(options []string) *optionsList {
|
||||
opts := optionsList{
|
||||
TextView: cview.NewTextView(),
|
||||
options: options,
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func NewOptionsList(options []string) *OptionsList {
|
|||
return &opts
|
||||
}
|
||||
|
||||
func (r *OptionsList) Draw(screen tcell.Screen) {
|
||||
func (r *optionsList) Draw(screen tcell.Screen) {
|
||||
_, height := screen.Size()
|
||||
|
||||
var b strings.Builder
|
||||
|
@ -75,7 +75,7 @@ func initGUI() (*cview.Application, error) {
|
|||
gmenu.SetInput(text)
|
||||
})
|
||||
|
||||
optionsList = NewOptionsList(nil)
|
||||
entryList = newOptionsList(nil)
|
||||
|
||||
grid := cview.NewGrid().
|
||||
SetBorders(false).
|
||||
|
@ -89,11 +89,11 @@ func initGUI() (*cview.Application, error) {
|
|||
if config.HideAppDetails {
|
||||
grid = grid.SetColumns(-1).
|
||||
AddItem(inputView, 0, 0, 1, 1, 0, 0, true).
|
||||
AddItem(optionsList, 1, 0, 1, 1, 0, 0, false)
|
||||
AddItem(entryList, 1, 0, 1, 1, 0, 0, false)
|
||||
} else {
|
||||
grid = grid.SetColumns(-1, -1).
|
||||
AddItem(inputView, 0, 0, 1, 2, 0, 0, true).
|
||||
AddItem(optionsList, 1, 0, 1, 1, 0, 0, false).
|
||||
AddItem(entryList, 1, 0, 1, 1, 0, 0, false).
|
||||
AddItem(appDetailsView, 1, 1, 1, 1, 0, 0, false)
|
||||
}
|
||||
|
||||
|
@ -101,49 +101,49 @@ func initGUI() (*cview.Application, error) {
|
|||
defer app.QueueUpdateDraw(updateEntryInfo)
|
||||
|
||||
if event.Key() == tcell.KeyUp {
|
||||
if optionsList.origin > 0 && optionsList.selected == optionsList.origin {
|
||||
optionsList.origin--
|
||||
if entryList.origin > 0 && entryList.selected == entryList.origin {
|
||||
entryList.origin--
|
||||
}
|
||||
if optionsList.selected > 0 {
|
||||
optionsList.selected--
|
||||
if entryList.selected > 0 {
|
||||
entryList.selected--
|
||||
}
|
||||
event = nil
|
||||
} else if event.Key() == tcell.KeyDown {
|
||||
if optionsList.selected < len(optionsList.options)-1 {
|
||||
optionsList.selected++
|
||||
if optionsList.selected > optionsList.origin+optionsList.shown-1 {
|
||||
optionsList.origin++
|
||||
if entryList.selected < len(entryList.options)-1 {
|
||||
entryList.selected++
|
||||
if entryList.selected > entryList.origin+entryList.shown-1 {
|
||||
entryList.origin++
|
||||
}
|
||||
}
|
||||
event = nil
|
||||
} else if event.Key() == tcell.KeyPgUp {
|
||||
if optionsList.origin == 0 {
|
||||
optionsList.selected = 0
|
||||
if entryList.origin == 0 {
|
||||
entryList.selected = 0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
optionsList.origin -= optionsList.shown - 2
|
||||
if optionsList.origin < 0 {
|
||||
optionsList.origin = 0
|
||||
entryList.origin -= entryList.shown - 2
|
||||
if entryList.origin < 0 {
|
||||
entryList.origin = 0
|
||||
}
|
||||
optionsList.selected = optionsList.origin
|
||||
entryList.selected = entryList.origin
|
||||
|
||||
return nil
|
||||
} else if event.Key() == tcell.KeyPgDn {
|
||||
numEntries := len(gmenu.FilteredEntries)
|
||||
|
||||
if optionsList.origin >= numEntries-optionsList.shown {
|
||||
optionsList.selected = numEntries - 1
|
||||
if entryList.origin >= numEntries-entryList.shown {
|
||||
entryList.selected = numEntries - 1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
optionsList.origin += optionsList.shown - 2
|
||||
if optionsList.origin > numEntries-optionsList.shown {
|
||||
optionsList.origin = numEntries - optionsList.shown
|
||||
entryList.origin += entryList.shown - 2
|
||||
if entryList.origin > numEntries-entryList.shown {
|
||||
entryList.origin = numEntries - entryList.shown
|
||||
}
|
||||
optionsList.selected = optionsList.origin
|
||||
entryList.selected = entryList.origin
|
||||
|
||||
return nil
|
||||
} else if event.Key() == tcell.KeyEnter {
|
||||
|
|
|
@ -5,33 +5,33 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/kballard/go-shellquote"
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/kballard/go-shellquote"
|
||||
)
|
||||
|
||||
func updateEntries(input string) {
|
||||
gmenu.FilterEntries()
|
||||
|
||||
optionsList.selected = 0
|
||||
optionsList.origin = 0
|
||||
entryList.selected = 0
|
||||
entryList.origin = 0
|
||||
defer app.QueueUpdateDraw(updateEntryInfo)
|
||||
|
||||
optionsList.options = nil
|
||||
entryList.options = nil
|
||||
for _, entry := range gmenu.FilteredEntries {
|
||||
optionsList.options = append(optionsList.options, entry.Label)
|
||||
entryList.options = append(entryList.options, entry.Label)
|
||||
}
|
||||
if input != "" {
|
||||
optionsList.options = append(optionsList.options, input)
|
||||
entryList.options = append(entryList.options, input)
|
||||
}
|
||||
}
|
||||
|
||||
func selectedIndex() int {
|
||||
if optionsList == nil {
|
||||
if entryList == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
return optionsList.selected
|
||||
return entryList.selected
|
||||
}
|
||||
|
||||
func selectedEntry() *desktop.Entry {
|
||||
|
|
|
@ -6,10 +6,11 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/mattn/go-isatty"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
)
|
||||
|
||||
// Config stores configuration variables.
|
||||
type Config struct {
|
||||
gmenu.Config
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/gotk3/gotk3/gdk"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
)
|
||||
|
||||
const CachedIconCompressionLevel = 3
|
||||
const cachedIconCompressionLevel = 3
|
||||
|
||||
var (
|
||||
iconTheme *gtk.IconTheme
|
||||
|
@ -56,7 +56,7 @@ func cacheIcon(cachedIcon string, pbuf *gdk.Pixbuf) {
|
|||
return
|
||||
}
|
||||
|
||||
pbuf.SavePNG(f.Name(), CachedIconCompressionLevel)
|
||||
pbuf.SavePNG(f.Name(), cachedIconCompressionLevel)
|
||||
}
|
||||
|
||||
func fallbackIcon(entry *gmenu.ListEntry) string {
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
"github.com/gotk3/gotk3/pango"
|
||||
"github.com/kballard/go-shellquote"
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -9,15 +9,12 @@ import (
|
|||
"runtime/pprof"
|
||||
"time"
|
||||
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
"gitlab.com/tslocum/gmenu/pkg/gmenu"
|
||||
)
|
||||
|
||||
const (
|
||||
appID = "space.rocketnine.gmenu"
|
||||
)
|
||||
|
||||
// Config stores configuration variables.
|
||||
type Config struct {
|
||||
gmenu.Config
|
||||
|
||||
|
|
10
go.mod
10
go.mod
|
@ -4,11 +4,13 @@ go 1.12
|
|||
|
||||
require (
|
||||
github.com/gdamore/tcell v1.3.0
|
||||
github.com/gotk3/gotk3 v0.0.0-20200103101635-d3629b451bb5
|
||||
github.com/gotk3/gotk3 v0.0.0-20200122052051-1b4add5ab128
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/lithammer/fuzzysearch v1.1.0
|
||||
github.com/mattn/go-isatty v0.0.11
|
||||
github.com/pkg/errors v0.8.1
|
||||
gitlab.com/tslocum/cview v1.4.1-0.20200122232819-5f880bc2c7e6
|
||||
github.com/mattn/go-isatty v0.0.12
|
||||
github.com/mattn/go-runewidth v0.0.8 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
gitlab.com/tslocum/cview v1.4.1
|
||||
gitlab.com/tslocum/desktop v0.1.4-0.20200123010527-46712e512c7d
|
||||
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect
|
||||
)
|
||||
|
|
23
go.sum
23
go.sum
|
@ -4,8 +4,8 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk
|
|||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
|
||||
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
||||
github.com/gotk3/gotk3 v0.0.0-20200103101635-d3629b451bb5 h1:FEketUKKSYVEM7KBQmhXmZCRu2udwsRuiy8uoyN9gUE=
|
||||
github.com/gotk3/gotk3 v0.0.0-20200103101635-d3629b451bb5/go.mod h1:Eew3QBwAOBTrfFFDmsDE5wZWbcagBL1NUslj1GhRveo=
|
||||
github.com/gotk3/gotk3 v0.0.0-20200122052051-1b4add5ab128 h1:Hjk+U6RSAEZGx3VIhq9RSyVJlvCRp5AYyyc9VmxvjJ4=
|
||||
github.com/gotk3/gotk3 v0.0.0-20200122052051-1b4add5ab128/go.mod h1:Eew3QBwAOBTrfFFDmsDE5wZWbcagBL1NUslj1GhRveo=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/lithammer/fuzzysearch v1.1.0 h1:go9v8tLCrNTTlH42OAaq4eHFe81TDHEnlrMEb6R4f+A=
|
||||
|
@ -14,27 +14,30 @@ github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09
|
|||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
|
||||
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
gitlab.com/tslocum/cview v1.4.1-0.20200122232819-5f880bc2c7e6 h1:C0UWplFR3t8+7Wj3M194fMIESyiN2jQBaukstRwRETk=
|
||||
gitlab.com/tslocum/cview v1.4.1-0.20200122232819-5f880bc2c7e6/go.mod h1:QbxliYQa2I32UJH2boP54jq6tnWlgm6yViaFXKGDfuM=
|
||||
gitlab.com/tslocum/desktop v0.1.3 h1:0yIUIhAaP8oEaHpKbJ+1L9xGfLaga//fPEimIubFecY=
|
||||
gitlab.com/tslocum/desktop v0.1.3/go.mod h1:cUn0Q8ALjkAq40qSei795yN3CfO5pkeYKo2gmzaZ2SI=
|
||||
gitlab.com/tslocum/cview v1.4.1 h1:bG1ugSSFEe8B6poP+xEeo7OIP+Ph4JBOs1fAVtuvgjY=
|
||||
gitlab.com/tslocum/cview v1.4.1/go.mod h1:QbxliYQa2I32UJH2boP54jq6tnWlgm6yViaFXKGDfuM=
|
||||
gitlab.com/tslocum/desktop v0.1.4-0.20200123010527-46712e512c7d h1:JlNn0QBnwVK3sZjqf9z+6JkTIN1UWU6lWQqAm1SadvI=
|
||||
gitlab.com/tslocum/desktop v0.1.4-0.20200123010527-46712e512c7d/go.mod h1:ujaXLjKXzooMcFT/+pUYFVIFBmBDehD+yBz6AUIuDGw=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191018095205-727590c5006e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7 h1:/W9OPMnnpmFXHYkcp2rQsbFUbRlRzfECQjmAFiOyHE8=
|
||||
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk=
|
||||
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package gmenu
|
||||
|
||||
// Config stores configuration variables.
|
||||
type Config struct {
|
||||
PrintVersion bool
|
||||
|
||||
|
@ -12,6 +13,7 @@ type Config struct {
|
|||
browserCommand string
|
||||
}
|
||||
|
||||
// TerminalCommand returns the command to execute to open a terminal.
|
||||
func (c *Config) TerminalCommand() string {
|
||||
if c.terminalCommand == "" {
|
||||
c.terminalCommand = "i3-sensible-terminal"
|
||||
|
@ -20,6 +22,7 @@ func (c *Config) TerminalCommand() string {
|
|||
return c.terminalCommand
|
||||
}
|
||||
|
||||
// BrowserCommand returns the command to execute to open a browser.
|
||||
func (c *Config) BrowserCommand() string {
|
||||
if c.browserCommand == "" {
|
||||
c.browserCommand = "xdg-open"
|
||||
|
@ -28,10 +31,12 @@ func (c *Config) BrowserCommand() string {
|
|||
return c.browserCommand
|
||||
}
|
||||
|
||||
// VersionInfo is the text printed when the --version flag is supplied.
|
||||
const VersionInfo = `%s - Desktop application launcher - v%s
|
||||
https://gitlab.com/tslocum/gmenu
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2019 Trevor Slocum <trevor@rocketnine.space>
|
||||
`
|
||||
|
||||
// Version is the version of the application.
|
||||
var Version = "0.0.0"
|
||||
|
|
|
@ -7,15 +7,18 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/tslocum/desktop"
|
||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/tslocum/desktop"
|
||||
)
|
||||
|
||||
var (
|
||||
// Entries is a slice of all desktop entries.
|
||||
Entries []*desktop.Entry
|
||||
Names []string
|
||||
// Names is a slice of all desktop entry names.
|
||||
Names []string
|
||||
|
||||
// FilteredEntries is a slice of filtered desktop entries.
|
||||
FilteredEntries []*ListEntry
|
||||
|
||||
inputBuffer = make(chan string, 3)
|
||||
|
@ -24,14 +27,17 @@ var (
|
|||
inputFlushed = make(chan bool)
|
||||
)
|
||||
|
||||
// ListEntry is a desktop entry and its label.
|
||||
type ListEntry struct {
|
||||
*desktop.Entry
|
||||
|
||||
Label string
|
||||
}
|
||||
|
||||
// InputUpdateHandler is a handler to be executed when the input is updated.
|
||||
type InputUpdateHandler func(input string)
|
||||
|
||||
// SharedInit performs any necessary initialization shared between gmenu and gtkmenu.
|
||||
func SharedInit(c *Config) {
|
||||
log.SetFlags(0)
|
||||
|
||||
|
@ -43,6 +49,7 @@ func SharedInit(c *Config) {
|
|||
flag.StringVar(&c.browserCommand, "browser", "", "browser command")
|
||||
}
|
||||
|
||||
// HandleInput is a goroutine which reads changes in the input buffer and calls the supplied InputUpdateHandler.
|
||||
func HandleInput(u InputUpdateHandler) {
|
||||
for in := range inputBuffer {
|
||||
input = in
|
||||
|
@ -54,6 +61,7 @@ func HandleInput(u InputUpdateHandler) {
|
|||
inputFlushed <- true
|
||||
}
|
||||
|
||||
// LoadEntries scans for and loads desktop entries.
|
||||
func LoadEntries(c *Config) {
|
||||
var err error
|
||||
Entries, Names, err = DesktopEntries(c)
|
||||
|
@ -62,15 +70,18 @@ func LoadEntries(c *Config) {
|
|||
}
|
||||
}
|
||||
|
||||
// SetInput sets the input buffer.
|
||||
func SetInput(i string) {
|
||||
inputBuffer <- i
|
||||
}
|
||||
|
||||
// CloseInput closes the input buffer.
|
||||
func CloseInput() {
|
||||
close(inputBuffer)
|
||||
<-inputFlushed
|
||||
}
|
||||
|
||||
// MatchEntry returns whether the entry at the supplied index matches the input buffer.
|
||||
func MatchEntry(i int) bool {
|
||||
if i == -1 {
|
||||
return true
|
||||
|
@ -83,6 +94,7 @@ func MatchEntry(i int) bool {
|
|||
return fuzzy.MatchFold(inputLower, Names[i])
|
||||
}
|
||||
|
||||
// FilterEntries sets FilteredEntries to all entries matching the input buffer.
|
||||
func FilterEntries() {
|
||||
FilteredEntries = nil
|
||||
if input == "" {
|
||||
|
@ -103,6 +115,7 @@ func FilterEntries() {
|
|||
}
|
||||
}
|
||||
|
||||
// DesktopEntries scans for desktop entries.
|
||||
func DesktopEntries(c *Config) ([]*desktop.Entry, []string, error) {
|
||||
var dirs []string
|
||||
if c.DataDirs != "" {
|
||||
|
@ -150,6 +163,7 @@ func DesktopEntries(c *Config) ([]*desktop.Entry, []string, error) {
|
|||
return desktopEntries, desktopNames, nil
|
||||
}
|
||||
|
||||
// Sort returns whether entry i should be sorted before entry j.
|
||||
func Sort(i, j int) bool {
|
||||
if input == "" {
|
||||
return SortEmpty(i, j)
|
||||
|
@ -158,6 +172,8 @@ func Sort(i, j int) bool {
|
|||
return SortFiltered(i, j)
|
||||
}
|
||||
|
||||
// SortEmpty returns whether entry i should be sorted before entry j when the
|
||||
// input buffer is blank.
|
||||
func SortEmpty(i, j int) bool {
|
||||
ilower := strings.ToLower(FilteredEntries[i].Label)
|
||||
jlower := strings.ToLower(FilteredEntries[j].Label)
|
||||
|
@ -171,6 +187,8 @@ func SortEmpty(i, j int) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// SortFiltered returns whether entry i should be sorted before entry j when
|
||||
// the input buffer is not blank.
|
||||
func SortFiltered(i, j int) bool {
|
||||
ilower := strings.ToLower(FilteredEntries[i].Label)
|
||||
if FilteredEntries[i].Entry == nil {
|
||||
|
@ -206,6 +224,7 @@ func SortFiltered(i, j int) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// Run executes the specified command.
|
||||
func Run(config *Config, execute string, path string, runInTerminal bool, waitUntilFinished bool) error {
|
||||
execute = strings.TrimSpace(execute)
|
||||
|
||||
|
|
Loading…
Reference in New Issue