lnav/src/lnav.hh

285 lines
8.3 KiB
C++
Raw Normal View History

2012-07-13 16:26:47 +00:00
/**
2013-05-03 06:02:03 +00:00
* Copyright (c) 2007-2012, Timothy Stack
*
* All rights reserved.
2013-05-28 04:35:00 +00:00
*
2013-05-03 06:02:03 +00:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
2013-05-28 04:35:00 +00:00
*
2013-05-03 06:02:03 +00:00
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
2013-05-28 04:35:00 +00:00
*
2013-05-03 06:02:03 +00:00
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2022-03-16 22:38:08 +00:00
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2013-05-03 06:02:03 +00:00
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
2012-07-13 16:26:47 +00:00
* @file lnav.hh
*/
#ifndef lnav_hh
#define lnav_hh
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
#include <list>
2012-07-13 16:26:47 +00:00
#include <map>
2022-03-16 22:38:08 +00:00
#include <memory>
2012-07-13 16:26:47 +00:00
#include <set>
#include <stack>
#include <unordered_map>
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
#include <signal.h>
#include <sys/time.h>
#include "archive_manager.hh"
2022-04-12 23:07:13 +00:00
#include "base/ansi_scrubber.hh"
#include "base/future_util.hh"
#include "base/isc.hh"
2012-07-13 16:26:47 +00:00
#include "bottom_status_source.hh"
2022-07-20 06:48:25 +00:00
#include "bound_tags.hh"
2022-03-16 22:38:08 +00:00
#include "command_executor.hh"
#include "config.h"
#include "db_sub_source.hh"
#include "doc_status_source.hh"
2022-03-16 22:38:08 +00:00
#include "file_collection.hh"
#include "files_sub_source.hh"
#include "filter_status_source.hh"
2012-07-13 16:26:47 +00:00
#include "grep_highlighter.hh"
2022-03-16 22:38:08 +00:00
#include "hist_source.hh"
#include "input_dispatcher.hh"
#include "listview_curses.hh"
#include "log_format_loader.hh"
2012-07-13 16:26:47 +00:00
#include "log_vtab_impl.hh"
2022-03-16 22:38:08 +00:00
#include "logfile.hh"
#include "plain_text_source.hh"
#include "preview_status_source.hh"
2022-03-16 22:38:08 +00:00
#include "readline_curses.hh"
#include "relative_time.hh"
#include "safe/safe.h"
#include "sql_util.hh"
2022-03-16 22:38:08 +00:00
#include "statusview_curses.hh"
#include "textfile_sub_source.hh"
#include "view_helpers.hh"
2012-07-13 16:26:47 +00:00
class spectrogram_source;
class spectro_status_source;
2022-06-23 05:53:52 +00:00
extern const std::vector<std::string> lnav_zoom_strings;
2012-07-13 16:26:47 +00:00
/** The status bars. */
typedef enum {
2022-07-15 05:32:38 +00:00
LNS_TOP,
2012-07-13 16:26:47 +00:00
LNS_BOTTOM,
LNS_FILTER,
LNS_FILTER_HELP,
LNS_DOC,
LNS_PREVIEW,
LNS_SPECTRO,
2012-07-13 16:26:47 +00:00
LNS__MAX
} lnav_status_t;
using ppid_time_pair_t = std::pair<int, int>;
using session_pair_t = std::pair<ppid_time_pair_t, ghc::filesystem::path>;
2013-06-02 21:20:15 +00:00
2015-04-02 13:49:16 +00:00
class input_state_tracker : public log_state_dumper {
public:
input_state_tracker()
2022-03-16 22:38:08 +00:00
{
memset(this->ist_recent_key_presses,
0,
sizeof(this->ist_recent_key_presses));
}
2015-04-02 13:49:16 +00:00
2022-03-16 22:38:08 +00:00
void log_state() override
{
2015-04-02 13:49:16 +00:00
log_info("recent_key_presses: index=%d", this->ist_index);
for (int lpc = 0; lpc < COUNT; lpc++) {
2022-03-16 22:38:08 +00:00
log_msg_extra(" 0x%x (%c)",
this->ist_recent_key_presses[lpc],
this->ist_recent_key_presses[lpc]);
2015-04-02 13:49:16 +00:00
}
log_msg_extra_complete();
}
2015-04-02 13:49:16 +00:00
2022-03-16 22:38:08 +00:00
void push_back(int ch)
{
2015-04-02 13:49:16 +00:00
this->ist_recent_key_presses[this->ist_index % COUNT] = ch;
this->ist_index = (this->ist_index + 1) % COUNT;
}
2015-04-02 13:49:16 +00:00
private:
static const int COUNT = 10;
int ist_recent_key_presses[COUNT];
size_t ist_index{0};
2015-04-02 13:49:16 +00:00
};
struct key_repeat_history {
2020-10-29 04:24:23 +00:00
int krh_key{0};
int krh_count{0};
vis_line_t krh_start_line{0_vl};
2022-03-16 22:38:08 +00:00
struct timeval krh_last_press_time {
0, 0
};
2022-03-16 22:38:08 +00:00
void update(int ch, vis_line_t top)
{
struct timeval now, diff;
gettimeofday(&now, nullptr);
timersub(&now, &this->krh_last_press_time, &diff);
if (diff.tv_sec >= 1 || diff.tv_usec > (750 * 1000)) {
this->krh_key = 0;
this->krh_count = 0;
}
this->krh_last_press_time = now;
if (this->krh_key == ch) {
this->krh_count += 1;
} else {
this->krh_key = ch;
this->krh_count = 1;
this->krh_start_line = top;
}
};
};
using file_location_t = mapbox::util::variant<vis_line_t, std::string>;
struct lnav_data_t {
2020-04-25 14:32:05 +00:00
std::map<std::string, std::list<session_pair_t>> ld_session_id;
2022-03-16 22:38:08 +00:00
time_t ld_session_time;
time_t ld_session_load_time;
const char* ld_program_name;
std::string ld_debug_log_name;
2022-03-16 22:38:08 +00:00
std::list<std::string> ld_commands;
bool ld_cmd_init_done;
bool ld_session_loaded;
std::vector<ghc::filesystem::path> ld_config_paths;
file_collection ld_active_files;
std::list<child_poller> ld_child_pollers;
std::list<std::pair<std::string, file_location_t>> ld_files_to_front;
2022-03-16 22:38:08 +00:00
bool ld_stdout_used;
sig_atomic_t ld_looping;
sig_atomic_t ld_winched;
sig_atomic_t ld_child_terminated;
unsigned long ld_flags;
WINDOW* ld_window;
ln_mode_t ld_mode;
ln_mode_t ld_last_config_mode{ln_mode_t::FILTER};
2022-03-16 22:38:08 +00:00
statusview_curses ld_status[LNS__MAX];
bottom_status_source ld_bottom_source;
filter_status_source ld_filter_status_source;
filter_help_status_source ld_filter_help_status_source;
doc_status_source ld_doc_status_source;
preview_status_source ld_preview_status_source;
std::unique_ptr<spectro_status_source> ld_spectro_status_source;
2022-03-16 22:38:08 +00:00
bool ld_preview_hidden;
int64_t ld_preview_generation{0};
action_broadcaster<listview_curses> ld_scroll_broadcaster;
action_broadcaster<listview_curses> ld_view_stack_broadcaster;
plain_text_source ld_help_source;
plain_text_source ld_doc_source;
textview_curses ld_doc_view;
textview_curses ld_filter_view;
files_sub_source ld_files_source;
files_overlay_source ld_files_overlay;
textview_curses ld_files_view;
plain_text_source ld_example_source;
textview_curses ld_example_view;
plain_text_source ld_match_source;
textview_curses ld_match_view;
plain_text_source ld_preview_source;
textview_curses ld_preview_view;
2022-04-12 23:07:13 +00:00
plain_text_source ld_user_message_source;
textview_curses ld_user_message_view;
std::chrono::time_point<std::chrono::steady_clock>
ld_user_message_expiration;
textview_curses ld_spectro_details_view;
plain_text_source ld_spectro_no_details_source;
2022-03-16 22:38:08 +00:00
view_stack<textview_curses> ld_view_stack;
textview_curses* ld_last_view;
textview_curses ld_views[LNV__MAX];
vis_line_t ld_search_start_line;
readline_curses* ld_rl_view;
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
logfile_sub_source ld_log_source;
hist_source2 ld_hist_source2;
int ld_zoom_level;
std::unique_ptr<spectrogram_source> ld_spectro_source;
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
textfile_sub_source ld_text_source;
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
std::map<textview_curses*, int> ld_last_user_mark;
std::map<textview_curses*, int> ld_select_start;
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
db_label_source ld_db_row_source;
db_overlay_source ld_db_overlay;
std::vector<std::string> ld_db_key_names;
2012-07-13 16:26:47 +00:00
2022-03-16 22:38:08 +00:00
vis_line_t ld_last_pretty_print_top;
2022-03-16 22:38:08 +00:00
std::unique_ptr<log_vtab_manager> ld_vtab_manager;
2022-09-22 04:34:04 +00:00
auto_sqlite3 ld_db;
std::unordered_map<std::string, std::string> ld_table_ddl;
2022-03-16 22:38:08 +00:00
std::list<pid_t> ld_children;
2015-04-02 13:49:16 +00:00
input_state_tracker ld_input_state;
input_dispatcher ld_input_dispatcher;
exec_context ld_exec_context;
2016-11-23 14:41:22 +00:00
int ld_fifo_counter;
struct key_repeat_history ld_key_repeat_history;
bool ld_initial_build{false};
bool ld_show_help_view{false};
lnav::func::scoped_cb ld_status_refresher;
ghc::filesystem::file_time_type ld_last_dot_lnav_time;
2012-07-13 16:26:47 +00:00
};
struct static_service {};
2022-03-16 22:38:08 +00:00
class main_looper
: public isc::service<main_looper>
, public static_service {
public:
};
extern struct lnav_data_t lnav_data;
2012-07-13 16:26:47 +00:00
extern readline_context::command_map_t lnav_commands;
extern const int ZOOM_LEVELS[];
2016-05-04 04:01:39 +00:00
extern const ssize_t ZOOM_COUNT;
2022-03-16 22:38:08 +00:00
#define HELP_MSG_1(x, msg) "Press '" ANSI_BOLD(#x) "' " msg
2014-02-24 23:50:42 +00:00
2022-03-16 22:38:08 +00:00
#define HELP_MSG_2(x, y, msg) "Press " ANSI_BOLD(#x) "/" ANSI_BOLD(#y) " " msg
2014-02-24 23:50:42 +00:00
2022-03-16 22:38:08 +00:00
bool setup_logline_table(exec_context& ec);
void wait_for_children();
2012-07-13 16:26:47 +00:00
#endif