summaryrefslogtreecommitdiffstats
path: root/src/state-extension-functions.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
commit207df6fc406e81bfeebdff7f404bd242ff3f099f (patch)
treea1a796b056909dd0a04ffec163db9363a8757808 /src/state-extension-functions.cc
parentReleasing progress-linux version 0.11.2-1~progress7.99u1. (diff)
downloadlnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz
lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/state-extension-functions.cc77
1 files changed, 63 insertions, 14 deletions
diff --git a/src/state-extension-functions.cc b/src/state-extension-functions.cc
index b382471..e7aca12 100644
--- a/src/state-extension-functions.cc
+++ b/src/state-extension-functions.cc
@@ -48,7 +48,31 @@ sql_log_top_line()
if (tc.get_inner_height() == 0_vl) {
return nonstd::nullopt;
}
- return (int64_t) tc.get_top();
+ return (int64_t) tc.get_selection();
+}
+
+static nonstd::optional<int64_t>
+sql_log_msg_line()
+{
+ const auto& tc = lnav_data.ld_views[LNV_LOG];
+
+ if (tc.get_inner_height() == 0_vl) {
+ return nonstd::nullopt;
+ }
+
+ auto top_line = tc.get_selection();
+ auto line_pair_opt = lnav_data.ld_log_source.find_line_with_file(top_line);
+ if (!line_pair_opt) {
+ return nonstd::nullopt;
+ }
+
+ auto ll = line_pair_opt.value().second;
+ while (ll->is_continued()) {
+ --ll;
+ top_line -= 1_vl;
+ }
+
+ return (int64_t) top_line;
}
static nonstd::optional<std::string>
@@ -60,15 +84,15 @@ sql_log_top_datetime()
return nonstd::nullopt;
}
- auto top_time = lnav_data.ld_log_source.time_for_row(
- lnav_data.ld_views[LNV_LOG].get_top());
- if (!top_time) {
+ auto top_ri = lnav_data.ld_log_source.time_for_row(
+ lnav_data.ld_views[LNV_LOG].get_selection());
+ if (!top_ri) {
return nonstd::nullopt;
}
char buffer[64];
- sql_strftime(buffer, sizeof(buffer), top_time.value());
+ sql_strftime(buffer, sizeof(buffer), top_ri->ri_time);
return buffer;
}
@@ -99,9 +123,14 @@ sql_lnav_version()
}
static int64_t
-sql_error(const char* str)
+sql_error(const char* str, nonstd::optional<string_fragment> reason)
{
- throw sqlite_func_error("{}", str);
+ auto um = lnav::console::user_message::error(str);
+
+ if (reason) {
+ um.with_reason(reason->to_string());
+ }
+ throw um;
}
static nonstd::optional<std::string>
@@ -129,33 +158,53 @@ state_extension_functions(struct FuncDef** basic_funcs,
static struct FuncDef state_funcs[] = {
sqlite_func_adapter<decltype(&sql_log_top_line), sql_log_top_line>::
builder(
- help_text("log_top_line",
- "Return the line number at the top of the log view.")
- .sql_function()),
+ help_text(
+ "log_top_line",
+ "Return the number of the focused line of the log view.")
+ .sql_function()
+ .with_prql_path({"lnav", "view", "top_line"})),
+
+ sqlite_func_adapter<decltype(&sql_log_msg_line), sql_log_msg_line>::
+ builder(help_text("log_msg_line",
+ "Return the starting line number of the focused "
+ "log message.")
+ .sql_function()
+ .with_prql_path({"lnav", "view", "msg_line"})),
sqlite_func_adapter<decltype(&sql_log_top_datetime),
sql_log_top_datetime>::
builder(help_text("log_top_datetime",
"Return the timestamp of the line at the top of "
"the log view.")
- .sql_function()),
+ .sql_function()
+ .with_prql_path({"lnav", "view", "top_datetime"})),
sqlite_func_adapter<decltype(&sql_lnav_top_file), sql_lnav_top_file>::
builder(help_text("lnav_top_file",
"Return the name of the file that the top line "
"in the current view came from.")
- .sql_function()),
+ .sql_function()
+ .with_prql_path({"lnav", "view", "top_file"})),
sqlite_func_adapter<decltype(&sql_lnav_version), sql_lnav_version>::
builder(
help_text("lnav_version", "Return the current version of lnav")
- .sql_function()),
+ .sql_function()
+ .with_prql_path({"lnav", "version"})),
sqlite_func_adapter<decltype(&sql_error), sql_error>::builder(
help_text("raise_error",
"Raises an error with the given message when executed")
.sql_function()
- .with_parameter({"msg", "The error message"}))
+ .with_parameter({"msg", "The error message"})
+ .with_parameter(
+ help_text("reason", "The reason the error occurred")
+ .optional())
+ .with_example({
+ "To raise an error if a variable is not set",
+ "SELECT ifnull($val, raise_error('please set $val', "
+ "'because'))",
+ }))
.with_flags(SQLITE_UTF8),
sqlite_func_adapter<decltype(&sql_echoln), sql_echoln>::builder(