pkg/eval: Use eval.ChopLineEnding everywhere for removing line ending.

This commit is contained in:
Qi Xiao 2020-05-06 23:10:57 +01:00
parent 721a0026df
commit eb37f92300
6 changed files with 8 additions and 11 deletions

View File

@ -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

View File

@ -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(

View File

@ -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 {

View File

@ -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()

View File

@ -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 {

View File

@ -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
}