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())
|
||||
}
|
||||
|
||||
37
vendor/github.com/muesli/reflow/padding/padding.go
generated
vendored
37
vendor/github.com/muesli/reflow/padding/padding.go
generated
vendored
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattn/go-runewidth"
|
||||
|
||||
"github.com/muesli/reflow/ansi"
|
||||
)
|
||||
|
||||
@@ -18,6 +17,7 @@ type Writer struct {
|
||||
|
||||
ansiWriter *ansi.Writer
|
||||
buf bytes.Buffer
|
||||
cache bytes.Buffer
|
||||
lineLen int
|
||||
ansi bool
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func NewWriterPipe(forward io.Writer, width uint, paddingFunc PaddingFunc) *Writ
|
||||
func Bytes(b []byte, width uint) []byte {
|
||||
f := NewWriter(width, nil)
|
||||
_, _ = f.Write(b)
|
||||
f.Close()
|
||||
_ = f.Flush()
|
||||
|
||||
return f.Bytes()
|
||||
}
|
||||
@@ -110,23 +110,34 @@ func (w *Writer) pad() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close will finish the padding operation. Always call it before trying to
|
||||
// retrieve the final result.
|
||||
func (w *Writer) Close() error {
|
||||
// don't pad empty trailing lines
|
||||
if w.lineLen == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return w.pad()
|
||||
// Close will finish the padding operation.
|
||||
func (w *Writer) Close() (err error) {
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
// Bytes returns the padded result as a byte slice.
|
||||
func (w *Writer) Bytes() []byte {
|
||||
return w.buf.Bytes()
|
||||
return w.cache.Bytes()
|
||||
}
|
||||
|
||||
// String returns the padded result as a string.
|
||||
func (w *Writer) String() string {
|
||||
return w.buf.String()
|
||||
return w.cache.String()
|
||||
}
|
||||
|
||||
// Flush will finish the padding operation. Always call it before trying to
|
||||
// retrieve the final result.
|
||||
func (w *Writer) Flush() (err error) {
|
||||
if w.lineLen != 0 {
|
||||
if err = w.pad(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w.cache.Reset()
|
||||
_, err = w.buf.WriteTo(&w.cache)
|
||||
w.lineLen = 0
|
||||
w.ansi = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
20
vendor/github.com/muesli/reflow/wordwrap/wordwrap.go
generated
vendored
20
vendor/github.com/muesli/reflow/wordwrap/wordwrap.go
generated
vendored
@@ -46,7 +46,7 @@ func NewWriter(limit int) *WordWrap {
|
||||
func Bytes(b []byte, limit int) []byte {
|
||||
f := NewWriter(limit)
|
||||
_, _ = f.Write(b)
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
|
||||
return f.Bytes()
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func String(s string, limit int) string {
|
||||
|
||||
func (w *WordWrap) addSpace() {
|
||||
w.lineLen += w.space.Len()
|
||||
w.buf.Write(w.space.Bytes())
|
||||
_, _ = w.buf.Write(w.space.Bytes())
|
||||
w.space.Reset()
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ func (w *WordWrap) addWord() {
|
||||
if w.word.Len() > 0 {
|
||||
w.addSpace()
|
||||
w.lineLen += w.word.PrintableRuneWidth()
|
||||
w.buf.Write(w.word.Bytes())
|
||||
_, _ = w.buf.Write(w.word.Bytes())
|
||||
w.word.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WordWrap) addNewLine() {
|
||||
w.buf.WriteRune('\n')
|
||||
_, _ = w.buf.WriteRune('\n')
|
||||
w.lineLen = 0
|
||||
w.space.Reset()
|
||||
}
|
||||
@@ -101,10 +101,10 @@ func (w *WordWrap) Write(b []byte) (int, error) {
|
||||
for _, c := range s {
|
||||
if c == '\x1B' {
|
||||
// ANSI escape sequence
|
||||
w.word.WriteRune(c)
|
||||
_, _ = w.word.WriteRune(c)
|
||||
w.ansi = true
|
||||
} else if w.ansi {
|
||||
w.word.WriteRune(c)
|
||||
_, _ = w.word.WriteRune(c)
|
||||
if (c >= 0x40 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) {
|
||||
// ANSI sequence terminated
|
||||
w.ansi = false
|
||||
@@ -117,7 +117,7 @@ func (w *WordWrap) Write(b []byte) (int, error) {
|
||||
w.lineLen = 0
|
||||
} else {
|
||||
// preserve whitespace
|
||||
w.buf.Write(w.space.Bytes())
|
||||
_, _ = w.buf.Write(w.space.Bytes())
|
||||
}
|
||||
w.space.Reset()
|
||||
}
|
||||
@@ -127,15 +127,15 @@ func (w *WordWrap) Write(b []byte) (int, error) {
|
||||
} else if unicode.IsSpace(c) {
|
||||
// end of current word
|
||||
w.addWord()
|
||||
w.space.WriteRune(c)
|
||||
_, _ = w.space.WriteRune(c)
|
||||
} else if inGroup(w.Breakpoints, c) {
|
||||
// valid breakpoint
|
||||
w.addSpace()
|
||||
w.addWord()
|
||||
w.buf.WriteRune(c)
|
||||
_, _ = w.buf.WriteRune(c)
|
||||
} else {
|
||||
// any other character
|
||||
w.word.WriteRune(c)
|
||||
_, _ = w.word.WriteRune(c)
|
||||
|
||||
// add a line break if the current word would exceed the line's
|
||||
// character limit
|
||||
|
||||
Reference in New Issue
Block a user