mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-22 05:29:44 +02:00
NormalizeLinefeeds removes rather than converts Window/Mac style lf's
This commit is contained in:
parent
d2bdac29aa
commit
766197de9d
@ -219,7 +219,8 @@ func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
v.Clear()
|
v.Clear()
|
||||||
output := utils.NormalizeLinefeeds(string(bom.Clean([]byte(s))))
|
output := string(bom.Clean([]byte(s)))
|
||||||
|
output = utils.NormalizeLinefeeds(s)
|
||||||
fmt.Fprint(v, output)
|
fmt.Fprint(v, output)
|
||||||
v.Wrap = true
|
v.Wrap = true
|
||||||
return nil
|
return nil
|
||||||
|
@ -64,9 +64,10 @@ func TrimTrailingNewline(str string) string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NormalizeLinefeeds - Removes all Windows and Mac style line feeds
|
||||||
func NormalizeLinefeeds(str string) string {
|
func NormalizeLinefeeds(str string) string {
|
||||||
str = strings.Replace(str, "\r\n", "\n", -1)
|
str = strings.Replace(str, "\r\n", "", -1)
|
||||||
str = strings.Replace(str, "\r", "\n", -1)
|
str = strings.Replace(str, "\r", "", -1)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,32 +3,32 @@ package utils
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var testCases = []struct {
|
var testCases = []struct {
|
||||||
Input []byte
|
Input []byte
|
||||||
Expected []byte
|
Expected []byte
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
// \r\n
|
// \r\n
|
||||||
Input: []byte{97, 115, 100, 102, 13, 10},
|
Input: []byte{97, 115, 100, 102, 13, 10},
|
||||||
Expected: []byte{97, 115, 100, 102, 10},
|
Expected: []byte{97, 115, 100, 102},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// \r
|
// \r
|
||||||
Input: []byte{97, 115, 100, 102, 13},
|
Input: []byte{97, 115, 100, 102, 13},
|
||||||
Expected: []byte{97, 115, 100, 102, 10},
|
Expected: []byte{97, 115, 100, 102},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// \n
|
// \n
|
||||||
Input: []byte{97, 115, 100, 102, 10},
|
Input: []byte{97, 115, 100, 102, 10},
|
||||||
Expected: []byte{97, 115, 100, 102, 10},
|
Expected: []byte{97, 115, 100, 102, 10},
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalizeLinefeeds(t *testing.T) {
|
func TestNormalizeLinefeeds(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
if NormalizeLinefeeds(string(tc.Input)) != string(tc.Expected) {
|
input := NormalizeLinefeeds(string(tc.Input))
|
||||||
t.Error("Error")
|
expected := string(tc.Expected)
|
||||||
|
if input != expected {
|
||||||
|
t.Error("Expected " + expected + ", got " + input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user