mirror of https://github.com/antonmedv/fx
Fix error message code snippet
parent
2e25c7e794
commit
90b6ecc60c
@ -1,32 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ring struct {
|
||||
buf [100]byte
|
||||
buf [70]byte
|
||||
start, end int
|
||||
}
|
||||
|
||||
func (r *ring) writeByte(b byte) {
|
||||
if b == '\n' {
|
||||
r.end = 0
|
||||
r.start = r.end
|
||||
return
|
||||
}
|
||||
r.buf[r.end] = b
|
||||
r.end++
|
||||
if r.end >= len(r.buf) {
|
||||
r.end = 0
|
||||
}
|
||||
r.end = (r.end + 1) % len(r.buf)
|
||||
|
||||
if r.end == r.start {
|
||||
r.start++
|
||||
if r.start >= len(r.buf) {
|
||||
r.start = 0
|
||||
}
|
||||
r.start = (r.start + 1) % len(r.buf)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ring) string() string {
|
||||
if r.start < r.end {
|
||||
return string(r.buf[r.start:r.end])
|
||||
var lines []byte
|
||||
newlineCount := 0
|
||||
|
||||
for i := r.end - 1; ; i-- {
|
||||
if i < 0 {
|
||||
i = len(r.buf) - 1
|
||||
}
|
||||
|
||||
if r.buf[i] == '\n' {
|
||||
newlineCount++
|
||||
if newlineCount == 2 {
|
||||
break
|
||||
}
|
||||
return string(r.buf[r.start:]) + string(r.buf[:r.end])
|
||||
}
|
||||
|
||||
lines = append(lines, r.buf[i])
|
||||
|
||||
if i == r.start {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for i, j := 0, len(lines)-1; i < j; i, j = i+1, j-1 {
|
||||
lines[i], lines[j] = lines[j], lines[i]
|
||||
}
|
||||
|
||||
return strings.TrimRight(string(lines), "\t \n")
|
||||
}
|
||||
|
Loading…
Reference in New Issue