package edit

import (
	
	
	
	

	
	
	
	
	
	
	
)

type customListingOpts struct {
	Binding    bindingsMap
	Caption    string
	KeepBottom bool
	Accept     eval.Callable
	AutoAccept bool
}

func (*customListingOpts) () {}

//elvdoc:fn listing:start-custom
//
// Starts a custom listing addon.

func ( *Editor,  *eval.Frame,  customListingOpts,  interface{}) {
	var  tk.Bindings
	if .Binding.Map != nil {
		 = newMapBindings(, .Evaler, vars.FromPtr(&.Binding))
	}
	var  func(string) []mode.ListingItem
	if ,  := .(eval.Callable);  {
		 = func( string) []mode.ListingItem {
			var  []mode.ListingItem
			var  sync.Mutex
			 := func( mode.ListingItem) {
				.Lock()
				defer .Unlock()
				 = append(, )
			}
			 := func( <-chan interface{}) {
				for  := range  {
					if ,  := getListingItem();  {
						()
					}
				}
			}
			 := func( *os.File) {
				 := bufio.NewReader()
				for {
					,  := .ReadString('\n')
					if  != "" {
						 := strutil.ChopLineEnding()
						(mode.ListingItem{ToAccept: , ToShow: ui.T()})
					}
					if  != nil {
						break
					}
				}
			}
			 := func( *eval.Frame) error { return .Call(, []interface{}{}, eval.NoOpts) }
			 := .PipeOutput(, , )
			// TODO(xiaq): Report the error.
			_ = 
			return 
		}
	} else {
		 = func( string) []mode.ListingItem {
			 := []mode.ListingItem{}
			vals.Iterate(, func( interface{}) bool {
				,  := getToFilter()
				,  := getListingItem()
				if  &&  && strings.Contains(, ) {
					// TODO(xiaq): Report type error when ok is false.
					 = append(, )
				}
				return true
			})
			return 
		}
	}

	,  := mode.NewListing(.app, mode.ListingSpec{
		Bindings: ,
		Caption:  .Caption,
		GetItems: func( string) ([]mode.ListingItem, int) {
			 := ()
			 := 0
			if .KeepBottom {
				 = len() - 1
			}
			return , 
		},
		Accept: func( string) bool {
			if .Accept != nil {
				callWithNotifyPorts(, .Evaler, .Accept, )
			}
			return false
		},
		AutoAccept: .AutoAccept,
	})
	startMode(.app, , )
}

func ( interface{}) (string, bool) {
	,  := vals.Index(, "to-filter")
	,  := .(string)
	return , 
}

func ( interface{}) ( mode.ListingItem,  bool) {
	,  := vals.Index(, "to-accept")
	,  := .(string)
	,  := vals.Index(, "to-show")
	,  := .(ui.Text)
	if ,  := .(string);  {
		 = ui.T()
		 = true
	}
	return mode.ListingItem{ToAccept: , ToShow: },  && 
}