mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Support handling indents with an IndentFunc
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
package gold
|
package gold
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IndentFunc = func(w io.Writer)
|
||||||
|
|
||||||
type IndentWriter struct {
|
type IndentWriter struct {
|
||||||
Forward *AnsiWriter
|
Forward *AnsiWriter
|
||||||
Indent uint
|
Indent uint
|
||||||
|
IndentFunc IndentFunc
|
||||||
|
|
||||||
skipIndent bool
|
skipIndent bool
|
||||||
}
|
}
|
||||||
@@ -15,12 +19,18 @@ type IndentWriter struct {
|
|||||||
func (w *IndentWriter) Write(b []byte) (int, error) {
|
func (w *IndentWriter) Write(b []byte) (int, error) {
|
||||||
for _, c := range string(b) {
|
for _, c := range string(b) {
|
||||||
if !w.skipIndent {
|
if !w.skipIndent {
|
||||||
|
if w.IndentFunc != nil {
|
||||||
|
for i := 0; i < int(w.Indent); i++ {
|
||||||
|
w.IndentFunc(w.Forward)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
_, err := w.Forward.Write([]byte(strings.Repeat(" ", int(w.Indent))))
|
_, err := w.Forward.Write([]byte(strings.Repeat(" ", int(w.Indent))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
w.Forward.RestoreAnsi()
|
}
|
||||||
|
|
||||||
|
w.Forward.RestoreAnsi()
|
||||||
w.skipIndent = true
|
w.skipIndent = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user