lnav/src/lnav.hh

351 lines
11 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;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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
#include "config.h"
#include <signal.h>
#include <sys/time.h>
2012-07-13 16:26:47 +00:00
#include <map>
#include <set>
#include <list>
#include <stack>
#include <memory>
#include "logfile.hh"
#include "hist_source.hh"
#include "statusview_curses.hh"
#include "listview_curses.hh"
#include "top_status_source.hh"
#include "bottom_status_source.hh"
#include "doc_status_source.hh"
2012-07-13 16:26:47 +00:00
#include "grep_highlighter.hh"
#include "db_sub_source.hh"
#include "textfile_sub_source.hh"
#include "log_vtab_impl.hh"
2013-05-31 15:01:31 +00:00
#include "readline_curses.hh"
#include "xterm_mouse.hh"
#include "piper_proc.hh"
#include "term_extra.hh"
#include "curl_looper.hh"
2015-09-14 15:56:42 +00:00
#include "relative_time.hh"
2015-12-29 04:30:04 +00:00
#include "log_format_loader.hh"
#include "spectro_source.hh"
#include "command_executor.hh"
#include "plain_text_source.hh"
#include "filter_sub_source.hh"
#include "filter_status_source.hh"
#include "preview_status_source.hh"
2012-07-13 16:26:47 +00:00
/** The command modes that are available while viewing a file. */
typedef enum {
LNM_PAGING,
LNM_FILTER,
2012-07-13 16:26:47 +00:00
LNM_COMMAND,
LNM_SEARCH,
LNM_CAPTURE,
LNM_SQL,
LNM_EXEC,
2012-07-13 16:26:47 +00:00
} ln_mode_t;
enum {
LNB_SYSLOG,
LNB__MAX,
LNB_TIMESTAMP,
LNB_HELP,
LNB_HEADLESS,
LNB_QUIET,
LNB_ROTATED,
LNB_CHECK_CONFIG,
LNB_INSTALL,
LNB_UPDATE_FORMATS,
LNB_VERBOSE,
LNB_SECURE_MODE,
2012-07-13 16:26:47 +00:00
};
/** Flags set on the lnav command-line. */
typedef enum {
2013-05-28 04:35:00 +00:00
LNF_SYSLOG = (1L << LNB_SYSLOG),
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +00:00
LNF_ROTATED = (1L << LNB_ROTATED),
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +00:00
LNF_TIMESTAMP = (1L << LNB_TIMESTAMP),
LNF_HELP = (1L << LNB_HELP),
LNF_HEADLESS = (1L << LNB_HEADLESS),
LNF_QUIET = (1L << LNB_QUIET),
LNF_CHECK_CONFIG = (1L << LNB_CHECK_CONFIG),
LNF_INSTALL = (1L << LNB_INSTALL),
LNF_UPDATE_FORMATS = (1L << LNB_UPDATE_FORMATS),
LNF_VERBOSE = (1L << LNB_VERBOSE),
LNF_SECURE_MODE = (1L << LNB_SECURE_MODE),
LNF__ALL = (LNF_SYSLOG|LNF_HELP),
2012-07-13 16:26:47 +00:00
} lnav_flags_t;
/** The different views available. */
typedef enum {
LNV_LOG,
LNV_TEXT,
LNV_HELP,
LNV_HISTOGRAM,
LNV_DB,
LNV_SCHEMA,
LNV_PRETTY,
LNV_SPECTRO,
2012-07-13 16:26:47 +00:00
LNV__MAX
} lnav_view_t;
extern const char *lnav_view_strings[LNV__MAX + 1];
2013-05-31 15:01:31 +00:00
extern const char *lnav_zoom_strings[];
2012-07-13 16:26:47 +00:00
/** The status bars. */
typedef enum {
LNS_TOP,
LNS_BOTTOM,
LNS_FILTER,
LNS_DOC,
LNS_PREVIEW,
2012-07-13 16:26:47 +00:00
LNS__MAX
} lnav_status_t;
void sqlite_close_wrapper(void *mem);
2013-06-16 01:07:50 +00:00
typedef std::pair<int, int> ppid_time_pair_t;
2013-06-02 21:20:15 +00:00
typedef std::pair<ppid_time_pair_t, std::string> session_pair_t;
2015-04-02 13:49:16 +00:00
class input_state_tracker : public log_state_dumper {
public:
input_state_tracker() : ist_index(0) {
memset(this->ist_recent_key_presses, 0, sizeof(this->ist_recent_key_presses));
};
void log_state() {
log_info("recent_key_presses: index=%d", this->ist_index);
for (int lpc = 0; lpc < COUNT; lpc++) {
log_msg_extra(" 0x%x (%c)", this->ist_recent_key_presses[lpc],
this->ist_recent_key_presses[lpc]);
}
log_msg_extra_complete();
};
void push_back(int ch) {
this->ist_recent_key_presses[this->ist_index % COUNT] = ch;
this->ist_index = (this->ist_index + 1) % COUNT;
};
private:
static const int COUNT = 10;
int ist_recent_key_presses[COUNT];
size_t ist_index;
};
struct key_repeat_history {
key_repeat_history()
: krh_key(0),
krh_count(0) {
this->krh_last_press_time.tv_sec = 0;
this->krh_last_press_time.tv_usec = 0;
}
int krh_key;
int krh_count;
vis_line_t krh_start_line;
struct timeval krh_last_press_time;
void update(int ch, vis_line_t top) {
struct timeval now, diff;
gettimeofday(&now, NULL);
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;
}
};
};
2012-07-13 16:26:47 +00:00
struct _lnav_data {
2013-06-16 01:07:50 +00:00
std::string ld_session_id;
time_t ld_session_time;
time_t ld_session_load_time;
2013-06-16 01:07:50 +00:00
time_t ld_session_save_time;
std::list<session_pair_t> ld_session_file_names;
int ld_session_file_index;
2013-05-28 04:35:00 +00:00
const char * ld_program_name;
const char * ld_debug_log_name;
2012-07-13 16:26:47 +00:00
std::list<std::string> ld_commands;
bool ld_cmd_init_done;
std::vector<std::string> ld_config_paths;
std::map<std::string, logfile_open_options> ld_file_names;
std::vector<std::shared_ptr<logfile>> ld_files;
2013-05-28 04:35:00 +00:00
std::list<std::string> ld_other_files;
2014-04-20 21:58:19 +00:00
std::set<std::string> ld_closed_files;
2013-09-14 19:30:57 +00:00
std::list<std::pair<std::string, int> > ld_files_to_front;
2015-07-12 16:57:02 +00:00
std::string ld_pt_search;
time_t ld_pt_min_time;
time_t ld_pt_max_time;
bool ld_stdout_used;
2013-05-28 04:35:00 +00:00
sig_atomic_t ld_looping;
sig_atomic_t ld_winched;
sig_atomic_t ld_child_terminated;
2013-05-28 04:35:00 +00:00
unsigned long ld_flags;
WINDOW * ld_window;
ln_mode_t ld_mode;
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +00:00
statusview_curses ld_status[LNS__MAX];
top_status_source ld_top_source;
bottom_status_source ld_bottom_source;
filter_status_source ld_filter_status_source;
doc_status_source ld_doc_status_source;
preview_status_source ld_preview_status_source;
bool ld_preview_hidden;
2013-05-28 04:35:00 +00:00
listview_curses::action::broadcaster ld_scroll_broadcaster;
listview_curses::action::broadcaster ld_view_stack_broadcaster;
2012-07-13 16:26:47 +00:00
plain_text_source ld_help_source;
plain_text_source ld_doc_source;
textview_curses ld_doc_view;
filter_sub_source ld_filter_source;
textview_curses ld_filter_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;
view_stack<textview_curses> ld_view_stack;
textview_curses *ld_last_view;
2013-05-28 04:35:00 +00:00
textview_curses ld_views[LNV__MAX];
std::shared_ptr<grep_proc<vis_line_t>> ld_meta_search;
2013-05-28 04:35:00 +00:00
vis_line_t ld_search_start_line;
readline_curses * ld_rl_view;
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +00:00
logfile_sub_source ld_log_source;
2015-12-09 06:46:10 +00:00
hist_source2 ld_hist_source2;
int ld_zoom_level;
spectrogram_source ld_spectro_source;
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +00:00
textfile_sub_source ld_text_source;
2012-07-13 16:26:47 +00:00
2013-05-28 04:35:00 +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
db_label_source ld_db_row_source;
2013-05-28 04:35:00 +00:00
db_overlay_source ld_db_overlay;
std::vector<std::string> ld_db_key_names;
2012-07-13 16:26:47 +00:00
2013-07-24 14:42:16 +00:00
std::string ld_previous_search;
2012-07-13 16:26:47 +00:00
vis_line_t ld_last_pretty_print_top;
2013-05-28 04:35:00 +00:00
log_vtab_manager * ld_vtab_manager;
auto_mem<sqlite3, sqlite_close_wrapper> ld_db;
std::unordered_map<std::string, std::string> ld_table_ddl;
std::list<pid_t> ld_children;
2016-12-10 15:21:24 +00:00
std::list<std::shared_ptr<piper_proc>> ld_pipers;
xterm_mouse ld_mouse;
term_extra ld_term_extra;
2015-04-02 13:49:16 +00:00
input_state_tracker ld_input_state;
curl_looper ld_curl_looper;
2015-09-14 15:56:42 +00:00
relative_time ld_last_relative_time;
2015-12-29 04:30:04 +00:00
std::map<std::string, std::vector<script_metadata> > ld_scripts;
2016-11-23 14:41:22 +00:00
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;
2012-07-13 16:26:47 +00:00
};
extern struct _lnav_data lnav_data;
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;
2014-02-24 23:50:42 +00:00
#define HELP_MSG_1(x, msg) \
"Press '" ANSI_BOLD(#x) "' " msg
#define HELP_MSG_2(x, y, msg) \
"Press " ANSI_BOLD(#x) "/" ANSI_BOLD(#y) " " msg
void rebuild_hist();
void rebuild_indexes();
void execute_examples();
2012-07-13 16:26:47 +00:00
bool ensure_view(textview_curses *expected_tc);
bool toggle_view(textview_curses *toggle_tc);
void layout_views();
2013-06-02 21:20:15 +00:00
2018-08-12 15:37:16 +00:00
bool setup_logline_table(exec_context &ec);
2013-06-06 02:34:48 +00:00
bool rescan_files(bool required = false);
void wait_for_children();
vis_line_t next_cluster(
vis_line_t(bookmark_vector<vis_line_t>::*f) (vis_line_t) const,
bookmark_type_t *bt,
vis_line_t top);
bool moveto_cluster(vis_line_t(bookmark_vector<vis_line_t>::*f) (vis_line_t) const,
bookmark_type_t *bt,
vis_line_t top);
void previous_cluster(bookmark_type_t *bt, textview_curses *tc);
vis_line_t search_forward_from(textview_curses *tc);
2015-03-29 21:50:34 +00:00
2012-07-13 16:26:47 +00:00
#endif