Skip to content
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

feat(help) Finished rendering and styled multiple help pages #58

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/chalk.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import config, confload, commands, norecurse, sinks, docker_base,

when isMainModule:
setupSignalHandlers() # util.nim
addDefaultSinks() # nimutils/sinks.nim
ioSetup() # sinks.nim
loadAllConfigs() # confload.nim
recursionCheck() # norecurse.nim
otherSetupTasks() # util.nim
Expand Down
90 changes: 61 additions & 29 deletions src/commands/cmd_help.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,31 @@ proc displayPluginKeys(s, v: string): string =
return "Any"
return asArr.join(", ")

template getKeyspecTable(state: ConfigState, filterValueStr: string): string =
template getKeyspecTable(state: ConfigState, filterValueStr: string,
colwidths: seq[int]): string =
let caption = "See <em>help key &lt;term&gt;</em> to search the table only"

state.getAllInstanceDocs("keyspec",
fieldsToUse = fieldsToUse,
filterField = "kind",
filterValue = filterValueStr,
headings = headingsToUse,
transformers = transformers,
docKind = docKind,
fieldsToUse = fieldsToUse,
filterField = "kind",
filterValue = filterValueStr,
headings = headingsToUse,
transformers = transformers,
docKind = docKind,
colwidths = colwidths,
caption = caption,
markdownFields = mdFields)

proc keyHelp(state: ConfigState, args: seq[string] = @[],
summary = false,
docKind = CDocConsole) :string =
var
transformers = TransformTableRef()
filter: bool = false
mdFields = @["doc"]
fieldsToUse = @["kind", "type"]
transformers = TransformTableRef()
filter: bool = false
mdFields = @["doc"]
fieldsToUse = @["kind", "type"]
headingsToUse = @["Key", "Collection Type", "Value Type", "Description"]
colwidths = @[20, 20, 20, 40]

