Repository navigation
feat(make): prettier, more intuitive help output for make/make help with unicode banner #191
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
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 |
|---|---|---|
|
|
@@ -40,6 +40,12 @@ function display_name(name) { | |
| return name | ||
| } | ||
|
|
||
| function rule(char, width, out, i) { | ||
| out = "" | ||
| for (i = 0; i < width; i++) out = out char | ||
| return out | ||
| } | ||
|
|
||
| # Sets parsed_name/parsed_summary/parsed_prereqs; returns 1 for a documented target line. | ||
| function parse_target(line, rest, marker) { | ||
| if (!match(line, /^[A-Za-z0-9][A-Za-z0-9_.%\/-]*/)) return 0 | ||
|
|
@@ -79,10 +85,28 @@ function print_section(title, i, shown) { | |
| shown = 0 | ||
| for (i = 1; i <= count; i++) { | ||
| if (sections[i] != title) continue | ||
| if (!shown) printf "\n%s\n", color_wrap("1;33", title) | ||
| if (!shown) { | ||
| if (color) { | ||
| printf "\n" | ||
| printf "%s %s\n", color_wrap("1;33", "▸"), color_wrap("1;33", title) | ||
| printf "%s\n", color_wrap("0;90", " " rule("─", 56)) | ||
| } else { | ||
| printf "\n%s\n", color_wrap("1;33", title) | ||
| } | ||
| } | ||
| shown = 1 | ||
| printf " %s%s %s\n", color_wrap("1;36", display_name(names[i])), \ | ||
| spaces(name_width - length(display_name(names[i]))), summaries[i] | ||
| if (color) { | ||
| printf " %s %s%s %s\n", | ||
| color_wrap("1;36", display_name(names[i])), | ||
| spaces(name_width - length(display_name(names[i]))), | ||
| color_wrap("0;90", "•"), | ||
| summaries[i] | ||
| } else { | ||
| printf " %s%s %s\n", | ||
| color_wrap("1;36", display_name(names[i])), | ||
| spaces(name_width - length(display_name(names[i]))), | ||
| summaries[i] | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -92,29 +116,58 @@ function compute_name_width( i, len) { | |
| len = length(display_name(names[i])) | ||
| if (len > name_width) name_width = len | ||
| } | ||
| if (name_width > 30) name_width = 30 | ||
| if (name_width < 12) name_width = 12 | ||
| if (name_width > 28) name_width = 28 | ||
| } | ||
|
|
||
| function print_header() { | ||
| printf "\n" | ||
| printf "%s\n", color_wrap("1;32", " ╭───────────────────────────────────────────────────────────────────────────────╮") | ||
| printf "%s\n", color_wrap("1;32", " │ │") | ||
| printf "%s\n", color_wrap("1;32", " │ 🌳 groot · make targets │") | ||
| printf "%s\n", color_wrap("1;32", " │ │") | ||
| printf "%s\n", color_wrap("1;32", " ╰───────────────────────────────────────────────────────────────────────────────╯") | ||
| printf "\n" | ||
| printf " %s %s\n", color_wrap("1;37", "Usage:"), color_wrap("0;37", "make <target> [VAR=value ...]") | ||
| printf " %s %s\n", color_wrap("1;37", "Detail:"), color_wrap("0;37", "make help-<target> e.g. make help-all") | ||
| printf " %s %s\n", color_wrap("1;37", "Color:"), color_wrap("0;37", "auto on TTY · set NO_COLOR=1 to disable") | ||
| } | ||
|
|
||
| function print_footer() { | ||
| printf "\n" | ||
| printf "%s\n", color_wrap("0;90", " ───────────────────────────────────────────────────────────────────────────────") | ||
| printf " %s\n", color_wrap("0;37", "Tip: run make help-<name> for usage lines & prerequisites") | ||
| printf " %s\n", color_wrap("0;37", " e.g. make help-all · make help-link · make help-clean") | ||
| printf "\n" | ||
| } | ||
|
|
||
| function print_list( ordered, ordered_count, i, is_ordered) { | ||
| compute_name_width() | ||
| printf "%s\n", "Usage: make <target> [VAR=value ...]" | ||
| if (color) print_header() | ||
|
Contributor
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. Keep the plain list guidance when
Also applies to: 154-154
|
||
| ordered_count = split(order, ordered, "|") | ||
| for (i = 1; i <= ordered_count; i++) { | ||
| if (ordered[i] in section_seen) print_section(ordered[i]) | ||
| is_ordered[ordered[i]] = 1 | ||
| } | ||
| for (i = 1; i <= section_count; i++) | ||
| if (!(section_titles[i] in is_ordered)) print_section(section_titles[i]) | ||
| printf "\nmake help-<target> prints one target's usage lines.\n" | ||
| if (color) print_footer() | ||
| } | ||
|
|
||
| function print_target( i) { | ||
| for (i = 1; i <= count; i++) { | ||
| if (names[i] != target) continue | ||
| printf "%s\n", color_wrap("1;36", "make " display_name(names[i])) | ||
| printf "\n" | ||
| if (color) { | ||
| printf "%s %s\n", color_wrap("1;36", "▸"), color_wrap("1;36", "make " display_name(names[i])) | ||
| printf "%s\n", color_wrap("0;90", " " rule("─", 48)) | ||
| } else { | ||
| printf " %s\n", display_name(names[i]) | ||
|
Comment on lines
+160
to
+165
Contributor
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. Preserve the existing plain target output when color is disabled. These unconditional changes add blank lines and alter the heading in the no-color path. The heading also drops Also applies to: 168-170
|
||
| } | ||
| printf " %s\n", summaries[i] | ||
| if (prereqs[i] != "") printf "Runs first: %s\n", prereqs[i] | ||
| if (prereqs[i] != "") printf "\n %s %s\n", color_wrap("1;33", "Runs first:"), prereqs[i] | ||
| if (has_extended[i]) printf "\n%s\n", extended[i] | ||
| printf "\n" | ||
| return 1 | ||
| } | ||
| printf "no documented target '%s' — make help lists them\n", target > "/dev/stderr" | ||
|
|
||
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.
Align all banner rows to one width.
The top and bottom borders are wider than the interior rows. In color mode, the right vertical bars stop before the corners, so the header is visibly malformed. Build the border and interior rows from one shared width. (raw.githubusercontent.com)