-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strange tree #2
Comments
Good catch, thanks! |
Thanks for fixing this. BTW, why you use 0x00 0xa0 for indentation? Line 164 in 2075aa9
On some character-set, for example japanese, it is shown as |
It's expected to be Unicode friendly. As far as I can remember I use the same |
This is output on Windows. Do you want workaround fixes only on Windows? |
One more thing. Corner string |
This package will never be platform-specific, as its output is statically defined and may be parsed in logs during process mining. The data it outputs is prevailing over the looks. |
So you don't want fixing for east asian ambiguous widths. Right? I don't have strong opinion about this. Just confirming how do you think. :) |
I'm ready to fix any issue as long as it's universal for all possible platforms and locales. If we can replace the spacing char so it will work fine with Unicode and asian encodings then let's do it. My point is that there should be no exception cases. |
Most easy way to fix this issue is: diff --git a/treeprint.go b/treeprint.go
index 467c87d..7412518 100644
--- a/treeprint.go
+++ b/treeprint.go
@@ -6,6 +6,9 @@ import (
"fmt"
"io"
"reflect"
+ "runtime"
+
+ "github.com/mattn/go-runewidth"
)
type Value interface{}
@@ -156,12 +159,25 @@ func printNodes(wr io.Writer,
func printValues(wr io.Writer,
level int, levelsEnded []int, edge EdgeType, meta MetaValue, val Value) {
+ var edgeTypeLink, spaces string
+ if !runewidth.IsEastAsian() {
+ spaces = " "
+ if runtime.GOOS == "windows" {
+ edgeTypeLink = string(EdgeTypeLink) + " "
+ } else {
+ edgeTypeLink = string(EdgeTypeLink) + " "
+ }
+ } else {
+ spaces = " "
+ edgeTypeLink = string(EdgeTypeLink) + " "
+ }
+
for i := 0; i < level; i++ {
if isEnded(levelsEnded, i) {
- fmt.Fprint(wr, " ")
+ fmt.Fprint(wr, spaces)
continue
}
- fmt.Fprintf(wr, "%s ", EdgeTypeLink)
+ fmt.Fprint(wr, edgeTypeLink)
}
if meta != nil {
fmt.Fprintf(wr, "%s [%v] %v\n", edge, meta, val) |
One another fix is using ASCII letters. For example |
Okay, as the output of this utility is predictable, you could hand off both transformations to the application logic which can be OS-specific. tree := treeprint.New()
// do stuff
log.Println(applyFilter(tree.String()))
func applyFilter(str string) string {
// uses github.com/mattn/go-runewidth
// checks runtime.GOOS
// replaces treeprint.EdgeTypeLink and other with mapped ASCII chars, etc
} I will add link to this issue in README. Thanks for the solution. |
I don't mind about fixing my apps. However, most of packages using treeprint will have to include this workaround. |
This is output from command lile https://github.com/lileio/lile
maybe this is expected?
The text was updated successfully, but these errors were encountered: