gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/program/shell/editor.go (about)

     1  package shell
     2  
     3  import (
     4  	"bufio"
     5  	"fmt"
     6  	"io"
     7  	"os"
     8  	"strings"
     9  )
    10  
    11  type editor interface {
    12  	ReadLine() (string, error)
    13  	Close()
    14  }
    15  
    16  type minEditor struct {
    17  	in  *bufio.Reader
    18  	out io.Writer
    19  }
    20  
    21  func newMinEditor(in, out *os.File) *minEditor {
    22  	return &minEditor{bufio.NewReader(in), out}
    23  }
    24  
    25  func (ed *minEditor) ReadLine() (string, error) {
    26  	wd, err := os.Getwd()
    27  	if err != nil {
    28  		wd = "?"
    29  	}
    30  	fmt.Fprintf(ed.out, "%s> ", wd)
    31  	line, err := ed.in.ReadString('\n')
    32  	// Chop off the trailing \r on Windows.
    33  	line = strings.TrimRight(line, "\r\n")
    34  	return line, err
    35  }
    36  
    37  func (editor *minEditor) Close() {
    38  }