Skip to content

Commit 90af473

Browse files
authored
Merge pull request #779 from noborus/trim-right
Remove extra spaces on the right in WriteQuit
2 parents 62590d6 + c84422d commit 90af473

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/klauspost/compress v1.18.0
1616
github.com/mattn/go-runewidth v0.0.16
1717
github.com/noborus/guesswidth v0.4.0
18-
github.com/noborus/tcellansi v0.0.0-20250320075053-376e9cb3c42b
18+
github.com/noborus/tcellansi v0.1.0
1919
github.com/pierrec/lz4/v4 v4.1.22
2020
github.com/rivo/uniseg v0.4.7
2121
github.com/spf13/cobra v1.9.1
@@ -36,10 +36,10 @@ require (
3636
github.com/sagikazarmark/locafero v0.9.0 // indirect
3737
github.com/sourcegraph/conc v0.3.0 // indirect
3838
github.com/spf13/afero v1.14.0 // indirect
39-
github.com/spf13/cast v1.7.1 // indirect
39+
github.com/spf13/cast v1.8.0 // indirect
4040
github.com/subosito/gotenv v1.6.0 // indirect
4141
go.uber.org/multierr v1.11.0 // indirect
4242
golang.org/x/sys v0.33.0 // indirect
43-
golang.org/x/text v0.24.0 // indirect
43+
golang.org/x/text v0.25.0 // indirect
4444
gopkg.in/yaml.v3 v3.0.1 // indirect
4545
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
4040
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
4141
github.com/noborus/guesswidth v0.4.0 h1:+PPh+Z+GM4mKmVrhYR4lpjeyBuLMSVo2arM+VErdHIc=
4242
github.com/noborus/guesswidth v0.4.0/go.mod h1:ghA6uh9RcK+uSmaDDmBMj/tRZ3BSpspDP6DMF5Xk3bc=
43-
github.com/noborus/tcellansi v0.0.0-20250320075053-376e9cb3c42b h1:5EpdRpG4A6J1vK/vwVLczm3l1hB4KwmlqHdsFgfTffc=
44-
github.com/noborus/tcellansi v0.0.0-20250320075053-376e9cb3c42b/go.mod h1:uZyUH8CuoepBfZgDzh8xV3z1sZFAw97hN8otIuZT5jA=
43+
github.com/noborus/tcellansi v0.1.0 h1:oYaYAHS0kB2gR6hBmn8KN9uZrINB4c/OsUuj5jsnOXw=
44+
github.com/noborus/tcellansi v0.1.0/go.mod h1:MIOzvoK75Q/5sN2ac4mG8WCZM3xoHW8HdGhRWdJXomk=
4545
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
4646
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
4747
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
@@ -61,8 +61,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS
6161
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
6262
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
6363
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
64-
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
65-
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
64+
github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk=
65+
github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
6666
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6767
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
6868
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
@@ -141,8 +141,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
141141
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
142142
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
143143
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
144-
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
145-
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
144+
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
145+
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
146146
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
147147
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
148148
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

oviewer/oviewer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ func (root *Root) writeCurrentScreen(output io.Writer) {
11771177
return
11781178
}
11791179
strs = tcellansi.ScreenContentToStrings(root.Screen, 0, root.Doc.width, 0, height-1)
1180+
strs = tcellansi.TrimRightSpaces(strs)
11801181
}
11811182
for _, str := range strs {
11821183
if _, err := output.Write([]byte(str)); err != nil {
@@ -1228,7 +1229,9 @@ func (root *Root) ScreenContent() []string {
12281229
root.Screen.Sync()
12291230
m := root.Doc
12301231
height := realHeight(root.scr)
1231-
return tcellansi.ScreenContentToStrings(root.Screen, 0, m.width, 0, height)
1232+
strs := tcellansi.ScreenContentToStrings(root.Screen, 0, m.width, 0, height)
1233+
strs = tcellansi.TrimRightSpaces(strs)
1234+
return strs
12321235
}
12331236

12341237
// writeOriginal writes to the original terminal.

oviewer/oviewer_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,16 @@ func TestRoot_outputOnExit(t *testing.T) {
13871387
IsWriteOnExit: true,
13881388
IsWriteOriginal: false,
13891389
},
1390-
wantOutput: "test \x1B[0m\n",
1390+
wantOutput: "test\n",
1391+
},
1392+
{
1393+
name: "writeCurrentScreen_test4",
1394+
fields: fields{
1395+
fileName: filepath.Join(testdata, "test4.txt"),
1396+
IsWriteOnExit: true,
1397+
IsWriteOriginal: false,
1398+
},
1399+
wantOutput: "\x1b[38;2;255;175;135m\x1b[1mHello\033[0m\n",
13911400
},
13921401
{
13931402
name: "writeOriginal",

testdata/test4.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello

0 commit comments

Comments
 (0)