diff --git a/pkg/edit/completion.go b/pkg/edit/completion.go index 30863799..6703353a 100644 --- a/pkg/edit/completion.go +++ b/pkg/edit/completion.go @@ -473,7 +473,7 @@ func adaptArgGeneratorMap(ev *eval.Evaler, m vals.Map) complete.ArgGenerator { for { line, err := buffered.ReadString('\n') if line != "" { - collect(complete.PlainItem(strings.TrimRight(line, "\r\n"))) + collect(complete.PlainItem(eval.ChopLineEnding(line))) } if err != nil { break diff --git a/pkg/edit/instant.go b/pkg/edit/instant.go index bed91857..ae543ef0 100644 --- a/pkg/edit/instant.go +++ b/pkg/edit/instant.go @@ -4,7 +4,6 @@ import ( "bufio" "io" "os" - "strings" "sync" "github.com/elves/elvish/pkg/cli" @@ -72,7 +71,7 @@ func instantStart(app cli.App, ev *eval.Evaler, binding cli.Handler) { } break } - addLine(strings.TrimRight(line, "\r\n")) + addLine(eval.ChopLineEnding(line)) } } err = fm.PipeOutput( diff --git a/pkg/edit/listing_custom.go b/pkg/edit/listing_custom.go index 431f4ab2..f1e21bc7 100644 --- a/pkg/edit/listing_custom.go +++ b/pkg/edit/listing_custom.go @@ -55,7 +55,7 @@ func listingStartCustom(ed *Editor, fm *eval.Frame, opts customListingOpts, item for { line, err := buffered.ReadString('\n') if line != "" { - s := strings.TrimRight(line, "\r\n") + s := eval.ChopLineEnding(line) collect(listing.Item{ToAccept: s, ToShow: ui.T(s)}) } if err != nil { diff --git a/pkg/eval/compile_value.go b/pkg/eval/compile_value.go index 5ac62c8c..5034e7f9 100644 --- a/pkg/eval/compile_value.go +++ b/pkg/eval/compile_value.go @@ -361,7 +361,7 @@ func captureOutput(fm *Frame, f func(*Frame) error) ([]interface{}, error) { for { line, err := buffered.ReadString('\n') if line != "" { - v := strings.TrimRight(line, "\r\n") + v := ChopLineEnding(line) m.Lock() vs = append(vs, v) m.Unlock() diff --git a/pkg/eval/frame.go b/pkg/eval/frame.go index 1b62c8ff..290c3aaf 100644 --- a/pkg/eval/frame.go +++ b/pkg/eval/frame.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "strings" "sync" "github.com/elves/elvish/pkg/diag" @@ -108,7 +107,7 @@ func linesToChan(r io.Reader, ch chan<- interface{}) { for { line, err := filein.ReadString('\n') if line != "" { - ch <- strings.TrimRight(line, "\r\n") + ch <- ChopLineEnding(line) } if err != nil { if err != io.EOF { diff --git a/pkg/shell/editor.go b/pkg/shell/editor.go index 010114d1..115449ee 100644 --- a/pkg/shell/editor.go +++ b/pkg/shell/editor.go @@ -5,7 +5,8 @@ import ( "fmt" "io" "os" - "strings" + + "github.com/elves/elvish/pkg/eval" ) type editor interface { @@ -28,7 +29,5 @@ func (ed *minEditor) ReadCode() (string, error) { } fmt.Fprintf(ed.out, "%s> ", wd) line, err := ed.in.ReadString('\n') - // Chop off the trailing \r on Windows. - line = strings.TrimRight(line, "\r\n") - return line, err + return eval.ChopLineEnding(line), err }