diff options
| author | Shulhan <ms@kilabit.info> | 2023-04-04 23:13:59 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-04-04 23:17:24 +0700 |
| commit | 076fe4f98722c5dd14aee1ec2342fdaa2691cf59 (patch) | |
| tree | 2206be0bd5cf532fce164bc0207d98a44fb9e7a0 /lib/bytes/bytes.go | |
| parent | 28f9a8505c70c7650229d2380996ab8f668bc5b6 (diff) | |
| download | pakakeh.go-076fe4f98722c5dd14aee1ec2342fdaa2691cf59.tar.xz | |
lib/bytes: changes the DumpPrettyTable output format
The change is to accommodate large bytes data, more than 0xFFFF.
The hex address in the first column is increased to 8 digits, the
characters compacted without space in between.
Diffstat (limited to 'lib/bytes/bytes.go')
| -rw-r--r-- | lib/bytes/bytes.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go index c895351f..9329f24a 100644 --- a/lib/bytes/bytes.go +++ b/lib/bytes/bytes.go @@ -560,8 +560,8 @@ func DumpPrettyTable(w io.Writer, title string, data []byte) { const ncol = 8 fmt.Fprintf(w, "%s\n", title) - fmt.Fprint(w, " | 0 1 2 3 4 5 6 7| 0 1 2 3 4 5 6 7| 0 1 2 3 4 5 6 7|\n") - fmt.Fprint(w, " | 8 9 A B C D E F| 8 9 A B C D E F| 8 9 A B C D E F|\n") + fmt.Fprint(w, " | 0 1 2 3 4 5 6 7 | 01234567 | 0 1 2 3 4 5 6 7 |\n") + fmt.Fprint(w, " | 8 9 A B C D E F | 89ABCDEF | 8 9 A B C D E F |\n") var ( chunks = SplitEach(data, ncol) @@ -571,7 +571,7 @@ func DumpPrettyTable(w io.Writer, title string, data []byte) { c byte ) for x, chunk = range chunks { - fmt.Fprintf(w, `%#02x|`, x*ncol) + fmt.Fprintf(w, `%#08x|`, x*ncol) // Print as hex. for y, c = range chunk { @@ -582,27 +582,27 @@ func DumpPrettyTable(w io.Writer, title string, data []byte) { } // Print as char. - fmt.Fprint(w, `|`) + fmt.Fprint(w, ` | `) for y, c = range chunk { if c >= 33 && c <= 126 { - fmt.Fprintf(w, ` %c`, c) + fmt.Fprintf(w, `%c`, c) } else { - fmt.Fprint(w, ` .`) + fmt.Fprint(w, `.`) } } for y++; y < ncol; y++ { - fmt.Fprint(w, ` `) + fmt.Fprint(w, ` `) } // Print as integer. - fmt.Fprint(w, `|`) + fmt.Fprint(w, ` |`) for y, c = range chunk { fmt.Fprintf(w, ` %3d`, c) } for y++; y < ncol; y++ { fmt.Fprint(w, ` `) } - fmt.Fprintf(w, "|%02d\n", x*ncol) + fmt.Fprintf(w, " |%d\n", x*ncol) } } |
