fix backtracking of line wrappers
This commit is contained in:
parent
4bc054c9ac
commit
5140794b16
@ -1,8 +1,5 @@
|
|||||||
# Notation - print Go objects
|
# Notation - print Go objects
|
||||||
|
|
||||||
[](https://goreportcard.com/report/github.com/aryszka/notation)
|
|
||||||
[](https://codecov.io/gh/aryszka/notation)
|
|
||||||
|
|
||||||
This package can be used to print (or sprint) Go objects for debugging purposes, with optional wrapping
|
This package can be used to print (or sprint) Go objects for debugging purposes, with optional wrapping
|
||||||
(indentation) and optional type information.
|
(indentation) and optional type information.
|
||||||
|
|
||||||
@ -18,7 +15,7 @@ Notation differs from these primarily in the 'flavor' of printing and the packag
|
|||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
`go get github.com/aryszka/notation`
|
`go get code.squareroundforest.org/arpio/notation`
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@ -44,8 +41,8 @@ Wrapping is **not eager**. It doesn't wrap a line when it can fit on 72 columns.
|
|||||||
to 112 columns, when the output is considered to be more readable that way. This means very simple Go objects
|
to 112 columns, when the output is considered to be more readable that way. This means very simple Go objects
|
||||||
are not wrapped even with the **`w`** variant of the functions.
|
are not wrapped even with the **`w`** variant of the functions.
|
||||||
|
|
||||||
For the available functions, see also the [godoc](https://godoc.org/github.com/aryszka/notation).
|
For the available functions, see also the [godoc](https://godoc.org/code.squareroundforest.org/arpio/notation).
|
||||||
(Alternatively: [pkg.go.dev](https://pkg.go.dev/github.com/aryszka/notation).)
|
(Alternatively: [pkg.go.dev](https://pkg.go.dev/squareroundforest.org/arpio/notation).)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package notation_test
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/aryszka/notation"
|
"code.squareroundforest.org/arpio/notation"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bike struct {
|
type bike struct {
|
||||||
|
|||||||
@ -290,6 +290,7 @@ func wrapNode(t, cf0, c0, c1 int, n node) node {
|
|||||||
//
|
//
|
||||||
cl := cf0 - t
|
cl := cf0 - t
|
||||||
var w int
|
var w int
|
||||||
|
part.lineEnds = nil
|
||||||
for j, nj := range part.items {
|
for j, nj := range part.items {
|
||||||
if w > 0 && w+len(part.sep)+nj.len > cl {
|
if w > 0 && w+len(part.sep)+nj.len > cl {
|
||||||
part.lineEnds = append(part.lineEnds, j)
|
part.lineEnds = append(part.lineEnds, j)
|
||||||
|
|||||||
46
notation.go
46
notation.go
@ -181,6 +181,16 @@ 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) {
|
||||||
|
n, err := fprintValues(w, o, v)
|
||||||
|
if err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nn, err := w.Write([]byte("\n"))
|
||||||
|
return n + nn, err
|
||||||
|
}
|
||||||
|
|
||||||
func printValues(o opts, v []interface{}) (int, error) {
|
func printValues(o opts, v []interface{}) (int, error) {
|
||||||
return fprintValues(stderr, o, v)
|
return fprintValues(stderr, o, v)
|
||||||
}
|
}
|
||||||
@ -237,6 +247,42 @@ func Fprintwv(w io.Writer, v ...interface{}) (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
|
||||||
|
// separated by a space.
|
||||||
|
func Fprintln(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
return fprintlnValues(w, none, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func Fprintlnw(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
return fprintlnValues(w, wrap, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func Fprintlnt(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
return fprintlnValues(w, types, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func Fprintlnwt(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
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
|
||||||
|
// objects are printed, they'll be separated by a space.
|
||||||
|
func Fprintlnv(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
return fprintlnValues(w, allTypes, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func Fprintlnwv(w io.Writer, v ...interface{}) (int, error) {
|
||||||
|
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 ...interface{}) (int, error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user