File tree 1 file changed +4
-40
lines changed
1 file changed +4
-40
lines changed Original file line number Diff line number Diff line change 1
1
package layout
2
2
3
3
import (
4
- "bytes"
5
4
"strings"
6
5
7
6
"github.com/charmbracelet/lipgloss"
8
- "github.com/opencode-ai/opencode/internal/tui/styles"
9
- "github.com/opencode-ai/opencode/internal/tui/util"
10
- "github.com/mattn/go-runewidth"
7
+ chAnsi "github.com/charmbracelet/x/ansi"
11
8
"github.com/muesli/ansi"
12
9
"github.com/muesli/reflow/truncate"
13
10
"github.com/muesli/termenv"
11
+ "github.com/opencode-ai/opencode/internal/tui/styles"
12
+ "github.com/opencode-ai/opencode/internal/tui/util"
14
13
)
15
14
16
15
// Most of this code is borrowed from
@@ -117,42 +116,7 @@ func PlaceOverlay(
117
116
// cutLeft cuts printable characters from the left.
118
117
// This function is heavily based on muesli's ansi and truncate packages.
119
118
func cutLeft (s string , cutWidth int ) string {
120
- var (
121
- pos int
122
- isAnsi bool
123
- ab bytes.Buffer
124
- b bytes.Buffer
125
- )
126
- for _ , c := range s {
127
- var w int
128
- if c == ansi .Marker || isAnsi {
129
- isAnsi = true
130
- ab .WriteRune (c )
131
- if ansi .IsTerminator (c ) {
132
- isAnsi = false
133
- if bytes .HasSuffix (ab .Bytes (), []byte ("[0m" )) {
134
- ab .Reset ()
135
- }
136
- }
137
- } else {
138
- w = runewidth .RuneWidth (c )
139
- }
140
-
141
- if pos >= cutWidth {
142
- if b .Len () == 0 {
143
- if ab .Len () > 0 {
144
- b .Write (ab .Bytes ())
145
- }
146
- if pos - cutWidth > 1 {
147
- b .WriteByte (' ' )
148
- continue
149
- }
150
- }
151
- b .WriteRune (c )
152
- }
153
- pos += w
154
- }
155
- return b .String ()
119
+ return chAnsi .Cut (s , cutWidth , lipgloss .Width (s ))
156
120
}
157
121
158
122
func max (a , b int ) int {
You can’t perform that action at this time.
0 commit comments