mirror of
https://github.com/tstack/lnav.git
synced 2024-08-17 00:40:30 +03:00
Merge branch 'master' of github:tstack/lnav
This commit is contained in:
commit
53ce768b9d
172
src/lnav.cc
172
src/lnav.cc
@ -755,12 +755,18 @@ static void sigwinch(int sig)
|
||||
|
||||
static void back_ten(int ten_minute)
|
||||
{
|
||||
logfile_sub_source &lss = lnav_data.ld_log_source;
|
||||
textview_curses * tc = lnav_data.ld_view_stack.top();
|
||||
logfile_sub_source *lss;
|
||||
|
||||
lss = dynamic_cast<logfile_sub_source *>(tc->get_sub_source());
|
||||
|
||||
if (!lss)
|
||||
return;
|
||||
|
||||
time_t hour = rounddown_offset(lnav_data.ld_top_time,
|
||||
60 * 60,
|
||||
ten_minute * 10 * 60);
|
||||
vis_line_t line = lss.find_from_time(hour);
|
||||
vis_line_t line = lss->find_from_time(hour);
|
||||
|
||||
--line;
|
||||
lnav_data.ld_view_stack.top()->set_top(line);
|
||||
@ -1185,52 +1191,48 @@ static void handle_paging_key(int ch)
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (lss) {
|
||||
lnav_data.ld_last_user_mark[tc] = tc->get_top();
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(lnav_data.ld_last_user_mark[tc]));
|
||||
tc->reload_data();
|
||||
lnav_data.ld_last_user_mark[tc] = tc->get_top();
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(lnav_data.ld_last_user_mark[tc]));
|
||||
tc->reload_data();
|
||||
|
||||
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
|
||||
u, U,
|
||||
"to move forward/backward through user bookmarks"));
|
||||
}
|
||||
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
|
||||
u, U,
|
||||
"to move forward/backward through user bookmarks"));
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
if (lss) {
|
||||
if (lnav_data.ld_last_user_mark.find(tc) ==
|
||||
lnav_data.ld_last_user_mark.end() ||
|
||||
!tc->is_visible(vis_line_t(lnav_data.ld_last_user_mark[tc]))) {
|
||||
lnav_data.ld_last_user_mark[tc] = tc->get_top();
|
||||
}
|
||||
else {
|
||||
vis_line_t height;
|
||||
unsigned long width;
|
||||
|
||||
tc->get_dimensions(height, width);
|
||||
if (lnav_data.ld_last_user_mark[tc] > tc->get_bottom() - 2 &&
|
||||
tc->get_top() + height < tc->get_inner_height()) {
|
||||
tc->shift_top(vis_line_t(1));
|
||||
}
|
||||
if (lnav_data.ld_last_user_mark[tc] + 1 >=
|
||||
tc->get_inner_height()) {
|
||||
break;
|
||||
}
|
||||
lnav_data.ld_last_user_mark[tc] += 1;
|
||||
}
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(lnav_data.ld_last_user_mark[tc]));
|
||||
tc->reload_data();
|
||||
|
||||
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
|
||||
c,
|
||||
"to copy marked lines to the clipboard"));
|
||||
if (lnav_data.ld_last_user_mark.find(tc) ==
|
||||
lnav_data.ld_last_user_mark.end() ||
|
||||
!tc->is_visible(vis_line_t(lnav_data.ld_last_user_mark[tc]))) {
|
||||
lnav_data.ld_last_user_mark[tc] = tc->get_top();
|
||||
}
|
||||
else {
|
||||
vis_line_t height;
|
||||
unsigned long width;
|
||||
|
||||
tc->get_dimensions(height, width);
|
||||
if (lnav_data.ld_last_user_mark[tc] > tc->get_bottom() - 2 &&
|
||||
tc->get_top() + height < tc->get_inner_height()) {
|
||||
tc->shift_top(vis_line_t(1));
|
||||
}
|
||||
if (lnav_data.ld_last_user_mark[tc] + 1 >=
|
||||
tc->get_inner_height()) {
|
||||
break;
|
||||
}
|
||||
lnav_data.ld_last_user_mark[tc] += 1;
|
||||
}
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(lnav_data.ld_last_user_mark[tc]));
|
||||
tc->reload_data();
|
||||
|
||||
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
|
||||
c,
|
||||
"to copy marked lines to the clipboard"));
|
||||
break;
|
||||
|
||||
case 'K':
|
||||
if (lss) {
|
||||
{
|
||||
int new_mark;
|
||||
|
||||
if (lnav_data.ld_last_user_mark.find(tc) ==
|
||||
@ -1243,8 +1245,8 @@ static void handle_paging_key(int ch)
|
||||
new_mark = lnav_data.ld_last_user_mark[tc];
|
||||
}
|
||||
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(new_mark));
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(new_mark));
|
||||
if (new_mark == tc->get_top()) {
|
||||
tc->shift_top(vis_line_t(-1));
|
||||
}
|
||||
@ -1264,39 +1266,37 @@ static void handle_paging_key(int ch)
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
if (lss) {
|
||||
if (lnav_data.ld_last_user_mark.find(tc) ==
|
||||
lnav_data.ld_last_user_mark.end()) {
|
||||
flash();
|
||||
}
|
||||
else {
|
||||
int start_line = min(
|
||||
(int)tc->get_top(), lnav_data.ld_last_user_mark[tc] + 1);
|
||||
int end_line = max(
|
||||
(int)tc->get_top(), lnav_data.ld_last_user_mark[tc] - 1);
|
||||
if (lnav_data.ld_last_user_mark.find(tc) ==
|
||||
lnav_data.ld_last_user_mark.end()) {
|
||||
flash();
|
||||
}
|
||||
else {
|
||||
int start_line = min((int)tc->get_top(),
|
||||
lnav_data.ld_last_user_mark[tc] + 1);
|
||||
int end_line = max((int)tc->get_top(),
|
||||
lnav_data.ld_last_user_mark[tc] - 1);
|
||||
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(start_line),
|
||||
vis_line_t(end_line));
|
||||
tc->reload_data();
|
||||
}
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
vis_line_t(start_line),
|
||||
vis_line_t(end_line));
|
||||
tc->reload_data();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
{
|
||||
bookmark_vector<vis_line_t>::iterator iter;
|
||||
{
|
||||
bookmark_vector<vis_line_t>::iterator iter;
|
||||
|
||||
for (iter = bm[&textview_curses::BM_SEARCH].begin();
|
||||
iter != bm[&textview_curses::BM_SEARCH].end();
|
||||
++iter) {
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER, *iter);
|
||||
for (iter = bm[&textview_curses::BM_SEARCH].begin();
|
||||
iter != bm[&textview_curses::BM_SEARCH].end();
|
||||
++iter) {
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER, *iter);
|
||||
}
|
||||
|
||||
lnav_data.ld_last_user_mark[tc] = -1;
|
||||
tc->reload_data();
|
||||
}
|
||||
|
||||
lnav_data.ld_last_user_mark[tc] = -1;
|
||||
tc->reload_data();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
case '2':
|
||||
@ -2423,29 +2423,27 @@ public:
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (lss) {
|
||||
if (this->lb_selection_start == vis_line_t(-1)) {
|
||||
this->lb_selection_start = vis_y;
|
||||
this->lb_selection_last = vis_line_t(-1);
|
||||
if (this->lb_selection_start == vis_line_t(-1)) {
|
||||
this->lb_selection_start = vis_y;
|
||||
this->lb_selection_last = vis_line_t(-1);
|
||||
}
|
||||
else {
|
||||
if (this->lb_selection_last != vis_line_t(-1)) {
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
this->lb_selection_start,
|
||||
this->lb_selection_last);
|
||||
}
|
||||
if (this->lb_selection_start == vis_y) {
|
||||
this->lb_selection_last = vis_line_t(-1);
|
||||
}
|
||||
else {
|
||||
if (this->lb_selection_last != vis_line_t(-1)) {
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
this->lb_selection_start,
|
||||
this->lb_selection_last);
|
||||
}
|
||||
if (this->lb_selection_start == vis_y) {
|
||||
this->lb_selection_last = vis_line_t(-1);
|
||||
}
|
||||
else {
|
||||
lss->toggle_user_mark(&textview_curses::BM_USER,
|
||||
this->lb_selection_start,
|
||||
vis_y);
|
||||
this->lb_selection_last = vis_y;
|
||||
}
|
||||
tc->toggle_user_mark(&textview_curses::BM_USER,
|
||||
this->lb_selection_start,
|
||||
vis_y);
|
||||
this->lb_selection_last = vis_y;
|
||||
}
|
||||
tc->reload_data();
|
||||
}
|
||||
tc->reload_data();
|
||||
break;
|
||||
|
||||
case xterm_mouse::XT_BUTTON_RELEASE:
|
||||
|
@ -123,6 +123,7 @@ typedef std::pair<ppid_time_pair_t, std::string> session_pair_t;
|
||||
struct _lnav_data {
|
||||
std::string ld_session_id;
|
||||
time_t ld_session_time;
|
||||
time_t ld_session_load_time;
|
||||
time_t ld_session_save_time;
|
||||
std::list<session_pair_t> ld_session_file_names;
|
||||
int ld_session_file_index;
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "auto_fd.hh"
|
||||
#include "lnav_util.hh"
|
||||
|
||||
std::string hash_string(const std::string &str)
|
||||
@ -144,7 +145,7 @@ bool change_to_parent_dir(void)
|
||||
file_format_t detect_file_format(const std::string &filename)
|
||||
{
|
||||
file_format_t retval = FF_UNKNOWN;
|
||||
int fd;
|
||||
auto_fd fd;
|
||||
|
||||
if ((fd = open(filename.c_str(), O_RDONLY)) != -1) {
|
||||
char buffer[32];
|
||||
|
@ -95,6 +95,9 @@ static string latest_bookmark_file(const string &name)
|
||||
|
||||
base = strrchr(path, '/') + 1;
|
||||
if (sscanf(base, "file-%*[^.].ts%d.json", ×tamp) == 1) {
|
||||
if (timestamp == lnav_data.ld_session_load_time) {
|
||||
return path;
|
||||
}
|
||||
file_names.push_back(make_pair(timestamp, path));
|
||||
}
|
||||
}
|
||||
@ -339,7 +342,7 @@ void load_bookmarks(void)
|
||||
const string &log_name = iter->ld_file->get_filename();
|
||||
string mark_file_name;
|
||||
yajl_handle handle;
|
||||
int fd;
|
||||
auto_fd fd;
|
||||
|
||||
fprintf(stderr, "load %s\n", log_name.c_str());
|
||||
|
||||
@ -452,20 +455,22 @@ void load_session(void)
|
||||
std::list<session_pair_t>::iterator sess_iter;
|
||||
yajlpp_parse_context ypc(view_info_handlers);
|
||||
yajl_handle handle;
|
||||
int fd;
|
||||
|
||||
load_bookmarks();
|
||||
auto_fd fd;
|
||||
|
||||
if (lnav_data.ld_session_file_names.empty()) {
|
||||
load_bookmarks();
|
||||
return;
|
||||
}
|
||||
|
||||
handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc);
|
||||
sess_iter = lnav_data.ld_session_file_names.begin();
|
||||
advance(sess_iter, lnav_data.ld_session_file_index);
|
||||
lnav_data.ld_session_load_time = sess_iter->first.second;
|
||||
lnav_data.ld_session_save_time = sess_iter->first.second;
|
||||
string &view_info_name = sess_iter->second;
|
||||
|
||||
load_bookmarks();
|
||||
|
||||
if ((fd = open(view_info_name.c_str(), O_RDONLY)) < 0) {
|
||||
perror("cannot open session file");
|
||||
}
|
||||
|
@ -197,6 +197,37 @@ public:
|
||||
|
||||
vis_bookmarks &get_bookmarks(void) { return this->tc_bookmarks; };
|
||||
|
||||
void toggle_user_mark(bookmark_type_t *bm,
|
||||
vis_line_t start_line,
|
||||
vis_line_t end_line = vis_line_t(-1))
|
||||
{
|
||||
if (end_line == -1) {
|
||||
end_line = start_line;
|
||||
}
|
||||
if (start_line > end_line) {
|
||||
std::swap(start_line, end_line);
|
||||
}
|
||||
for (vis_line_t curr_line = start_line; curr_line <= end_line;
|
||||
++curr_line) {
|
||||
bookmark_vector<vis_line_t> &bv =
|
||||
this->tc_bookmarks[bm];
|
||||
bookmark_vector<vis_line_t>::iterator iter;
|
||||
bool added;
|
||||
|
||||
iter = bv.insert_once(curr_line);
|
||||
if (iter == bv.end()) {
|
||||
added = true;
|
||||
}
|
||||
else {
|
||||
bv.erase(iter);
|
||||
added = false;
|
||||
}
|
||||
if (this->tc_sub_source != NULL) {
|
||||
this->tc_sub_source->text_mark(bm, (int)curr_line, added);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void set_sub_source(text_sub_source *src)
|
||||
{
|
||||
this->tc_sub_source = src;
|
||||
|
@ -435,7 +435,7 @@ public:
|
||||
return VC_ANSI_START + ((fg * 8) + bg);
|
||||
};
|
||||
|
||||
int ansi_color_pair(int fg, int bg)
|
||||
static inline int ansi_color_pair(int fg, int bg)
|
||||
{
|
||||
return COLOR_PAIR(ansi_color_pair_index(fg, bg));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user