Skip to content

Commit

Permalink
[prompt] timezone completion
Browse files Browse the repository at this point in the history
  • Loading branch information
tstack committed Feb 18, 2025
1 parent 7e19fbd commit 03e281e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/cmd.parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ parse_for(mode_t mode,
case help_parameter_format_t::HPF_STRING:
case help_parameter_format_t::HPF_FILENAME:
case help_parameter_format_t::HPF_LOADED_FILE:
case help_parameter_format_t::HPF_FORMAT_FIELD: {
case help_parameter_format_t::HPF_FORMAT_FIELD:
case help_parameter_format_t::HPF_TIMEZONE: {
if (!param.ht_enum_values.empty()) {
auto enum_iter = std::find(param.ht_enum_values.begin(),
param.ht_enum_values.end(),
Expand Down
1 change: 1 addition & 0 deletions src/help_text.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum class help_parameter_format_t {
HPF_FORMAT_FIELD,
HPF_DIRECTORY,
HPF_TIME_FILTER_POINT,
HPF_TIMEZONE,
};

struct help_example {
Expand Down
16 changes: 16 additions & 0 deletions src/lnav.prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,22 @@ prompt::get_cmd_parameter_completion(textview_curses& tc,
SUBST_TEXT.value(x + " "));
});
}
case help_parameter_format_t::HPF_TIMEZONE: {
std::vector<std::string> tz_strs;
try {
for (const auto& tz : date::get_tzdb().zones) {
tz_strs.emplace_back(tz.name());
}
} catch (const std::runtime_error& e) {
log_error("unable to get tzdb -- %s", e.what());
}

return tz_strs | lnav::itertools::similar_to(str, 10)
| lnav::itertools::map([](const auto& x) {
return attr_line_t().append(x).with_attr_for_all(
SUBST_TEXT.value(x + " "));
});
}
}
} else {
return ht->ht_enum_values | lnav::itertools::similar_to(str, 10)
Expand Down
17 changes: 7 additions & 10 deletions src/lnav_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ com_unix_time(exec_context& ec,
{
std::string retval;

if (args.empty()) {
} else if (args.size() >= 2) {
if (args.size() >= 2) {
bool parsed = false;
struct tm log_time;
time_t u_time;
Expand Down Expand Up @@ -599,11 +598,6 @@ com_convert_time_to(exec_context& ec,
{
std::string retval;

if (args.empty()) {
args.emplace_back("timezone");
return Ok(retval);
}

if (args.size() == 1) {
return ec.make_error("expecting a timezone name");
}
Expand Down Expand Up @@ -4208,7 +4202,9 @@ readline_context::command_t STD_COMMANDS[] = {
help_text(":convert-time-to")
.with_summary("Convert the focused timestamp to the "
"given timezone")
.with_parameter(help_text("zone", "The timezone name")),
.with_parameter(
help_text("zone", "The timezone name")
.with_format(help_parameter_format_t::HPF_TIMEZONE)),
},
{
"set-file-timezone",
Expand All @@ -4218,7 +4214,8 @@ readline_context::command_t STD_COMMANDS[] = {
"not include a timezone. The timezone is applied "
"to "
"the focused file or the given glob pattern.")
.with_parameter({"zone", "The timezone name"})
.with_parameter(help_text{"zone", "The timezone name"}.with_format(
help_parameter_format_t::HPF_TIMEZONE))
.with_parameter(help_text{"pattern",
"The glob pattern to match against "
"files that should use this timezone"}
Expand Down Expand Up @@ -4811,7 +4808,7 @@ readline_context::command_t STD_COMMANDS[] = {
help_text(":zoom-to")
.with_summary("Zoom the histogram view to the given level")
.with_parameter(help_text("zoom-level", "The zoom level")
.with_enum_values(lnav_zoom_strings))
.with_enum_values(lnav_zoom_strings))
.with_example({"To set the zoom level to '1-week'", "1-week"}),
},
{"echo",
Expand Down

0 comments on commit 03e281e

Please sign in to comment.