package edit
import (
)
func ( *Editor, *eval.Evaler, store.Store, histutil.Store, eval.NsBuilder) {
:= newBindingVar(emptyBindingsMap)
:= .app
.AddNs("listing",
eval.NsBuilder{
"binding": ,
}.AddGoFns("<edit:listing>:", map[string]interface{}{
"accept": func() { listingAccept() },
"accept-close": func() { listingAcceptClose() },
"up": func() { listingUp() },
"down": func() { listingDown() },
"up-cycle": func() { listingUpCycle() },
"down-cycle": func() { listingDownCycle() },
"page-up": func() { listingPageUp() },
"page-down": func() { listingPageDown() },
"start-custom": func( *eval.Frame, customListingOpts, interface{}) {
listingStartCustom(, , , )
},
}).Ns())
initHistlist(, , , , )
initLastcmd(, , , , )
initLocation(, , , , )
}
var filterSpec = mode.FilterSpec{
Maker: func( string) func(string) bool {
, := filter.Compile()
if == nil {
return func(string) bool { return true }
}
return .Match
},
Highlighter: filter.Highlight,
}
func ( *Editor, *eval.Evaler, histutil.Store, vars.PtrVar, eval.NsBuilder) {
:= newBindingVar(emptyBindingsMap)
:= newMapBindings(, , , )
:= newBoolVar(true)
.AddNs("histlist",
eval.NsBuilder{
"binding": ,
}.AddGoFns("<edit:histlist>", map[string]interface{}{
"start": func() {
, := mode.NewHistlist(.app, mode.HistlistSpec{
Bindings: ,
AllCmds: .AllCmds,
Dedup: func() bool {
return .Get().(bool)
},
Filter: filterSpec,
})
startMode(.app, , )
},
"toggle-dedup": func() {
.Set(!.Get().(bool))
listingRefilter(.app)
.app.Redraw()
},
}).Ns())
}
func ( *Editor, *eval.Evaler, histutil.Store, vars.PtrVar, eval.NsBuilder) {
:= newBindingVar(emptyBindingsMap)
:= newMapBindings(, , , )
.AddNs("lastcmd",
eval.NsBuilder{
"binding": ,
}.AddGoFn("<edit:lastcmd>", "start", func() {
, := mode.NewLastcmd(.app, mode.LastcmdSpec{
Bindings: , Store: })
startMode(.app, , )
}).Ns())
}
func ( *Editor, *eval.Evaler, store.Store, vars.PtrVar, eval.NsBuilder) {
:= newBindingVar(emptyBindingsMap)
:= newListVar(vals.EmptyList)
:= newListVar(vals.EmptyList)
:= newMapVar(vals.EmptyMap)
:= newMapBindings(, , , )
:= mode.LocationWSIterator(
adaptToIterateStringPair())
.AddNs("location",
eval.NsBuilder{
"binding": ,
"hidden": ,
"pinned": ,
"workspaces": ,
}.AddGoFn("<edit:location>", "start", func() {
, := mode.NewLocation(.app, mode.LocationSpec{
Bindings: , Store: dirStore{, },
IteratePinned: adaptToIterateString(),
IterateHidden: adaptToIterateString(),
IterateWorkspaces: ,
Filter: filterSpec,
})
startMode(.app, , )
}).Ns())
.AddAfterChdir(func(string) {
, := os.Getwd()
if != nil {
return
}
.AddDir(, 1)
, := .Parse()
if != "" {
.AddDir(+[len():], 1)
}
})
}
func ( cli.App) {
, := .CopyState().Addon.(tk.ComboBox)
if ! {
return
}
.ListBox().Accept()
}
func ( cli.App) {
listingAccept()
closeMode()
}
func ( cli.App) { listingSelect(, tk.Prev) }
func ( cli.App) { listingSelect(, tk.Next) }
func ( cli.App) { listingSelect(, tk.PrevWrap) }
func ( cli.App) { listingSelect(, tk.NextWrap) }
func ( cli.App) { listingSelect(, tk.PrevPage) }
func ( cli.App) { listingSelect(, tk.NextPage) }
func ( cli.App) { listingSelect(, tk.Left) }
func ( cli.App) { listingSelect(, tk.Right) }
func ( cli.App, func(tk.ListBoxState) int) {
, := .CopyState().Addon.(tk.ComboBox)
if ! {
return
}
.ListBox().Select()
}
func ( cli.App) {
, := .CopyState().Addon.(tk.ComboBox)
if ! {
return
}
.Refilter()
}
func ( vars.Var) func(func(string)) {
return func( func( string)) {
vals.Iterate(.Get(), func( interface{}) bool {
(vals.ToString())
return true
})
}
}
func ( vars.Var) func(func(string, string) bool) {
return func( func(, string) bool) {
:= .Get().(hashmap.Map)
for := .Iterator(); .HasElem(); .Next() {
, := .Elem()
, := .(string)
, := .(string)
if && {
:= (, )
if ! {
break
}
}
}
}
}
type dirStore struct {
ev *eval.Evaler
st store.Store
}
func ( dirStore) ( string) error {
return .ev.Chdir()
}
func ( dirStore) ( map[string]struct{}) ([]store.Dir, error) {
return .st.Dirs()
}
func ( dirStore) () (string, error) {
return os.Getwd()
}
func ( cli.App, tk.Widget, error) {
if != nil {
.SetAddon(, false)
.Redraw()
}
if != nil {
.Notify(.Error())
}
}