parent
587492082e
commit
c523e0759f
|
@ -1,3 +1,6 @@
|
|||
0.2.9
|
||||
- gtkmenu: Restrict to single instance
|
||||
|
||||
0.2.8
|
||||
- Update dependencies
|
||||
|
||||
|
|
|
@ -31,7 +31,10 @@ func newOptionsList(options []string) *optionsList {
|
|||
options: options,
|
||||
}
|
||||
|
||||
opts.TextView = opts.SetDynamicColors(true).SetWrap(true).SetWordWrap(false)
|
||||
tv := opts.TextView
|
||||
tv.SetDynamicColors(true)
|
||||
tv.SetWrap(true)
|
||||
tv.SetWordWrap(false)
|
||||
|
||||
return &opts
|
||||
}
|
||||
|
@ -61,43 +64,48 @@ func (r *optionsList) Draw(screen tcell.Screen) {
|
|||
r.shown++
|
||||
}
|
||||
|
||||
r.TextView.SetText(b.String()).Highlight("gmenu").ScrollToBeginning().Draw(screen)
|
||||
tv := r.TextView
|
||||
tv.SetText(b.String())
|
||||
tv.Highlight("gmenu")
|
||||
tv.ScrollToBeginning()
|
||||
tv.Draw(screen)
|
||||
}
|
||||
|
||||
func initTUI() (*cview.Application, error) {
|
||||
app = cview.NewApplication()
|
||||
inputView = cview.NewInputField().
|
||||
SetLabel("").
|
||||
SetFieldWidth(0).
|
||||
SetFieldBackgroundColor(tcell.ColorDefault).
|
||||
SetFieldTextColor(tcell.ColorDefault).
|
||||
SetChangedFunc(func(text string) {
|
||||
gmenu.SetInput(text)
|
||||
})
|
||||
|
||||
inputView = cview.NewInputField()
|
||||
inputView.SetLabel("")
|
||||
inputView.SetFieldWidth(0)
|
||||
inputView.SetFieldBackgroundColor(tcell.ColorDefault)
|
||||
inputView.SetFieldTextColor(tcell.ColorDefault)
|
||||
inputView.SetChangedFunc(func(text string) {
|
||||
gmenu.SetInput(text)
|
||||
})
|
||||
|
||||
entryList = newOptionsList(nil)
|
||||
|
||||
grid := cview.NewGrid().
|
||||
SetBorders(false).
|
||||
SetRows(1, -1)
|
||||
grid := cview.NewGrid()
|
||||
grid.SetBorders(false)
|
||||
grid.SetRows(1, -1)
|
||||
|
||||
appDetailsView = cview.NewTextView().
|
||||
SetTextAlign(cview.AlignLeft).
|
||||
SetWrap(true).
|
||||
SetWordWrap(true)
|
||||
appDetailsView = cview.NewTextView()
|
||||
appDetailsView.SetTextAlign(cview.AlignLeft)
|
||||
appDetailsView.SetWrap(true)
|
||||
appDetailsView.SetWordWrap(true)
|
||||
|
||||
if config.HideAppDetails {
|
||||
grid = grid.SetColumns(-1).
|
||||
AddItem(inputView, 0, 0, 1, 1, 0, 0, true).
|
||||
AddItem(entryList, 1, 0, 1, 1, 0, 0, false)
|
||||
grid.SetColumns(-1)
|
||||
grid.AddItem(inputView, 0, 0, 1, 1, 0, 0, true)
|
||||
grid.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(entryList, 1, 0, 1, 1, 0, 0, false).
|
||||
AddItem(appDetailsView, 1, 1, 1, 1, 0, 0, false)
|
||||
grid.SetColumns(-1, -1)
|
||||
grid.AddItem(inputView, 0, 0, 1, 2, 0, 0, true)
|
||||
grid.AddItem(entryList, 1, 0, 1, 1, 0, 0, false)
|
||||
grid.AddItem(appDetailsView, 1, 1, 1, 1, 0, 0, false)
|
||||
}
|
||||
|
||||
app = app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
defer app.QueueUpdateDraw(updateEntryInfo)
|
||||
|
||||
if event.Key() == tcell.KeyUp {
|
||||
|
@ -159,7 +167,7 @@ func initTUI() (*cview.Application, error) {
|
|||
return event
|
||||
})
|
||||
|
||||
app = app.SetRoot(grid, true)
|
||||
app.SetRoot(grid, true)
|
||||
|
||||
go gmenu.HandleInput(updateEntries)
|
||||
gmenu.SetInput("")
|
||||
|
|
|
@ -64,7 +64,7 @@ func updateEntryInfo() {
|
|||
comLine = "Shell command"
|
||||
}
|
||||
|
||||
appDetailsView = appDetailsView.SetText(exLine + "\n\n" + comLine)
|
||||
appDetailsView.SetText(exLine + "\n\n" + comLine)
|
||||
}
|
||||
|
||||
func listSelect(runInTerminal bool) error {
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
"github.com/gotk3/gotk3/gtk"
|
||||
)
|
||||
|
||||
func initWindow() *gtk.Window {
|
||||
w, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
||||
func initWindow(application *gtk.Application) *gtk.ApplicationWindow {
|
||||
w, err := gtk.ApplicationWindowNew(application)
|
||||
if err != nil {
|
||||
log.Fatal("failed to create application window:", err)
|
||||
log.Fatal("failed to create window:", err)
|
||||
}
|
||||
|
||||
_, err = w.Connect("key-press-event", handleKeybinding)
|
||||
|
@ -44,7 +44,7 @@ func initWindow() *gtk.Window {
|
|||
return w
|
||||
}
|
||||
|
||||
func handleKeybinding(_ *gtk.Window, ev *gdk.Event) bool {
|
||||
func handleKeybinding(_ *gtk.ApplicationWindow, ev *gdk.Event) bool {
|
||||
keyEvent := &gdk.EventKey{ev}
|
||||
switch keyEvent.KeyVal() {
|
||||
case gdk.KEY_Up, gdk.KEY_Down:
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"runtime/pprof"
|
||||
"sync"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
|
@ -26,6 +27,8 @@ type Config struct {
|
|||
CPUProfile string
|
||||
}
|
||||
|
||||
const appID = "space.rocketnine.gmenu"
|
||||
|
||||
var (
|
||||
config = &Config{}
|
||||
listBox *gtk.ListBox
|
||||
|
@ -35,6 +38,8 @@ var (
|
|||
profileCPU *os.File
|
||||
|
||||
container *gtk.Box
|
||||
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -81,6 +86,24 @@ func load() {
|
|||
loaded <- true
|
||||
}
|
||||
|
||||
func onActivate(application *gtk.Application) {
|
||||
once.Do(func() {
|
||||
w := initWindow(application)
|
||||
container = newBox(gtk.ORIENTATION_VERTICAL)
|
||||
w.Add(container)
|
||||
|
||||
<-loaded
|
||||
initList(container)
|
||||
w.ShowAll()
|
||||
|
||||
if config.CPUProfile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
profileCPU.Close()
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
|
@ -93,26 +116,17 @@ func main() {
|
|||
|
||||
err = pprof.StartCPUProfile(profileCPU)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start profiling cpu: %s", err)
|
||||
log.Fatal("failed to start profiling cpu:", err)
|
||||
}
|
||||
}
|
||||
|
||||
go load()
|
||||
gtk.Init(nil)
|
||||
|
||||
w := initWindow()
|
||||
container = newBox(gtk.ORIENTATION_VERTICAL)
|
||||
w.Add(container)
|
||||
|
||||
<-loaded
|
||||
initList(container)
|
||||
w.ShowAll()
|
||||
|
||||
if config.CPUProfile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
profileCPU.Close()
|
||||
return
|
||||
application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
|
||||
if err != nil {
|
||||
log.Fatal("failed to create application:", err)
|
||||
}
|
||||
application.Connect("activate", func() { onActivate(application) })
|
||||
|
||||
gtk.Main()
|
||||
os.Exit(application.Run(flag.Args()))
|
||||
}
|
||||
|
|
11
go.mod
11
go.mod
|
@ -3,12 +3,13 @@ module gitlab.com/tslocum/gmenu
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200926152101-0fb77ddaa5b4
|
||||
github.com/gotk3/gotk3 v0.5.0
|
||||
github.com/gdamore/tcell/v2 v2.0.1-0.20201109052606-7d87d8188c8d
|
||||
github.com/gotk3/gotk3 v0.5.1-0.20201111061058-cdb396edc76f
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/lithammer/fuzzysearch v1.1.0
|
||||
github.com/lithammer/fuzzysearch v1.1.1
|
||||
github.com/mattn/go-isatty v0.0.12
|
||||
gitlab.com/tslocum/cview v1.4.10-0.20201001195155-f83115be6190
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
gitlab.com/tslocum/cview v1.5.2-0.20201114045554-68b2c49d115a
|
||||
gitlab.com/tslocum/desktop v0.1.4
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
|
||||
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 // indirect
|
||||
)
|
||||
|
|
33
go.sum
33
go.sum
|
@ -1,14 +1,14 @@
|
|||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell/v2 v2.0.0-dev/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
|
||||
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200926152101-0fb77ddaa5b4 h1:9WLVV5c2UI2qvgROlgzLgCuK5gi7igcU5LNsPXCSFB8=
|
||||
github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200926152101-0fb77ddaa5b4/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
|
||||
github.com/gotk3/gotk3 v0.5.0 h1:GOkq4cFgAfeK6YAukLi64bz8zPayZKeCSSRr4mcFReQ=
|
||||
github.com/gotk3/gotk3 v0.5.0/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
||||
github.com/gdamore/tcell/v2 v2.0.1-0.20201109052606-7d87d8188c8d h1:C1FQEuzw5kUUveSXpZp3v0+qOR+VEnzHsQ7K6n39LsM=
|
||||
github.com/gdamore/tcell/v2 v2.0.1-0.20201109052606-7d87d8188c8d/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
|
||||
github.com/gotk3/gotk3 v0.5.1-0.20201111061058-cdb396edc76f h1:pqE4gan8c1ZSjo32V9QD5P41pM5Tlas9gzI+rcYUaI8=
|
||||
github.com/gotk3/gotk3 v0.5.1-0.20201111061058-cdb396edc76f/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
||||
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=
|
||||
github.com/lithammer/fuzzysearch v1.1.0/go.mod h1:Bqx4wo8lTOFcJr3ckpY6HA9lEIOO0H5HrkJ5CsN56HQ=
|
||||
github.com/lithammer/fuzzysearch v1.1.1 h1:8F9OAV2xPuYblToVohjanztdnPjbtA0MLgMvDKQ0Z08=
|
||||
github.com/lithammer/fuzzysearch v1.1.1/go.mod h1:H2bng+w5gsR7NlfIJM8ElGZI0sX6C/9uzGqicVXGU6c=
|
||||
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.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
|
@ -18,23 +18,26 @@ github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/Qd
|
|||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
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/cbind v0.1.2 h1:ptDjO7WeOl1HglprsK18L8I9JeRkmtuBoBBaYw/6/Ow=
|
||||
gitlab.com/tslocum/cbind v0.1.2/go.mod h1:HfB7qAhHSZbn1rFK8M9SvSN5NG6ScAg/3h3iE6xdeeI=
|
||||
gitlab.com/tslocum/cview v1.4.10-0.20201001195155-f83115be6190 h1:umxJVyKBcvHV4/P4082XlP7tWQvOMkI3Ac0wRcbJ7no=
|
||||
gitlab.com/tslocum/cview v1.4.10-0.20201001195155-f83115be6190/go.mod h1:w5TvvYokp4jonrVHf60hopeNkuegZZHQS+vttPtFIkI=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
gitlab.com/tslocum/cbind v0.1.3 h1:FT/fTQ4Yj3eo5021lB3IbkIt8eVtYGhrw/xur+cjvUU=
|
||||
gitlab.com/tslocum/cbind v0.1.3/go.mod h1:RvwYE3auSjBNlCmWeGspzn+jdLUVQ8C2QGC+0nP9ChI=
|
||||
gitlab.com/tslocum/cview v1.5.2-0.20201114045554-68b2c49d115a h1:sW8cntP6g3lPyYwNtElIrsSsXKYIfLIMNLx6VSuzSc8=
|
||||
gitlab.com/tslocum/cview v1.5.2-0.20201114045554-68b2c49d115a/go.mod h1:Mg+xnHJzsuJTjlRT/TBluZeTjMmir1+FH0LmQYN4Gd4=
|
||||
gitlab.com/tslocum/desktop v0.1.4 h1:ew+nJFAaNLXQw9SlX3M2OZjHd55SJCc5k3J+rQUPA4E=
|
||||
gitlab.com/tslocum/desktop v0.1.4/go.mod h1:xegVIo1fwhovdUkErI999g3qb5gK9T7+s76hMLDOXRg=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200928205150-006507a75852 h1:sXxgOAXy8JwHhZnPuItAlUtwIlxrlEqi28mKhUR+zZY=
|
||||
golang.org/x/sys v0.0.0-20200928205150-006507a75852/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201013132646-2da7054afaeb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 h1:Z991aAXPjz0tLnj74pVXW3eWJ5lHMIBvbRfMq4M2jHA=
|
||||
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/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=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
|
Loading…
Reference in New Issue