Skip to content

Commit b44369e

Browse files
committed
[:comment] show markdown preview of the comment text
1 parent 1799c2c commit b44369e

5 files changed

+166
-143
lines changed

src/cmds.io.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
11991199
file_range range;
12001200

12011201
lb.set_fd(preview_fd);
1202-
for (int lpc = 0; lpc < 10; lpc++) {
1202+
for (int lpc = 0; lpc < 24; lpc++) {
12031203
auto load_result = lb.load_next_line(range);
12041204

12051205
if (load_result.isErr()) {
@@ -1243,10 +1243,14 @@ com_open(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
12431243
}
12441244
}
12451245

1246+
auto tf = detect_text_format(al.get_string(), fn_str);
1247+
log_debug(":open preview text format: %s",
1248+
fmt::to_string(tf).c_str());
1249+
12461250
lnav_data.ld_preview_view[0].set_sub_source(
12471251
&lnav_data.ld_preview_source[0]);
12481252
lnav_data.ld_preview_source[0].replace_with(al).set_text_format(
1249-
detect_text_format(al.get_string()));
1253+
tf);
12501254
lnav_data.ld_preview_status_source[0]
12511255
.get_description()
12521256
.set_value("For file: %s", fn.c_str());

src/lnav_commands.cc

+17-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
#include "log_format_loader.hh"
7474
#include "log_search_table.hh"
7575
#include "log_search_table_fwd.hh"
76+
#include "md2attr_line.hh"
77+
#include "md4cpp.hh"
7678
#include "ptimec.hh"
7779
#include "readline_callbacks.hh"
7880
#include "readline_highlighters.hh"
@@ -1882,7 +1884,22 @@ com_comment(exec_context& ec,
18821884
std::string retval;
18831885

18841886
if (args.size() > 1) {
1887+
args[1] = trim(remaining_args(cmdline, args));
1888+
18851889
if (ec.ec_dry_run) {
1890+
md2attr_line mdal;
1891+
1892+
auto parse_res = md4cpp::parse(args[1], mdal);
1893+
if (parse_res.isOk()) {
1894+
auto al = parse_res.unwrap();
1895+
lnav_data.ld_preview_status_source[0]
1896+
.get_description()
1897+
.set_value("Comment rendered as markdown:");
1898+
lnav_data.ld_preview_view[0].set_sub_source(
1899+
&lnav_data.ld_preview_source[0]);
1900+
lnav_data.ld_preview_source[0].replace_with(al);
1901+
}
1902+
18861903
return Ok(std::string());
18871904
}
18881905
auto* tc = *lnav_data.ld_view_stack.top();
@@ -1893,7 +1910,6 @@ com_comment(exec_context& ec,
18931910
}
18941911
auto& lss = lnav_data.ld_log_source;
18951912

1896-
args[1] = trim(remaining_args(cmdline, args));
18971913
auto unquoted = auto_buffer::alloc(args[1].size() + 1);
18981914
auto unquoted_len = unquote_content(
18991915
unquoted.in(), args[1].c_str(), args[1].size(), 0);

src/themes/dracula.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"bgdarker": "#191A21",
1212
"foreground": "#F8F8F2",
1313
"selection": "#44475A",
14+
"comment": "#6272A4",
1415
"black": "#21222C",
1516
"red": "#FF5555",
1617
"green": "#50FA7B",
@@ -193,7 +194,7 @@
193194
"bold": true
194195
},
195196
"comment": {
196-
"color": "#6272A4"
197+
"color": "$comment"
197198
},
198199
"doc-directive": {
199200
"color": "$pink"

test/expected/test_cli.sh_0b3639753916f71254e8c9cce4ebb8bfd9978d3e.out

+2-1
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@
10161016
"bglighter": "#424450",
10171017
"black": "#21222C",
10181018
"blue": "#BD93F9",
1019+
"comment": "#6272A4",
10191020
"cyan": "#8BE9FD",
10201021
"foreground": "#F8F8F2",
10211022
"green": "#50FA7B",
@@ -1445,7 +1446,7 @@
14451446
"strike": false
14461447
},
14471448
"comment": {
1448-
"color": "#6272A4",
1449+
"color": "$comment",
14491450
"background-color": "",
14501451
"underline": false,
14511452
"bold": false,

0 commit comments

Comments
 (0)