-
Notifications
You must be signed in to change notification settings - Fork 327
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
FIXES #176: templates: default table template was wider than terminal #295
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,14 +293,30 @@ const defaultDebugTemplate = "{{ . | toJson}}\n" | |
const defaultListTemplate = "{{ range .issues }}{{ .key | append \":\" | printf \"%-12s\"}} {{ .fields.summary }}\n{{ end }}" | ||
|
||
const defaultTableTemplate = `{{/* table template */ -}} | ||
{{$w := sub termWidth 107 -}} | ||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ | ||
| {{ "Issue" | printf "%-14s" }} | {{ "Summary" | printf (printf "%%-%ds" (sub $w 2)) }} | {{ "Type" | printf "%-12s"}} | {{ "Priority" | printf "%-12s" }} | {{ "Status" | printf "%-12s" }} | {{ "Age" | printf "%-10s" }} | {{ "Reporter" | printf "%-12s" }} | {{ "Assignee" | printf "%-12s" }} | | ||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ | ||
{{$issuew := int 10 -}} | ||
{{$typew := int $issuew -}} | ||
{{$priorityw := int 14 -}} | ||
{{$statusw := $priorityw -}} | ||
{{$agew := int 10 -}} | ||
{{$reporterw := int 25 -}} | ||
{{$assigneew := int 12 -}} | ||
{{$dissuew := int (add 2 $issuew) -}} | ||
{{$dtypew := int (add 2 $typew) -}} | ||
{{$dpriorityw := int (add 2 $priorityw) -}} | ||
{{$dstatusw := int (add 2 $statusw) -}} | ||
{{$dagew := int (add 2 $agew) -}} | ||
{{$dreporterw := int (add 2 $reporterw) -}} | ||
{{$dassigneew := int (add 2 $assigneew) -}} | ||
{{$usedcols := int (add 25 (add $issuew (add $typew (add $priorityw (add $statusw (add $agew (add $reporterw $assigneew))))))) -}} | ||
{{$summaryw := int (max 40 (sub termWidth $usedcols)) -}} | ||
{{$dsummaryw := int (add 2 $summaryw) -}} | ||
+{{ "-" | rep $dissuew }}+{{ "-" | rep $dsummaryw }}+{{ "-" | rep $dtypew }}+{{ "-" | rep $dpriorityw }}+{{ "-" | rep $dstatusw }}+{{ "-" | rep $dagew }}+{{ "-" | rep $dreporterw }}+{{ "-" | rep $dassigneew }}+ | ||
| {{ "Issue" | printf (printf "%%-%ds" $issuew) }} | {{ "Summary" | printf (printf "%%-%ds" $summaryw) }} | {{ "Type" | printf (printf "%%-%ds" $typew)}} | {{ "Priority" | printf (printf "%%-%ds" $priorityw) }} | {{ "Status" | printf (printf "%%-%ds" $statusw) }} | {{ "Age" | printf (printf "%%-%ds" $agew) }} | {{ "Reporter" | printf (printf "%%-%ds" $reporterw) }} | {{ "Assignee" | printf (printf "%%-%ds" $assigneew) }} | | ||
+{{ "-" | rep $dissuew }}+{{ "-" | rep $dsummaryw }}+{{ "-" | rep $dtypew }}+{{ "-" | rep $dpriorityw }}+{{ "-" | rep $dstatusw }}+{{ "-" | rep $dagew }}+{{ "-" | rep $dreporterw }}+{{ "-" | rep $dassigneew }}+ | ||
{{ range .issues -}} | ||
| {{ .key | printf "%-14s"}} | {{ .fields.summary | abbrev (sub $w 2) | printf (printf "%%-%ds" (sub $w 2)) }} | {{.fields.issuetype.name | printf "%-12s" }} | {{if .fields.priority}}{{.fields.priority.name | printf "%-12s" }}{{else}}<unassigned>{{end}} | {{.fields.status.name | printf "%-12s" }} | {{.fields.created | age | printf "%-10s" }} | {{if .fields.reporter}}{{ .fields.reporter.name | printf "%-12s"}}{{else}}<unassigned>{{end}} | {{if .fields.assignee }}{{.fields.assignee.name | printf "%-12s" }}{{else}}<unassigned>{{end}} | | ||
| {{ .key | printf (printf "%%-%ds" $issuew)}} | {{ .fields.summary | abbrev (int (sub $summaryw 2)) | printf (printf "%%-%ds" $summaryw) }} | {{.fields.issuetype.name | printf (printf "%%-%ds" $typew) }} | {{if .fields.priority}}{{.fields.priority.name | printf (printf "%%-%ds" $priorityw) }}{{else}}<unassigned>{{end}} | {{.fields.status.name | printf (printf "%%-%ds" $statusw) }} | {{.fields.created | age | printf (printf "%%-%ds" $agew) }} | {{if .fields.reporter}}{{ .fields.reporter.name | printf (printf "%%-%ds" $reporterw)}}{{else}}<unassigned>{{end}} | {{if .fields.assignee }}{{.fields.assignee.name | printf (printf "%%-%ds" $assigneew) }}{{else}}<unassigned>{{end}} | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there must be a better way to get responsive padding than this pattern: I guess we could add a new templating function, something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then - if I understand the template syntax, which I'm still a bit fuzzy on - we would replace the example I quoted with something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is pretty rough, your solution is probably the best with what we have. I wonder if we should just add some template functions that correspond to https://github.com/olekukonko/tablewriter to make the table writing easier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @dobbymoodge, I played a bit more with
and I get this now:
It auto sizes the columns based on the text, otherwise it will wrap cells to fit within the console width. So I think I will continue with this approach as the templates seem to be much more readable and will create a PR for it and ping you. |
||
{{ end -}} | ||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ | ||
+{{ "-" | rep $dissuew }}+{{ "-" | rep $dsummaryw }}+{{ "-" | rep $dtypew }}+{{ "-" | rep $dpriorityw }}+{{ "-" | rep $dstatusw }}+{{ "-" | rep $dagew }}+{{ "-" | rep $dreporterw }}+{{ "-" | rep $dassigneew }}+ | ||
` | ||
const defaultAttachListTemplate = `{{/* table template */ -}} | ||
+{{ "-" | rep 12 }}+{{ "-" | rep 30 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
seems to returnint64
, but thesub
template function only wantsint
type args, so there's just a ton of casting going on.Something like
{{$newval := sub $bar (add 2 $foo) -}}
would give an error likeERROR Invalid Usage: template: gojira:1:30: executing "gojira" at <$foo>: wrong type for value; expected int; got int64