if summary:
fieldsToUse.add("shortdoc")
Expand All @@ -76,7 +82,7 @@ proc keyHelp(state: ConfigState, args: seq[string] = @[],

case len(args)
of 0, 1:
result = state.getKeyspecTable("")
result = state.getKeyspecTable("", colwidths = colwidths)
of 2:
case args[1].toLowerAscii()
of "help", "--help":
Expand All @@ -97,24 +103,24 @@ any word that matches is returned.
"""
of "chalk", "chalk-time", "chalktime":
result = "# Chalk-Time Host Metadata Keys"
result &= state.getKeyspecTable("0")
result &= state.getKeyspecTable("0", colwidths = colwidths)
result = "# Chalk-Time Artifact Metadata Keys"
result &= state.getKeyspecTable("1")
result &= state.getKeyspecTable("1", colwidths = colwidths)
of "runtime", "run-time":
result = "# Run-Time Artifact Metadata Keys"
result &= state.getKeyspecTable("2")
result &= state.getKeyspecTable("2", colwidths = colwidths)
result = "# Run-Time Host Metadata Keys"
result &= state.getKeyspecTable("3")
result &= state.getKeyspecTable("3", colwidths = colwidths)
of "host":
result = "# Chalk-Time Host Metadata Keys"
result &= state.getKeyspecTable("0")
result &= state.getKeyspecTable("0", colwidths = colwidths)
result = "# Run-Time Host Metadata Keys"
result &= state.getKeyspecTable("3")
result &= state.getKeyspecTable("3", colwidths = colwidths)
of "artifact":
result = "# Chalk-Time Artifact Metadata Keys"
result &= state.getKeyspecTable("1")
result &= state.getKeyspecTable("1", colwidths = colwidths)
result = "# Run-Time Artifact Metadata Keys"
result &= state.getKeyspecTable("2")
result &= state.getKeyspecTable("2", colwidths = colwidths)
else:
filter = true
else:
Expand All @@ -129,6 +135,7 @@ any word that matches is returned.
"Collection Type",
"Value Type",
"Description"],
colwidths = colwidths,
transformers = transformers,
markdownFields=["shortdoc", "doc"])

Expand Down Expand Up @@ -159,9 +166,10 @@ proc searchEmbeddedDocs(terms: seq[string]): string =

result &= "<h2>Match on document: " & docName & "</h2>"
result &= doc.highlightMatches(matchedTerms)
result &= "<p></p>"

if result == "":
result = "<h2>No matches in other documents.</h2>"
result = "<h2>No matches in other documents.</h2><p></p>"

proc searchMetadataKeys(state: ConfigState, terms: seq[string]): string =
var transformers = TransformTableRef()
Expand Down Expand Up @@ -210,10 +218,10 @@ proc searchConfigVars(state: ConfigState, args: seq[string]): string =
result &= "<tr><th>Config value type</th><td>" & match[1]
result &= "</td></tr>"
result &= "<tr><th>Default value</th></td><td>" & match[2]
result &= "</td></tr></tbody></table>"
result &= "</td></tr></tbody></table><p></p>"

if result == "":
result = "<h2>No matches in configuration variables</h2>"
result = "<h2>No matches in configuration variables</h2><p></p>"

proc formatCommandName(dotted: string): string =
let parts = dotted.split(".")
Expand Down Expand Up @@ -260,18 +268,18 @@ proc searchFlags(state: ConfigState, args: seq[string]): string =
if match.autoFlags:
result &= "<tr><th>Choices are also valid flags:</th><td>Yes</td></tr>"

result &= "</tbody></table>"
result &= "</tbody></table><p></p>"

result &= match.doc

if result == "":
result = "<h2>No matches found in command-line flag documentation</h2>"
result = "<h2>No matches found in command-line flag documentation</h2><p></p>"

proc searchCommandDescriptions(state: ConfigState, args: seq[string]): string =
let matches = state.getCommandNonFlagData(allCommandSections, args)

if len(matches) == 0:
result &= "<h2>No matches in command descriptions</h2>"
result &= "<h2>No matches in command descriptions</h2><p></p>"

else:
for match in matches:
Expand All @@ -295,7 +303,7 @@ proc getHelpTopics(state: ConfigState): string =
for k, _ in helpFiles:
result &= "<li>" & resolveHelpFileName(k) & "</li>"

result &= "</ul>"
result &= "</ul><p></p>"

result = result.stylize()

Expand Down Expand Up @@ -402,20 +410,22 @@ See `chalk help reporting` for more information on templates.
reportTemplates.add(item)

if len(markTemplates) + len(reportTemplates) == 0:
result &= stylize("<h1>No matching templates found.</h1>")
result &= stylize("<h1>No matching templates found.</h1><p></p>")
return

for markTmplName in markTemplates:
let theTemplate = chalkConfig.markTemplates[markTmplName]

result &= stylize("<h2>Mark Template: " & markTmplName & "</h2>")
result &= state.formatOneTemplate(theTemplate)
result &= "<p></p>"

for repTmplName in reportTemplates:
let theTemplate = chalkConfig.reportTemplates[repTmplName]

result &= stylize("<h2>Report Template: " & repTmplName & "</h2>")
result &= state.formatOneTemplate(theTemplate)
result &= "<p></p>"

proc fullTextSearch(state: ConfigState, args: seq[string]): string =
result &= "<h1>Searching documentation for term"
Expand Down Expand Up @@ -445,7 +455,7 @@ proc getOutputHelp(state: ConfigState, kind = CDocConsole): string =
(_, rtlong) = state.getSectionDocs("report_template", kind)
(_, oclong) = state.getSectionDocs("outconf", kind)
(_, sconflong) = state.getSectionDocs("sink_config", kind)
(_, custlong) = state.getSectionDocs("custom_report", kind)
(_, custlong) = state.getSectionDocs("custom_report", kind)

result = mtlong
result &= rtlong
Expand All @@ -466,6 +476,26 @@ proc hasHelpFlag(args: seq[string]): bool =
if s in ["help", "h"]:
return true

proc makeColorTable(): string =
perClassStyles["light"] = newStyle(fgColor = "white")
perClassStyles["dark"] = newStyle(fgColor = "black")
styleMap.del("tr.even")
styleMap.del("tr.odd")
styleMap["tr"] = newStyle(bgColor = "default")



result = "<table class=light><tbody>"
for color, v in colorTable:
if v < 0x400000:
result &= """<tr class=light><td class=light><center><bg-""" &
color & ">" & color & "</bg-" & color & "></center></td></tr>"
else:
result &= """<tr class=dark><td class=dark><center><bg-""" & color &
">" & color & "</bg-" & color & "></center></td></tr>"
result &= "</tbody></table>"
result = result.stylize()

proc runChalkHelp*(cmdName = "help") {.noreturn.} =
var
args = getArgs()
Expand Down Expand Up @@ -493,6 +523,8 @@ proc runChalkHelp*(cmdName = "help") {.noreturn.} =
else:
for arg in args:
case arg
of "nikon":
toOut &= makeColorTable()
of "output", "reports", "reporting":
toOut &= con4mRuntime.getOutputHelp()
of "plugins":
Expand Down
5 changes: 2 additions & 3 deletions src/configs/getopts.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,9 @@ plenty of in-command help. Currently, the interface is being redone,
but for the moment:
<p>


- <jazzberry>chalk help commands</jazzberry> shows the overview help for the command line.
- <jazzberry>chalk help "cmdname" </jazzberry> shows the help for an individual command, as does <fandango>chalk "cmdname" --help</fandango>
- <jazzberry>chalk help config</jazzberry> shows the overview help for configuration options you can set via the <fandango>chalk load</fandango> command.
- <jazzberry>chalk help "cmdname" </jazzberry> shows the help for an individual command, as does <em>chalk "cmdname" --help</em>
- <jazzberry>chalk help config</jazzberry> shows the overview help for configuration options you can set via the <em>chalk load</em> command.
- <jazzberry>chalk help metadata</jazzberry> shows information about the many types of metadata that you can choose to collect.
- <jazzberry>chalk help builtins</jazzberry> shows information about built-in functions that you can use in a custom configuration to do your own data collection or customization.
- <jazzberry>chalk help topics</jazzberry> will show a list of long-form help documents that
Expand Down
61 changes: 59 additions & 2 deletions src/sinks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import uri, config

proc chalkLogWrap(msg: string, extra: StringTable) : (string, bool) =
return (msg.perLineWrap(startingMaxLineWidth = -7,
firstHangingIndent = 7), true)
return (msg, true)

const
availableFilters = { "log_level" : MsgFilter(logLevelFilter),
Expand Down Expand Up @@ -338,3 +337,61 @@ proc setupDefaultLogConfigs*() =
logger=okCbOpt).get()

discard subscribe("chalk_usage_stats", useConf)

proc ioSetup*(bgColor = "darkslategray") =
let
ourPink = "hotpink" # True color is jazzberry
ourPurple = "mediumpurple" # True color is fandango
chalkDefault = newStyle(overflow = OWrap, rpad = 0, tmargin = 0, lpad = 0,
bgColor = bgColor, fgColor = "gainsboro")
chalkH1 = newStyle(fgColor = ourPink, bold = BoldOn,
italic = ItalicOn, casing = CasingUpper,
align = AlignC)
chalkH2 = newStyle(fgColor = "atomiclime", bgColor = "darkslategray",
bold = BoldOn, align = AlignL, italic = ItalicOn,
tmargin = 2)
chalkH3 = newStyle(bgColor = ourPink, fgColor = "white",
italic = ItalicOn, tmargin = 1,
casing = CasingUpper)
chalkH4 = newStyle(fgColor = ourPink, italic = ItalicOn,
underline = UnderlineSingle, casing = CasingTitle)
chalkH5 = newStyle(fgColor = "atomiclime", bgColor = "black",
italic = ItalicOn, casing = CasingTitle)
chalkH6 = newStyle(fgColor = "white", bgColor = bgColor,
underline = UnderlineSingle, casing = CasingTitle)
chalkEm = newStyle(fgColor = ourPink, italic = ItalicOn)
chalkTH = newStyle(fgColor = "black", bold = BoldOn, overflow = OWrap,
casing = CasingUpper, tmargin = 0,
bgColor = "atomiclime", align = AlignC)
chalkTR = newStyle(fgColor = "white", bold = BoldOn, lpad = 0,
rpad = 0, overflow = OWrap, tmargin = 0,
bgColor = ourPink)
chalkEven = newStyle(fgColor = "white", bgColor = ourPink,
overflow = OWrap)
chalkOdd = newStyle(fgColor = "white", bgColor = ourPurple,
overflow = OWrap)
chalkCaption = newStyle(bgColor = "black", fgColor = "atomiclime",
align = AlignC, italic = ItalicOn, bmargin = 2)
chalkTable = newStyle(borders = [BorderAll], overflow = OWrap,
fgColor = "white",
bgcolor = bgColor)

setDefaultStyle(chalkDefault)
setStyle("h1", chalkH1)
setStyle("h2", chalkH2)
setStyle("h3", chalkH3)
setStyle("h4", chalkH4)
setStyle("h5", chalkH5)
setStyle("h6", chalkH6)
setStyle("em", chalkEm)
setStyle("th", chalkTH)
setStyle("tr", chalkTR)
setStyle("tr.even", chalkEven)
setStyle("tr.odd", chalkOdd)
setStyle("caption", chalkCaption)
setStyle("table", chalkTable)
setStyle("thead", chalkTable)
setStyle("tbody", chalkTable)
setStyle("tfoot", chalkTable)
once:
addDefaultSinks()