예제 #1
0
파일: editor.go 프로젝트: elves/elvish
// NewEditor creates an Editor.
func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
	seq := -1
	if st != nil {
		var err error
		seq, err = st.NextCmdSeq()
		if err != nil {
			// TODO(xiaq): Also report the error
			seq = -1
		}
	}

	prompt, rprompt := defaultPrompts()

	ed := &Editor{
		file:   file,
		writer: newWriter(file),
		reader: NewReader(file),
		sigs:   sigs,
		store:  st,
		evaler: ev,
		cmdSeq: seq,
		ps1:    eval.NewPtrVariableWithValidator(prompt, MustBeFn),
		rps1:   eval.NewPtrVariableWithValidator(rprompt, MustBeFn),

		abbreviations: make(map[string]string),
		beforeReadLine: eval.NewPtrVariableWithValidator(
			eval.NewList(), eval.IsListOfFnValue),
		afterReadLine: eval.NewPtrVariableWithValidator(
			eval.NewList(), eval.IsListOfFnValue),
	}
	ev.Editor = ed
	ev.Modules["le"] = makeModule(ed)
	return ed
}
예제 #2
0
func newHistoryListing(s *store.Store) (*historyListing, error) {
	seq, err := s.NextCmdSeq()
	if err != nil {
		return nil, err
	}
	cmds, err := s.Cmds(seq-100, seq)
	if err != nil {
		return nil, err
	}
	return &historyListing{cmds}, nil
}
예제 #3
0
파일: location.go 프로젝트: zhsj/elvish
func newLocation(s *store.Store) (*location, error) {
	if s == nil {
		return nil, ErrStoreOffline
	}
	all, err := s.ListDirs()
	if err != nil {
		return nil, err
	}

	loc := &location{all: all}
	loc.listing = newListing(modeLocation, loc)
	return loc, nil
}
예제 #4
0
파일: editor.go 프로젝트: fionser/elvish
// NewEditor creates an Editor.
func NewEditor(file *os.File, sigs <-chan os.Signal, st *store.Store) *Editor {
	seq := -1
	if st != nil {
		var err error
		seq, err = st.NextCmdSeq()
		if err != nil {
			// TODO(xiaq): Also report the error
			seq = -1
		}
	}

	return &Editor{
		file:   file,
		writer: newWriter(file),
		reader: NewReader(file),
		sigs:   sigs,
		store:  st,
		cmdSeq: seq,
	}
}
예제 #5
0
파일: histlist.go 프로젝트: zhsj/elvish
func newHistlist(s *store.Store) (*histlist, error) {
	if s == nil {
		return nil, ErrStoreOffline
	}
	seq, err := s.NextCmdSeq()
	if err != nil {
		return nil, err
	}
	all, err := s.Cmds(0, seq)
	if err != nil {
		return nil, err
	}
	last := make(map[string]int)
	for i, entry := range all {
		last[entry] = i
	}
	hl := &histlist{all: all, last: last, indexWidth: len(strconv.Itoa(len(all) - 1))}
	hl.listing = newListing(modeHistoryListing, hl)
	return hl, nil
}
예제 #6
0
// NewEditor creates an Editor.
func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
	seq := -1
	if st != nil {
		var err error
		seq, err = st.NextCmdSeq()
		if err != nil {
			// TODO(xiaq): Also report the error
			seq = -1
		}
	}

	ed := &Editor{
		file:   file,
		writer: newWriter(file),
		reader: NewReader(file),
		sigs:   sigs,
		store:  st,
		evaler: ev,
		cmdSeq: seq,
	}
	ev.Editor = ed
	return ed
}