示例#1
0
文件: view.go 项目: yaoshipu/peco
func (v *View) movePage(p hub.Payload, r PagingRequest) {
	defer p.Done()

	if v.layout.MovePage(v.state, r) {
		v.layout.DrawScreen(v.state, false)
	}
}
示例#2
0
文件: filter.go 项目: yaoshipu/peco
// Work is the actual work horse that that does the matching
// in a goroutine of its own. It wraps Matcher.Match().
func (f *Filter) Work(ctx context.Context, q hub.Payload) {
	defer q.Done()

	query, ok := q.Data().(string)
	if !ok {
		return
	}

	if pdebug.Enabled {
		g := pdebug.Marker("Filter.Work query '%s'", query)
		defer g.End()
	}

	state := f.state
	if query == "" {
		state.ResetCurrentLineBuffer()
		if !state.config.StickySelection {
			state.Selection().Reset()
		}
		return
	}

	// Create a new pipeline
	p := pipeline.New()
	p.SetSource(state.Source())
	thisf := state.Filters().Current().Clone()
	thisf.SetQuery(query)
	p.Add(thisf)

	buf := NewMemoryBuffer()
	p.SetDestination(buf)
	state.SetCurrentLineBuffer(buf)

	go func() {
		defer state.Hub().SendDraw(true)
		if err := p.Run(ctx); err != nil {
			state.Hub().SendStatusMsg(err.Error())
		}
	}()

	go func() {
		if pdebug.Enabled {
			pdebug.Printf("waiting for query to finish")
			defer pdebug.Printf("Filter.Work: finished running query")
		}
		t := time.NewTicker(100 * time.Millisecond)
		defer t.Stop()
		defer state.Hub().SendStatusMsg("")
		defer state.Hub().SendDraw(true)
		for {
			select {
			case <-p.Done():
				return
			case <-t.C:
				pdebug.Printf("Sending draw while waiting for filter to end")
				state.Hub().SendDraw(true)
			}
		}
	}()

	if !state.config.StickySelection {
		state.Selection().Reset()
	}
}
示例#3
0
文件: view.go 项目: yaoshipu/peco
func (v *View) drawPrompt(p hub.Payload) {
	defer p.Done()

	v.layout.DrawPrompt(v.state)
}
示例#4
0
文件: view.go 项目: yaoshipu/peco
func (v *View) drawScreen(p hub.Payload, runningQuery bool) {
	defer p.Done()

	v.layout.DrawScreen(v.state, runningQuery)
}
示例#5
0
文件: view.go 项目: yaoshipu/peco
func (v *View) purgeDisplayCache(p hub.Payload) {
	defer p.Done()

	v.layout.PurgeDisplayCache()
}
示例#6
0
文件: view.go 项目: yaoshipu/peco
func (v *View) printStatus(p hub.Payload, r statusMsgReq) {
	defer p.Done()
	v.layout.PrintStatus(r.Message(), r.Delay())
}