summaryrefslogtreecommitdiffstats
path: root/src/help_text_formatter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/help_text_formatter.cc')
-rw-r--r--src/help_text_formatter.cc171
1 files changed, 163 insertions, 8 deletions
diff --git a/src/help_text_formatter.cc b/src/help_text_formatter.cc
index e0b92a0..5d3b8a2 100644
--- a/src/help_text_formatter.cc
+++ b/src/help_text_formatter.cc
@@ -42,18 +42,17 @@
using namespace lnav::roles::literals;
-std::multimap<std::string, help_text*> help_text::TAGGED;
-
static std::vector<help_text*>
get_related(const help_text& ht)
{
std::vector<help_text*> retval;
for (const auto& tag : ht.ht_tags) {
- auto tagged = help_text::TAGGED.equal_range(tag);
+ auto tagged = help_text::tag_map().equal_range(tag);
for (auto tag_iter = tagged.first; tag_iter != tagged.second;
- ++tag_iter) {
+ ++tag_iter)
+ {
if (tag_iter->second == &ht) {
continue;
}
@@ -349,6 +348,88 @@ format_help_text_for_term(const help_text& ht,
}
break;
}
+ case help_context_t::HC_PRQL_TRANSFORM: {
+ auto line_start = out.al_string.length();
+
+ out.append(";").append(lnav::roles::symbol(ht.ht_name));
+ for (const auto& param : ht.ht_parameters) {
+ out.append(" ");
+ if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) {
+ out.append(lnav::roles::symbol(param.ht_name));
+ out.append(":");
+ if (param.ht_default_value) {
+ out.append(param.ht_default_value);
+ } else {
+ out.append("null");
+ }
+ } else {
+ if (param.ht_group_start) {
+ out.append(param.ht_group_start);
+ }
+ out.append(lnav::roles::variable(param.ht_name));
+ }
+ if (param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) {
+ out.append("1"_variable);
+ out.append(" [");
+ out.append("..."_variable);
+ out.append(" ");
+ out.append(lnav::roles::variable(param.ht_name));
+ out.append("N"_variable);
+ out.append("]");
+ }
+ if (param.ht_group_end) {
+ out.append(param.ht_group_end);
+ }
+ }
+ out.with_attr(string_attr{
+ line_range{(int) line_start, (int) out.get_string().length()},
+ VC_ROLE.value(role_t::VCR_H3),
+ });
+ if (htc != help_text_content::synopsis) {
+ alb.append("\n")
+ .append(lnav::roles::table_border(
+ repeat("\u2550", tws.tws_width)))
+ .append("\n")
+ .indent(body_indent)
+ .append(attr_line_t::from_ansi_str(ht.ht_summary),
+ &tws.with_indent(body_indent + 2))
+ .append("\n");
+ }
+ break;
+ }
+ case help_context_t::HC_PRQL_FUNCTION: {
+ auto line_start = out.al_string.length();
+
+ out.append(lnav::roles::symbol(ht.ht_name));
+ for (const auto& param : ht.ht_parameters) {
+ out.append(" ");
+ out.append(lnav::roles::variable(param.ht_name));
+ if (param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) {
+ out.append("1"_variable);
+ out.append(" [");
+ out.append("..."_variable);
+ out.append(" ");
+ out.append(lnav::roles::variable(param.ht_name));
+ out.append("N"_variable);
+ out.append("]");
+ }
+ }
+ out.with_attr(string_attr{
+ line_range{(int) line_start, (int) out.get_string().length()},
+ VC_ROLE.value(role_t::VCR_H3),
+ });
+ if (htc != help_text_content::synopsis) {
+ alb.append("\n")
+ .append(lnav::roles::table_border(
+ repeat("\u2550", tws.tws_width)))
+ .append("\n")
+ .indent(body_indent)
+ .append(attr_line_t::from_ansi_str(ht.ht_summary),
+ &tws.with_indent(body_indent + 2))
+ .append("\n");
+ }
+ break;
+ }
default:
break;
}
@@ -377,6 +458,32 @@ format_help_text_for_term(const help_text& ht,
.append(attr_line_t::from_ansi_str(param.ht_summary),
&(tws.with_indent(2 + max_param_name_width + 3)))
.append("\n");
+ if (!param.ht_enum_values.empty()) {
+ alb.indent(body_indent + max_param_name_width)
+ .append(" ")
+ .append("Values"_h5)
+ .append(": ");
+ auto initial = true;
+ for (const auto* ename : param.ht_enum_values) {
+ if (!initial) {
+ alb.append("|");
+ }
+ alb.append(lnav::roles::symbol(ename));
+ initial = false;
+ }
+ alb.append("\n");
+ }
+ if (!param.ht_parameters.empty()) {
+ for (const auto& sub_param : param.ht_parameters) {
+ alb.indent(body_indent + max_param_name_width + 3)
+ .append(lnav::roles::variable(sub_param.ht_name))
+ .append(" - ")
+ .append(
+ attr_line_t::from_ansi_str(sub_param.ht_summary),
+ &(tws.with_indent(2 + max_param_name_width + 5)))
+ .append("\n");
+ }
+ }
}
}
if (htc == help_text_content::full && !ht.ht_results.empty()) {
@@ -448,7 +555,8 @@ void
format_example_text_for_term(const help_text& ht,
const help_example_to_attr_line_fun_t eval,
size_t width,
- attr_line_t& out)
+ attr_line_t& out,
+ help_example::language lang)
{
if (ht.ht_example.empty()) {
return;
@@ -460,6 +568,10 @@ format_example_text_for_term(const help_text& ht,
out.append(ht.ht_example.size() == 1 ? "Example"_h4 : "Examples"_h4)
.append("\n");
for (const auto& ex : ht.ht_example) {
+ if (ex.he_language != lang) {
+ continue;
+ }
+
attr_line_t ex_line(ex.he_cmd);
const char* prompt = "";
text_wrap_settings tws;
@@ -479,6 +591,8 @@ format_example_text_for_term(const help_text& ht,
case help_context_t::HC_SQL_KEYWORD:
case help_context_t::HC_SQL_FUNCTION:
case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION:
+ case help_context_t::HC_PRQL_TRANSFORM:
+ case help_context_t::HC_PRQL_FUNCTION:
readline_sqlite_highlighter(ex_line, 0);
prompt = ";";
break;
@@ -488,6 +602,8 @@ format_example_text_for_term(const help_text& ht,
ex_line.pad_to(50).with_attr_for_all(
VC_ROLE.value(role_t::VCR_QUOTED_CODE));
+ auto ex_result
+ = eval(ht, ex).with_attr_for_all(SA_PREFORMATTED.value());
alb.append("#")
.append(fmt::to_string(count))
.append(" ")
@@ -498,7 +614,7 @@ format_example_text_for_term(const help_text& ht,
.append(ex_line, &tws.with_indent(3).with_padding_indent(3))
.append("\n")
.indent(3)
- .append(eval(ht, ex), &tws.with_indent(3))
+ .append(ex_result, &tws.with_indent(0))
.append("\n");
count += 1;
@@ -516,7 +632,14 @@ link_name(const help_text& ht)
if (is_sql_infix) {
scrubbed_name = "infix";
} else {
- scrubbed_name = ht.ht_name;
+ if (ht.ht_context == help_context_t::HC_PRQL_TRANSFORM) {
+ scrubbed_name += "prql_";
+ }
+ scrubbed_name += ht.ht_name;
+ if (scrubbed_name[0] == '.') {
+ scrubbed_name.erase(scrubbed_name.begin());
+ scrubbed_name.insert(0, "dot_");
+ }
}
if (ht.ht_function_type == help_function_type_t::HFT_AGGREGATE) {
scrubbed_name += "_agg";
@@ -549,7 +672,7 @@ format_help_text_for_rst(const help_text& ht,
return;
}
- bool is_sql_func = false, is_sql = false;
+ bool is_sql_func = false, is_sql = false, is_prql = false;
switch (ht.ht_context) {
case help_context_t::HC_COMMAND:
prefix = ":";
@@ -567,6 +690,12 @@ format_help_text_for_rst(const help_text& ht,
is_sql = true;
prefix = "";
break;
+ case help_context_t::HC_PRQL_TRANSFORM:
+ case help_context_t::HC_PRQL_FUNCTION:
+ is_sql = true;
+ is_prql = true;
+ prefix = "";
+ break;
default:
prefix = "";
break;
@@ -599,6 +728,11 @@ format_help_text_for_rst(const help_text& ht,
out_count += fmt::fprintf(rst_file, "\\[");
}
out_count += fmt::fprintf(rst_file, "%s", param.ht_name);
+ if (is_prql && param.ht_default_value) {
+ out_count += fmt::fprintf(rst_file, ":");
+ out_count
+ += fmt::fprintf(rst_file, "%s", param.ht_default_value);
+ }
if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) {
out_count += fmt::fprintf(rst_file, "\\]");
}
@@ -616,6 +750,13 @@ format_help_text_for_rst(const help_text& ht,
fmt::fprintf(rst_file, " %s\n", ht.ht_summary);
fmt::fprintf(rst_file, "\n");
+
+ if (!ht.ht_prql_path.empty()) {
+ fmt::print(rst_file,
+ FMT_STRING(" **PRQL Name**: {}\n\n"),
+ fmt::join(ht.ht_prql_path, "."));
+ }
+
if (ht.ht_description != nullptr) {
fmt::fprintf(rst_file, " %s\n", ht.ht_description);
}
@@ -637,6 +778,20 @@ format_help_text_for_rst(const help_text& ht,
param.ht_name,
param.ht_nargs == help_nargs_t::HN_REQUIRED ? "\\*" : "",
param.ht_summary);
+
+ if (!param.ht_parameters.empty()) {
+ fprintf(rst_file, "\n");
+ for (const auto& sub_param : param.ht_parameters) {
+ fmt::fprintf(
+ rst_file,
+ " * **%s%s** --- %s\n",
+ sub_param.ht_name,
+ sub_param.ht_nargs == help_nargs_t::HN_REQUIRED
+ ? "\\*"
+ : "",
+ sub_param.ht_summary);
+ }
+ }
}
}
fmt::fprintf(rst_file, "\n");