From 8ba506cf975d4db069d7554c1260fcb3603aadf6 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 22 Apr 2012 20:37:27 -0400 Subject: cleaner text output w/ tabwriter --- formats.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'formats.go') diff --git a/formats.go b/formats.go index d66ea4a..11994fe 100644 --- a/formats.go +++ b/formats.go @@ -11,6 +11,7 @@ import ( "log" "strings" "strconv" + "text/tabwriter" ) // This compound container struct is useful for serializing to XML and JSON @@ -37,11 +38,12 @@ func DumpBomAsText(bm *BomMeta, b *Bom, out io.Writer) { fmt.Fprintf(out, "Description:\t%s\n", bm.Description) } fmt.Println() + tabWriter := tabwriter.NewWriter(out, 2, 4, 1, ' ', 0) // "by line item" // TODO: use text/tabwriter here to get proper column alignment - fmt.Fprintf(out, "tag\tqty\tmanufacturer\tmpn\t\tfunction\t\tcomment\n") + fmt.Fprintf(tabWriter, "tag\tqty\tmanufacturer\tmpn\t\tfunction\t\tcomment\n") for _, li := range b.LineItems { - fmt.Fprintf(out, "%s\t%d\t%s\t%s\t\t%s\t\t%s\n", + fmt.Fprintf(tabWriter, "%s\t%d\t%s\t%s\t\t%s\t\t%s\n", li.Tag, len(li.Elements), li.Manufacturer, @@ -49,20 +51,7 @@ func DumpBomAsText(bm *BomMeta, b *Bom, out io.Writer) { li.Function, li.Comment) } - /* // "by circuit element" - fmt.Fprintf(out, "tag\tsymbol\tmanufacturer\tmpn\t\tdescription\t\tcomment\n") - for _, li := range b.LineItems { - for _, elm := range li.Elements { - fmt.Fprintf(out, "%s\t%s\t%s\t%s\t\t%s\t\t%s\n", - li.Tag, - elm, - li.Manufacturer, - li.Mpn, - li.Description, - li.Comment) - } - } - */ + tabWriter.Flush() } // --------------------- csv ----------------------- -- cgit v1.2.3