Skip to content

Commit 2acb1b8

Browse files
committed
[stdin] dump stdin content if less than terminal height or marked
1 parent 7b3992e commit 2acb1b8

9 files changed

Lines changed: 59 additions & 10 deletions

File tree

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ Features:
6464
to get/set the sticky state via SQL. Sticky headers
6565
and user bookmarks are saved and restored across
6666
sessions for both log and text views.
67+
* In pager mode (activated by the `-q` flag), the input
68+
will always be written to the terminal if it is
69+
smaller than the height. Previously, if the input
70+
took awhile to generate, nothing would be written.
71+
Also, when the input is larger than the terminal
72+
height, any marked lines will be written to the
73+
terminal.
6774
* Introducing "Log-Oriented Debugging", a collection of
6875
features to streamline mapping log messages back to
6976
the source code that generated them. For example,
@@ -96,6 +103,10 @@ Features:
96103
breakpoints have been added, you can press `F7`/`F8`
97104
to move to the previous/next log message that
98105
matches a breakpoint.
106+
- If the log format specifies source file/line fields,
107+
the first character of the source file will be
108+
underlined and can be clicked to open the source
109+
file at the given log message.
99110
* The `all_opids` and `all_thread_ids` virtual tables
100111
have been added to make it simple to discover all of
101112
the operations and threads across all log files. The

docs/source/usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ to modify lnav's behavior to make it more amenable for this purpose:
235235
With this option, lnav will:
236236

237237
* Not save the piped content after exiting.
238-
* Print the content to the screen if it is less than the height of the
239-
terminal.
238+
* Print any marked lines to the screen OR all lines if the total
239+
height is less than the terminal height.
240240

241241
Searching
242242
---------

src/bookmarks.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public:
138138
return retval;
139139
}
140140

141+
bool contains(LineType vl)
142+
{
143+
return this->bv_tree.find(vl) != this->bv_tree.end();
144+
}
145+
141146
std::pair<iterator, iterator> equal_range(LineType start, LineType stop)
142147
{
143148
auto lb = this->bv_tree.lower_bound(start);

src/cmds.scripting.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ com_eval(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
255255
log_debug("Expanded command to evaluate: %s", expanded_cmd.c_str());
256256

257257
if (expanded_cmd.empty()) {
258-
return ec.make_error("empty result after evaluation");
258+
return Ok(retval);
259259
}
260260

261261
if (ec.ec_dry_run) {

src/lnav.cc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4443,14 +4443,33 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
44434443
} else {
44444444
init_session();
44454445

4446-
guard_termios gt(STDIN_FILENO);
4447-
lnav_log_orig_termios = gt.get_termios();
4446+
{
4447+
guard_termios gt(STDIN_FILENO);
4448+
lnav_log_orig_termios = gt.get_termios();
4449+
4450+
looper();
44484451

4449-
looper();
4452+
dup2(STDOUT_FILENO, STDERR_FILENO);
44504453

4451-
dup2(STDOUT_FILENO, STDERR_FILENO);
4454+
signal(SIGINT, SIG_DFL);
4455+
}
44524456

4453-
signal(SIGINT, SIG_DFL);
4457+
if (stdin_url && verbosity == verbosity_t::quiet) {
4458+
auto& tc = lnav_data.ld_views[LNV_TEXT];
4459+
auto& bv = tc.get_bookmarks()[&textview_curses::BM_USER];
4460+
tc.tc_mark_style = std::nullopt;
4461+
bool is_short = tc.get_inner_height() < term_size.ws_row - 3;
4462+
if (is_short || !bv.empty()) {
4463+
for (auto vl = 0_vl; vl < tc.get_inner_height(); ++vl) {
4464+
if (!is_short && !bv.contains(vl)) {
4465+
continue;
4466+
}
4467+
std::vector<attr_line_t> rows(1);
4468+
tc.listview_value_for_rows(tc, vl, rows);
4469+
write_line_to(stdout, rows[0]);
4470+
}
4471+
}
4472+
}
44544473
}
44554474

44564475
log_info("exiting main loop");

src/logfile_sub_source.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv,
843843
this->lss_token_al.al_attrs.emplace_back(lr,
844844
VC_COMMAND.value(ui_command{
845845
source_location{},
846-
":toggle-breakpoint",
846+
"|lnav-open-source",
847847
}));
848848
}
849849

src/root-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"impls": {
150150
"IntelliJ": {
151151
"config-dir": ".idea",
152-
"prefers": "^.*(?:\\.java|\\.kt)$",
152+
"prefers": "^.*(?:\\.java|\\.kt|\\.py)$",
153153
"test": "command -v idea",
154154
"command": "idea --line ${LINE} --column ${COL} \"$FILE_PATH\""
155155
},

src/scripts/lnav-open-source.lnav

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# @synopsis: lnav-open-source
3+
# @description: Open the source file for the focused log message.
4+
#
5+
6+
;SELECT jget(log_msg_src, '/file', NULL) AS file_path,
7+
jget(log_msg_src, '/begin_line', NULL) AS begin_line
8+
FROM lnav_focused_msg
9+
;SELECT raise_error('Unable to locate source file: ' || $file_path,
10+
'Use :add-source-path to add a source path.')
11+
WHERE $file_path IS NULL
12+
;SELECT unparse_url(json_object('scheme', 'file', 'path', $file_path, 'fragment', format('L%d', $begin_line))) AS url
13+
:xopen $url

src/scripts/scripts.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ BUILTIN_LNAVSCRIPTS = \
88
$(srcdir)/scripts/lnav-copy-text.lnav \
99
$(srcdir)/scripts/lnav-link-callback.lnav \
1010
$(srcdir)/scripts/lnav-moveto-breakpoint.lnav \
11+
$(srcdir)/scripts/lnav-open-source.lnav \
1112
$(srcdir)/scripts/lnav-pop-view.lnav \
1213
$(srcdir)/scripts/lnav-write-external-access-info-to.lnav \
1314
$(srcdir)/scripts/partition-by-boot.lnav \

0 commit comments

Comments
 (0)