mirror of
https://gitea.com/gitea/tea
synced 2024-05-08 08:46:07 +02:00
0d98cbd657
* update & migrate gitea sdk (Fix Delete Tag Issue) * upgraded github.com/AlecAivazis/survey v2.2.7 => v2.2.8 * upgraded github.com/adrg/xdg v0.2.3 => v0.3.1 * upgraded github.com/araddon/dateparse * upgraded github.com/olekukonko/tablewriter v0.0.4 => v0.0.5 * upgraded gopkg.in/yaml.v2 v2.3.0 => v2.4.0 Reviewed-on: https://gitea.com/gitea/tea/pulls/337 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
34 lines
604 B
Go
34 lines
604 B
Go
package ansi
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/mattn/go-runewidth"
|
|
)
|
|
|
|
// Buffer is a buffer aware of ANSI escape sequences.
|
|
type Buffer struct {
|
|
bytes.Buffer
|
|
}
|
|
|
|
// PrintableRuneCount returns the amount of printable runes in the buffer.
|
|
func (w Buffer) PrintableRuneCount() int {
|
|
var n int
|
|
var ansi bool
|
|
for _, c := range w.String() {
|
|
if c == '\x1B' {
|
|
// ANSI escape sequence
|
|
ansi = true
|
|
} else if ansi {
|
|
if (c >= 0x40 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) {
|
|
// ANSI sequence terminated
|
|
ansi = false
|
|
}
|
|
} else {
|
|
n += runewidth.StringWidth(string(c))
|
|
}
|
|
}
|
|
|
|
return n
|
|
}
|