support printing to a logger
This commit is contained in:
parent
5e2cff8642
commit
2ec220c1de
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module code.squareroundforest.org/arpio/notation
|
module code.squareroundforest.org/arpio/notation
|
||||||
|
|
||||||
go 1.15
|
go 1.26.0
|
||||||
|
|||||||
126
notation.go
126
notation.go
@ -41,7 +41,7 @@ type pending struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
parts []interface{}
|
parts []any
|
||||||
len int
|
len int
|
||||||
wrapLen wrapLen
|
wrapLen wrapLen
|
||||||
fullWrap wrapLen
|
fullWrap wrapLen
|
||||||
@ -77,7 +77,7 @@ type writer struct {
|
|||||||
|
|
||||||
var stderr io.Writer = os.Stderr
|
var stderr io.Writer = os.Stderr
|
||||||
|
|
||||||
func nodeOf(parts ...interface{}) node {
|
func nodeOf(parts ...any) node {
|
||||||
return node{parts: parts}
|
return node{parts: parts}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func (s str) String() string {
|
|||||||
return s.val
|
return s.val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writer) write(o interface{}) {
|
func (w *writer) write(o any) {
|
||||||
if w.err != nil {
|
if w.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func config(name string, dflt int) int {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func fprintValues(w io.Writer, o opts, v []interface{}) (int, error) {
|
func fprintValues(w io.Writer, o opts, v []any) (int, error) {
|
||||||
tab := config("TABWIDTH", 8)
|
tab := config("TABWIDTH", 8)
|
||||||
cols0 := config("LINEWIDTH", 80-tab)
|
cols0 := config("LINEWIDTH", 80-tab)
|
||||||
cols1 := config("LINEWIDTH1", (cols0+tab)*3/2-tab)
|
cols1 := config("LINEWIDTH1", (cols0+tab)*3/2-tab)
|
||||||
@ -181,7 +181,7 @@ func fprintValues(w io.Writer, o opts, v []interface{}) (int, error) {
|
|||||||
return wr.n, wr.err
|
return wr.n, wr.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func fprintlnValues(w io.Writer, o opts, v []interface{}) (int, error) {
|
func fprintlnValues(w io.Writer, o opts, v []any) (int, error) {
|
||||||
n, err := fprintValues(w, o, v)
|
n, err := fprintValues(w, o, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
@ -191,11 +191,11 @@ func fprintlnValues(w io.Writer, o opts, v []interface{}) (int, error) {
|
|||||||
return n + nn, err
|
return n + nn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printValues(o opts, v []interface{}) (int, error) {
|
func printValues(o opts, v []any) (int, error) {
|
||||||
return fprintValues(stderr, o, v)
|
return fprintValues(stderr, o, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printlnValues(o opts, v []interface{}) (int, error) {
|
func printlnValues(o opts, v []any) (int, error) {
|
||||||
n, err := fprintValues(stderr, o, v)
|
n, err := fprintValues(stderr, o, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
@ -205,7 +205,7 @@ func printlnValues(o opts, v []interface{}) (int, error) {
|
|||||||
return n + nn, err
|
return n + nn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func sprintValues(o opts, v []interface{}) string {
|
func sprintValues(o opts, v []any) string {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
fprintValues(&b, o, v)
|
fprintValues(&b, o, v)
|
||||||
return b.String()
|
return b.String()
|
||||||
@ -213,182 +213,220 @@ func sprintValues(o opts, v []interface{}) string {
|
|||||||
|
|
||||||
// Fprint prints the provided objects to the provided writer. When multiple objects are printed, they'll be
|
// Fprint prints the provided objects to the provided writer. When multiple objects are printed, they'll be
|
||||||
// separated by a space.
|
// separated by a space.
|
||||||
func Fprint(w io.Writer, v ...interface{}) (int, error) {
|
func Fprint(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, none, v)
|
return fprintValues(w, none, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintw prints the provided objects to the provided writer, with wrapping (and indentation) where necessary.
|
// Fprintw prints the provided objects to the provided writer, with wrapping (and indentation) where necessary.
|
||||||
// When multiple objects are printed, they'll be separated by a newline.
|
// When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintw(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintw(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, wrap, v)
|
return fprintValues(w, wrap, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintt prints the provided objects to the provided writer with moderate type information. When multiple
|
// Fprintt prints the provided objects to the provided writer with moderate type information. When multiple
|
||||||
// objects are printed, they'll be separated by a space.
|
// objects are printed, they'll be separated by a space.
|
||||||
func Fprintt(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintt(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, types, v)
|
return fprintValues(w, types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintwt prints the provided objects to the provided writer, with wrapping (and indentation) where necessary,
|
// Fprintwt prints the provided objects to the provided writer, with wrapping (and indentation) where necessary,
|
||||||
// and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
// and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintwt(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintwt(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, wrap|types, v)
|
return fprintValues(w, wrap|types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintv prints the provided objects to the provided writer with verbose type information. When multiple
|
// Fprintv prints the provided objects to the provided writer with verbose type information. When multiple
|
||||||
// objects are printed, they'll be separated by a space.
|
// objects are printed, they'll be separated by a space.
|
||||||
func Fprintv(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintv(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, allTypes, v)
|
return fprintValues(w, allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintwv prints the provided objects to the provided writer, with wrapping (and indentation) where necessary,
|
// Fprintwv prints the provided objects to the provided writer, with wrapping (and indentation) where necessary,
|
||||||
// and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
// and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintwv(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintwv(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintValues(w, wrap|allTypes, v)
|
return fprintValues(w, wrap|allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintln prints the provided objects to the provided writer with a closing newline. When multiple objects are printed, they'll be
|
// Fprintln prints the provided objects to the provided writer with a closing newline. When multiple objects are printed, they'll be
|
||||||
// separated by a space.
|
// separated by a space.
|
||||||
func Fprintln(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintln(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, none, v)
|
return fprintlnValues(w, none, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintlnw prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary.
|
// Fprintlnw prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary.
|
||||||
// When multiple objects are printed, they'll be separated by a newline.
|
// When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintlnw(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintlnw(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, wrap, v)
|
return fprintlnValues(w, wrap, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintlnt prints the provided objects to the provided writer with a closing newline, with moderate type information. When multiple
|
// Fprintlnt prints the provided objects to the provided writer with a closing newline, with moderate type information. When multiple
|
||||||
// objects are printed, they'll be separated by a space.
|
// objects are printed, they'll be separated by a space.
|
||||||
func Fprintlnt(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintlnt(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, types, v)
|
return fprintlnValues(w, types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintlnwt prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary,
|
// Fprintlnwt prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary,
|
||||||
// and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
// and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintlnwt(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintlnwt(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, wrap|types, v)
|
return fprintlnValues(w, wrap|types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintv prints the provided objects to the provided writer with a closing newline, with verbose type information. When multiple
|
// Fprintv prints the provided objects to the provided writer with a closing newline, with verbose type information. When multiple
|
||||||
// objects are printed, they'll be separated by a space.
|
// objects are printed, they'll be separated by a space.
|
||||||
func Fprintlnv(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintlnv(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, allTypes, v)
|
return fprintlnValues(w, allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fprintlnwv prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary,
|
// Fprintlnwv prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary,
|
||||||
// and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
// and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Fprintlnwv(w io.Writer, v ...interface{}) (int, error) {
|
func Fprintlnwv(w io.Writer, v ...any) (int, error) {
|
||||||
return fprintlnValues(w, wrap|allTypes, v)
|
return fprintlnValues(w, wrap|allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print prints the provided objects to stderr. When multiple objects are printed, they'll be separated by a
|
// Print prints the provided objects to stderr. When multiple objects are printed, they'll be separated by a
|
||||||
// space.
|
// space.
|
||||||
func Print(v ...interface{}) (int, error) {
|
func Print(v ...any) (int, error) {
|
||||||
return printValues(none, v)
|
return printValues(none, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printw prints the provided objects to stderr, with wrapping (and indentation) where necessary. When multiple
|
// Printw prints the provided objects to stderr, with wrapping (and indentation) where necessary. When multiple
|
||||||
// objects are printed, they'll be separated by a newline.
|
// objects are printed, they'll be separated by a newline.
|
||||||
func Printw(v ...interface{}) (int, error) {
|
func Printw(v ...any) (int, error) {
|
||||||
return printValues(wrap, v)
|
return printValues(wrap, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printt prints the provided objects to stderr with moderate type information. When multiple objects are
|
// Printt prints the provided objects to stderr with moderate type information. When multiple objects are
|
||||||
// printed, they'll be separated by a space.
|
// printed, they'll be separated by a space.
|
||||||
func Printt(v ...interface{}) (int, error) {
|
func Printt(v ...any) (int, error) {
|
||||||
return printValues(types, v)
|
return printValues(types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printwt prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with
|
// Printwt prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with
|
||||||
// moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
// moderate type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Printwt(v ...interface{}) (int, error) {
|
func Printwt(v ...any) (int, error) {
|
||||||
return printValues(wrap|types, v)
|
return printValues(wrap|types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printv prints the provided objects to stderr with verbose type information. When multiple objects are
|
// Printv prints the provided objects to stderr with verbose type information. When multiple objects are
|
||||||
// printed, they'll be separated by a space.
|
// printed, they'll be separated by a space.
|
||||||
func Printv(v ...interface{}) (int, error) {
|
func Printv(v ...any) (int, error) {
|
||||||
return printValues(allTypes, v)
|
return printValues(allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printwv prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with
|
// Printwv prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with
|
||||||
// verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
// verbose type information. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Printwv(v ...interface{}) (int, error) {
|
func Printwv(v ...any) (int, error) {
|
||||||
return printValues(wrap|allTypes, v)
|
return printValues(wrap|allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Println prints the provided objects to stderr with a closing newline. When multiple objects are printed,
|
// Println prints the provided objects to stderr with a closing newline. When multiple objects are printed,
|
||||||
// they'll be separated by a space.
|
// they'll be separated by a space.
|
||||||
func Println(v ...interface{}) (int, error) {
|
func Println(v ...any) (int, error) {
|
||||||
return printlnValues(none, v)
|
return printlnValues(none, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printlnw prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
// Printlnw prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
||||||
// necessary. When multiple objects are printed, they'll be separated by a newline.
|
// necessary. When multiple objects are printed, they'll be separated by a newline.
|
||||||
func Printlnw(v ...interface{}) (int, error) {
|
func Printlnw(v ...any) (int, error) {
|
||||||
return printlnValues(wrap, v)
|
return printlnValues(wrap, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printlnt prints the provided objects to stderr with a closing newline, and with moderate type information. When
|
// Printlnt prints the provided objects to stderr with a closing newline, and with moderate type information. When
|
||||||
// multiple objects are printed, they'll be separated by a space.
|
// multiple objects are printed, they'll be separated by a space.
|
||||||
func Printlnt(v ...interface{}) (int, error) {
|
func Printlnt(v ...any) (int, error) {
|
||||||
return printlnValues(types, v)
|
return printlnValues(types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printlnwt prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
// Printlnwt prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
||||||
// necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a
|
// necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a
|
||||||
// newline.
|
// newline.
|
||||||
func Printlnwt(v ...interface{}) (int, error) {
|
func Printlnwt(v ...any) (int, error) {
|
||||||
return printlnValues(wrap|types, v)
|
return printlnValues(wrap|types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printlnv prints the provided objects to stderr with a closing newline, and with verbose type information. When
|
// Printlnv prints the provided objects to stderr with a closing newline, and with verbose type information. When
|
||||||
// multiple objects are printed, they'll be separated by a space.
|
// multiple objects are printed, they'll be separated by a space.
|
||||||
func Printlnv(v ...interface{}) (int, error) {
|
func Printlnv(v ...any) (int, error) {
|
||||||
return printlnValues(allTypes, v)
|
return printlnValues(allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printlnwv prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
// Printlnwv prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where
|
||||||
// necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a
|
// necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a
|
||||||
// newline.
|
// newline.
|
||||||
func Printlnwv(v ...interface{}) (int, error) {
|
func Printlnwv(v ...any) (int, error) {
|
||||||
return printlnValues(wrap|allTypes, v)
|
return printlnValues(wrap|allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprint returns the string representation of the Go objects. When multiple objects are provided, they'll be
|
// Sprint returns the string representation of the Go objects. When multiple objects are provided, they'll be
|
||||||
// seprated by a space.
|
// separated by a space.
|
||||||
func Sprint(v ...interface{}) string {
|
func Sprint(v ...any) string {
|
||||||
return sprintValues(none, v)
|
return sprintValues(none, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprintw returns the string representation of the Go objects, with wrapping (and indentation) where necessary.
|
// Sprintw returns the string representation of the Go objects, with wrapping (and indentation) where necessary.
|
||||||
// When multiple objects are provided, they'll be seprated by a newline.
|
// When multiple objects are provided, they'll be separated by a newline.
|
||||||
func Sprintw(v ...interface{}) string {
|
func Sprintw(v ...any) string {
|
||||||
return sprintValues(wrap, v)
|
return sprintValues(wrap, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprintt returns the string representation of the Go objects, with moderate type information. When multiple
|
// Sprintt returns the string representation of the Go objects, with moderate type information. When multiple
|
||||||
// objects are provided, they'll be seprated by a space.
|
// objects are provided, they'll be separated by a space.
|
||||||
func Sprintt(v ...interface{}) string {
|
func Sprintt(v ...any) string {
|
||||||
return sprintValues(types, v)
|
return sprintValues(types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprintwt returns the string representation of the Go objects, with wrapping (and indentation) where necessary,
|
// Sprintwt returns the string representation of the Go objects, with wrapping (and indentation) where necessary,
|
||||||
// and with moderate type information. When multiple objects are provided, they'll be seprated by a newline.
|
// and with moderate type information. When multiple objects are provided, they'll be separated by a newline.
|
||||||
func Sprintwt(v ...interface{}) string {
|
func Sprintwt(v ...any) string {
|
||||||
return sprintValues(wrap|types, v)
|
return sprintValues(wrap|types, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprintv returns the string representation of the Go objects, with verbose type information. When multiple
|
// Sprintv returns the string representation of the Go objects, with verbose type information. When multiple
|
||||||
// objects are provided, they'll be seprated by a space.
|
// objects are provided, they'll be separated by a space.
|
||||||
func Sprintv(v ...interface{}) string {
|
func Sprintv(v ...any) string {
|
||||||
return sprintValues(allTypes, v)
|
return sprintValues(allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprintwv returns the string representation of the Go objects, with wrapping (and indentation) where necessary,
|
// Sprintwv returns the string representation of the Go objects, with wrapping (and indentation) where necessary,
|
||||||
// and with verbose type information. When multiple objects are provided, they'll be seprated by a newline.
|
// and with verbose type information. When multiple objects are provided, they'll be separated by a newline.
|
||||||
func Sprintwv(v ...interface{}) string {
|
func Sprintwv(v ...any) string {
|
||||||
return sprintValues(wrap|allTypes, v)
|
return sprintValues(wrap|allTypes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lprint prints the string representation of the Go objects onto the provided logging object. When multiple
|
||||||
|
// objects are provided, they'll be separated by a space.
|
||||||
|
func Lprint(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprint(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lprintw prints the string representation of the Go objects onto the provided logging object, with wrapping
|
||||||
|
// (and indentation) where necessary. When multiple objects are provided, they'll be separated by a newline.
|
||||||
|
func Lprintw(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprintw(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lprintt prints the string representation of the Go objects onto the provided logging object, with moderate
|
||||||
|
// type information. When multiple objects are provided, they'll be separated by a space.
|
||||||
|
func Lprintt(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprintt(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lprintwt prints the string representation of the Go objects onto the provided logging object, with wrapping
|
||||||
|
// (and indentation) where necessary, and with moderate type information. When multiple objects are provided,
|
||||||
|
// they'll be separated by a newline.
|
||||||
|
func Lprintwt(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprintwt(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lprintv prints the string representation of the Go objects onto the provided logging object, with verbose
|
||||||
|
// type information. When multiple objects are provided, they'll be separated by a space.
|
||||||
|
func Lprintv(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprintv(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lprintwv prints the string representation of the Go objects onto the provided logging object, with wrapping
|
||||||
|
// (and indentation) where necessary, and with verbose type information. When multiple objects are provided,
|
||||||
|
// they'll be separated by a newline.
|
||||||
|
func Lprintwv(t interface{ Log(v ...any) }, v ...any) {
|
||||||
|
t.Log(Sprintwv(v...))
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user