Skip to content

Commit

Permalink
Fix metadata rendering issue
Browse files Browse the repository at this point in the history
Prior to this commit, the printed metadata was wrapped/formatted incorrectly.
This commit fixes it by replacing newline characters with the appropriate amount
of \t and spaces to fit in the table. Might be a bit hacky/messy.
  • Loading branch information
narasaka committed Nov 16, 2023
1 parent a483525 commit eb3db37
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions go/cli/mcap/cmd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ var (

func printMetadata(w io.Writer, r io.ReadSeeker, info *mcap.Info) error {
rows := make([][]string, 0, len(info.MetadataIndexes))
rows = append(rows, []string{
headers := []string{
"name",
"offset",
"length",
"metadata",
})
}
rows = append(rows, headers)
// jsonRowSeparator is used to replace the newline characters
// so that the metadata displayed is formatted and wrapped correctly
jsonRowSeparator := "\n" + strings.Repeat("\t", len(headers)-1) + strings.Repeat(" ", len(headers)-1)
for _, idx := range info.MetadataIndexes {
offset := idx.Offset + 1 + 8
if offset > math.MaxInt64 {
Expand Down Expand Up @@ -62,7 +66,7 @@ func printMetadata(w io.Writer, r io.ReadSeeker, info *mcap.Info) error {
idx.Name,
fmt.Sprintf("%d", idx.Offset),
fmt.Sprintf("%d", idx.Length),
prettyJSON,
strings.ReplaceAll(prettyJSON, "\n", jsonRowSeparator),
})
}
utils.FormatTable(w, rows)
Expand Down

0 comments on commit eb3db37

Please sign in to comment.