Something went wrong. Try again.
[mirror] Tool for collecting work URLs from AO3 list views
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556package logbuffer
import ( "fmt" "io" "strings")
type LogBuffer struct { stream *[]string}
func NewLogBuffer() LogBuffer { return LogBuffer{ stream: &[]string{}, }}
func (l LogBuffer) Write(p []byte) (n int, err error) { str := string(p)
strs := strings.Split(str, "\n")
if len(*l.stream) == 0 { *l.stream = append(*l.stream, "") }
if len(strs) >= 1 { (*l.stream)[len(*l.stream)-1] += strs[0] }
if len(strs) >= 2 { *l.stream = append(*l.stream, strs[1:]...) }
return len(p), nil}
func (l LogBuffer) GetAtMostFromEnd(lines int) []string { if lines <= 0 { return []string{} }
if lines > len(*l.stream) { return *l.stream }
return (*l.stream)[len(*l.stream)-lines:]}
func (l LogBuffer) Dump(writer io.Writer) { for _, line := range *l.stream { fmt.Fprintln(writer, line) }}