Skip to content

Commit

Permalink
Merge pull request #77 from obnoxiousnerd/table_footer
Browse files Browse the repository at this point in the history
Add `footer` parameter to `out.Table`
  • Loading branch information
dominikbraun authored May 31, 2021
2 parents 7561157 + f9d1967 commit bf934a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getProjectCommand(t *core.Timetrace) *cobra.Command {
return
}

out.Table([]string{"Key"}, [][]string{{project.Key}})
out.Table([]string{"Key"}, [][]string{{project.Key}}, nil)
},
}

Expand Down Expand Up @@ -102,5 +102,5 @@ func showRecord(record *core.Record, formatter *core.Formatter) {
},
}

out.Table([]string{"Start", "End", "Project", "Billable"}, rows)
out.Table([]string{"Start", "End", "Project", "Billable"}, rows, nil)
}
4 changes: 2 additions & 2 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func listProjectsCommand(t *core.Timetrace) *cobra.Command {
rows[i][2] = allModules
}

out.Table([]string{"#", "Key", "Modules"}, rows)
out.Table([]string{"#", "Key", "Modules"}, rows, nil)
},
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func listRecordsCommand(t *core.Timetrace) *cobra.Command {
rows[i][5] = billable
}

out.Table([]string{"#", "Key", "Project", "Start", "End", "Billable"}, rows)
out.Table([]string{"#", "Key", "Project", "Start", "End", "Billable"}, rows, nil)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cli/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func statusCommand(t *core.Timetrace) *cobra.Command {
report.FormatTodayTime(),
},
}
out.Table([]string{"Current project", "Worked since start", "Worked today"}, rows)
out.Table([]string{"Current project", "Worked since start", "Worked today"}, rows, nil)
},
}

Expand Down
7 changes: 6 additions & 1 deletion out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ func Err(format string, a ...interface{}) {
}

// Table renders a table with the given rows to the standard output.
func Table(header []string, rows [][]string) {
func Table(header []string, rows [][]string, footer []string) {
paddedHeaders := headersWithPadding(header)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(paddedHeaders)
setHeaderColor(table, paddedHeaders)
// If footer array is not empty, then render footer in table.
if len(footer) > 0 {
paddedFooters := headersWithPadding(footer)
table.SetFooter(paddedFooters)
}
table.AppendBulk(rows)
table.Render()
}
Expand Down

0 comments on commit bf934a8

Please sign in to comment.