mirror of
https://gitea.com/Sirherobrine23/tea.git
synced 2024-08-20 10:32:36 +00:00
fixes Use Survey For Interactions With User Add Vendor "github.com/AlecAivazis/survey/v2" Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/186 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Norwin <noerw@noreply.gitea.io>
56 lines
951 B
Go
56 lines
951 B
Go
package colorable
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
)
|
|
|
|
// NonColorable holds writer but removes escape sequence.
|
|
type NonColorable struct {
|
|
out io.Writer
|
|
}
|
|
|
|
// NewNonColorable returns new instance of Writer which removes escape sequence from Writer.
|
|
func NewNonColorable(w io.Writer) io.Writer {
|
|
return &NonColorable{out: w}
|
|
}
|
|
|
|
// Write writes data on console
|
|
func (w *NonColorable) Write(data []byte) (n int, err error) {
|
|
er := bytes.NewReader(data)
|
|
var bw [1]byte
|
|
loop:
|
|
for {
|
|
c1, err := er.ReadByte()
|
|
if err != nil {
|
|
break loop
|
|
}
|
|
if c1 != 0x1b {
|
|
bw[0] = c1
|
|
w.out.Write(bw[:])
|
|
continue
|
|
}
|
|
c2, err := er.ReadByte()
|
|
if err != nil {
|
|
break loop
|
|
}
|
|
if c2 != 0x5b {
|
|
continue
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
for {
|
|
c, err := er.ReadByte()
|
|
if err != nil {
|
|
break loop
|
|
}
|
|
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
|
break
|
|
}
|
|
buf.Write([]byte(string(c)))
|
|
}
|
|
}
|
|
|
|
return len(data), nil
|
|
}
|