Update Dependencies (#390)
Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/390 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
7
vendor/github.com/muesli/reflow/ansi/ansi.go
generated
vendored
Normal file
7
vendor/github.com/muesli/reflow/ansi/ansi.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
package ansi
|
||||
|
||||
const Marker = '\x1B'
|
||||
|
||||
func IsTerminator(c rune) bool {
|
||||
return (c >= 0x40 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a)
|
||||
}
|
||||
10
vendor/github.com/muesli/reflow/ansi/buffer.go
generated
vendored
10
vendor/github.com/muesli/reflow/ansi/buffer.go
generated
vendored
@@ -11,26 +11,28 @@ type Buffer struct {
|
||||
bytes.Buffer
|
||||
}
|
||||
|
||||
// PrintableRuneWidth returns the width of all printable runes in the buffer.
|
||||
// PrintableRuneWidth returns the cell width of all printable runes in the
|
||||
// buffer.
|
||||
func (w Buffer) PrintableRuneWidth() int {
|
||||
return PrintableRuneWidth(w.String())
|
||||
}
|
||||
|
||||
// PrintableRuneWidth returns the cell width of the given string.
|
||||
func PrintableRuneWidth(s string) int {
|
||||
var n int
|
||||
var ansi bool
|
||||
|
||||
for _, c := range s {
|
||||
if c == '\x1B' {
|
||||
if c == Marker {
|
||||
// ANSI escape sequence
|
||||
ansi = true
|
||||
} else if ansi {
|
||||
if (c >= 0x40 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) {
|
||||
if IsTerminator(c) {
|
||||
// ANSI sequence terminated
|
||||
ansi = false
|
||||
}
|
||||
} else {
|
||||
n += runewidth.StringWidth(string(c))
|
||||
n += runewidth.RuneWidth(c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
vendor/github.com/muesli/reflow/ansi/writer.go
generated
vendored
43
vendor/github.com/muesli/reflow/ansi/writer.go
generated
vendored
@@ -1,45 +1,48 @@
|
||||
package ansi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Writer struct {
|
||||
Forward io.Writer
|
||||
|
||||
ansi bool
|
||||
ansiseq string
|
||||
lastseq string
|
||||
ansiseq bytes.Buffer
|
||||
lastseq bytes.Buffer
|
||||
seqchanged bool
|
||||
runeBuf []byte
|
||||
}
|
||||
|
||||
// Write is used to write content to the ANSI buffer.
|
||||
func (w *Writer) Write(b []byte) (int, error) {
|
||||
for _, c := range string(b) {
|
||||
if c == '\x1B' {
|
||||
if c == Marker {
|
||||
// ANSI escape sequence
|
||||
w.ansi = true
|
||||
w.seqchanged = true
|
||||
w.ansiseq += string(c)
|
||||
_, _ = w.ansiseq.WriteRune(c)
|
||||
} else if w.ansi {
|
||||
w.ansiseq += string(c)
|
||||
if (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) {
|
||||
_, _ = w.ansiseq.WriteRune(c)
|
||||
if IsTerminator(c) {
|
||||
// ANSI sequence terminated
|
||||
w.ansi = false
|
||||
|
||||
_, _ = w.Forward.Write([]byte(w.ansiseq))
|
||||
if strings.HasSuffix(w.ansiseq, "[0m") {
|
||||
if bytes.HasSuffix(w.ansiseq.Bytes(), []byte("[0m")) {
|
||||
// reset sequence
|
||||
w.lastseq = ""
|
||||
} else if strings.HasSuffix(w.ansiseq, "m") {
|
||||
w.lastseq.Reset()
|
||||
w.seqchanged = false
|
||||
} else if c == 'm' {
|
||||
// color code
|
||||
w.lastseq = w.ansiseq
|
||||
_, _ = w.lastseq.Write(w.ansiseq.Bytes())
|
||||
}
|
||||
w.ansiseq = ""
|
||||
|
||||
_, _ = w.ansiseq.WriteTo(w.Forward)
|
||||
}
|
||||
} else {
|
||||
_, err := w.Forward.Write([]byte(string(c)))
|
||||
_, err := w.writeRune(c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -49,8 +52,16 @@ func (w *Writer) Write(b []byte) (int, error) {
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (w *Writer) writeRune(r rune) (int, error) {
|
||||
if w.runeBuf == nil {
|
||||
w.runeBuf = make([]byte, utf8.UTFMax)
|
||||
}
|
||||
n := utf8.EncodeRune(w.runeBuf, r)
|
||||
return w.Forward.Write(w.runeBuf[:n])
|
||||
}
|
||||
|
||||
func (w *Writer) LastSequence() string {
|
||||
return w.lastseq
|
||||
return w.lastseq.String()
|
||||
}
|
||||
|
||||
func (w *Writer) ResetAnsi() {
|
||||
@@ -61,5 +72,5 @@ func (w *Writer) ResetAnsi() {
|
||||
}
|
||||
|
||||
func (w *Writer) RestoreAnsi() {
|
||||
_, _ = w.Forward.Write([]byte(w.lastseq))
|
||||
_, _ = w.Forward.Write(w.lastseq.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user