[docs] add some more keymap/theme docs

This commit is contained in:
Timothy Stack 2020-09-13 23:03:23 -07:00
parent 692cf37e1b
commit be106fcb8d
11 changed files with 160 additions and 23 deletions

View File

@ -16,7 +16,17 @@ The configuration for **lnav** is stored in the following JSON files in
* :file:`configs/installed/*.json` -- Contains configuration files installed
using the :code:`-i` flag (e.g. :code:`$ lnav -i /path/to/config.json`).
* :file:`configs/*/*.json` -- Other directories that contain :file:`*.json`
files will be loaded on startup.
files will be loaded on startup. This structure is convenient for installing
**lnav** configurations, like from a git repository.
A valid **lnav** configuration file must contain an object with the
:code:`$schema` property, like so:
.. code-block:: json
{
"$schema": "https://lnav.org/schemas/config-v1.schema.json"
}
.. note::
@ -47,12 +57,97 @@ your liking. The options can be changed using the :code:`:config` command.
Theme Definitions
-----------------
User interface themes are also defined through the JSON configuration files.
User Interface themes are defined in a JSON configuration file. A theme is
made up of the style definitions for different types of text in the UI. A
:ref:`definition<theme_style>` can include the foreground/background colors
and the bold/underline attributes. The style definitions are broken up into
multiple categories for the sake of organization. To make it easier to write
a definition, a theme can define variables that can be referenced as color
values.
Variables
^^^^^^^^^
The :code:`vars` object in a theme definition contains the mapping of variable
names to color values. These variables can be referenced in style definitions
by prefixing them with a dollar-sign (e.g. :code:`$black`). The following
variables can also be defined to control the values of the ANSI colors that
are log messages or plain text:
* black
* red
* green
* yellow
* blue
* magenta
* cyan
* white
Specifying Colors
^^^^^^^^^^^^^^^^^
Colors can be specified using hexadecimal notation by starting with a hash
(e.g. :code:`#aabbcc`) or using a color name as found at
http://jonasjacek.github.io/colors/. If colors are not specified for a style,
the values from the :code:`styles/text` definition.
.. note::
When specifying colors in hexadecimal notation, you do not need to have an
exact match in the XTerm 256 color palette. A best approximation will be
picked based on the `CIEDE2000 <https://en.wikipedia.org/wiki/Color_difference#CIEDE2000>`_
color difference algorithm.
Example
^^^^^^^
The following example sets the black/background color for text to a dark grey
using a variable and sets the foreground to an off-white. This theme is
incomplete, but it works enough to give you an idea of how a theme is defined.
You can copy the code block, save it to a file in
:file:`~/.lnav/configs/installed/` and then activate it by executing
:code:`:config /ui/theme example` in lnav. For a more complete theme
definition, see one of the definitions built into **lnav**, like
`monocai <https://github.com/tstack/lnav/blob/master/src/themes/monocai.json>`_.
.. code-block:: json
{
"$schema": "https://lnav.org/schemas/config-v1.schema.json",
"ui": {
"theme-defs": {
"example1": {
"vars": {
"black": "#2d2a2e"
},
"styles": {
"text": {
"color": "#f6f6f6",
"background-color": "$black"
}
}
}
}
}
}
Reference
^^^^^^^^^
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/theme-defs/patternProperties/([\w\-]+)/properties/vars
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/theme-defs/patternProperties/([\w\-]+)/properties/styles
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/theme-defs/patternProperties/([\w\-]+)/properties/syntax-styles
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/theme-defs/patternProperties/([\w\-]+)/properties/status-styles
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/theme-defs/patternProperties/([\w\-]+)/properties/log-level-styles
.. _theme_style:
.. jsonschema:: ../../src/internals/config-v1.schema.json#/definitions/style
@ -61,6 +156,34 @@ User interface themes are also defined through the JSON configuration files.
Keymap Definitions
------------------
Keymaps in **lnav** map a key sequence to a command to execute.
Keymaps in **lnav** map a key sequence to a command to execute. When a key is
pressed, it is converted into a hex-encoded string that is looked up in the
keymap. The :code:`command` value associated with the entry in the keymap is
then executed. Note that the "command" can be an **lnav**
:ref:`command<commands>`, a :ref:`SQL statement/query<sql-ext>`, or an
**lnav** script. If an :code:`alt-msg` value is included in the entry, the
bottom-right section of the UI will be updated with the help text.
.. note::
Not all functionality is available via commands or SQL at the moment. Also,
some hotkeys are not implemented via keymaps.
Key Sequence Encoding
^^^^^^^^^^^^^^^^^^^^^
Key presses are converted into a hex-encoded string that is used to lookup an
entry in the keymap. Each byte of the keypress value is formatted as an
:code:`x` followed by the hex-encoding in lowercase. For example, the encoding
for the £ key would be :code:`xc2xa3`.
.. note::
Since **lnav** is a terminal application, it can only receive keypresses that
can be represented as characters or escape sequences. For example, it cannot
handle modifier keypresses.
Reference
^^^^^^^^^
.. jsonschema:: ../../src/internals/config-v1.schema.json#/properties/ui/properties/keymap-defs/patternProperties/([\w\-]+)

View File

@ -241,3 +241,5 @@ Query
Customizing
-----------
You can customize the behavior of hotkeys by defining your own keymaps.
Consult the :ref:`Keymaps<keymaps>` configuration section for more information.

View File

@ -4,3 +4,4 @@
How It Works
============
"Magic"

View File

@ -92,10 +92,10 @@ can be used to change the keymap:
The builtin keymaps are:
:de: German
:fr: French
:uk: United Kingdom
:us: United States
:de: `German <https://github.com/tstack/lnav/blob/master/src/keymaps/de-keymap.json>`_
:fr: `French <https://github.com/tstack/lnav/blob/master/src/keymaps/fr-keymap.json>`_
:uk: `United Kingdom <https://github.com/tstack/lnav/blob/master/src/keymaps/uk-keymap.json>`_
:us: `United States <https://github.com/tstack/lnav/blob/master/src/keymaps/us-keymap.json>`_
To create or customize a keymap, consult the :ref:`keymaps` section.
@ -129,4 +129,4 @@ In order for **lnav** to understand your log files, it needs to told how to
parse the log messages using a log format definition. There are many log
formats builtin and **lnav** will automatically determine the best format to
use. In case your log file is not recognized, consult the :ref:`log_formats`
section for information on how to .
section for information on how to create a format.

View File

@ -148,7 +148,7 @@ typedef union {
class string_attr_type {
public:
string_attr_type(const char *name = nullptr)
explicit string_attr_type(const char *name = nullptr) noexcept
: sat_name(name) {
};

View File

@ -238,7 +238,7 @@ bool handle_paging_key(int ch)
if (xterm_mouse::is_available()) {
lnav_data.ld_mouse.set_enabled(!lnav_data.ld_mouse.is_enabled());
lnav_data.ld_rl_view->set_value(
string("info: mouse mode -- ") +
ok_prefix("info: mouse mode -- ") +
(lnav_data.ld_mouse.is_enabled() ?
ANSI_BOLD("enabled") : ANSI_BOLD("disabled")));
}
@ -259,7 +259,7 @@ bool handle_paging_key(int ch)
tc->get_bookmarks()[&textview_curses::BM_USER].clear();
tc->reload_data();
lnav_data.ld_rl_view->set_value("Cleared bookmarks");
lnav_data.ld_rl_view->set_value(ok_prefix("Cleared bookmarks"));
break;
case '>':
@ -625,7 +625,8 @@ bool handle_paging_key(int ch)
start_helper.lh_string_attrs, &logline::L_OPID);
if (!opid_range.is_valid()) {
alerter::singleton().chime();
lnav_data.ld_rl_view->set_value("Log message does not contain an opid");
lnav_data.ld_rl_view->set_value(
err_prefix("Log message does not contain an opid"));
} else {
unsigned int opid_hash = start_line.get_opid();
logline_helper next_helper(*lss);
@ -671,7 +672,7 @@ bool handle_paging_key(int ch)
string opid_str = start_helper.to_string(opid_range);
lnav_data.ld_rl_view->set_value(
"No more messages found with opid: " + opid_str);
err_prefix("No more messages found with opid: " + opid_str));
alerter::singleton().chime();
}
}
@ -868,7 +869,8 @@ bool handle_paging_key(int ch)
case 't':
if (lnav_data.ld_text_source.current_file() == nullptr) {
alerter::singleton().chime();
lnav_data.ld_rl_view->set_value("No text files loaded");
lnav_data.ld_rl_view->set_value(
err_prefix("No text files loaded"));
}
else if (toggle_view(&lnav_data.ld_views[LNV_TEXT])) {
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(

View File

@ -780,7 +780,16 @@ std::string ok_prefix(std::string msg)
return std::string(ANSI_COLOR(COLOR_GREEN) "\u2714" ANSI_NORM " ") + msg;
}
std::string err_prefix(const std::string msg)
{
if (msg.empty()) {
return msg;
}
return std::string(ANSI_COLOR(COLOR_RED) "\u2718" ANSI_NORM " ") + msg;
}
Result<std::string, std::string> err_to_ok(const std::string msg)
{
return Ok(std::string(ANSI_COLOR(COLOR_RED) "\u2718" ANSI_NORM " ") + msg);
return Ok(err_prefix(msg));
}

View File

@ -530,6 +530,7 @@ final_action<A> finally(A act) // deduce action type
}
std::string ok_prefix(std::string msg);
std::string err_prefix(std::string msg);
Result<std::string, std::string> err_to_ok(std::string msg);
#endif

View File

@ -216,7 +216,6 @@ void log_format::check_for_new_year(std::vector<logline> &dst, exttm etm,
time_t diff = dst.back().get_time() - log_tv.tv_sec;
int off_year = 0, off_month = 0, off_day = 0, off_hour = 0;
std::vector<logline>::iterator iter;
bool do_change = true;
if (diff <= 0) {
@ -239,8 +238,8 @@ void log_format::check_for_new_year(std::vector<logline> &dst, exttm etm,
}
log_debug("%d:detected time rollover; offsets=%d %d %d %d", dst.size(),
off_year, off_month, off_day, off_hour);
for (iter = dst.begin(); iter != dst.end(); iter++) {
time_t ot = iter->get_time();
for (auto &ll : dst) {
time_t ot = ll.get_time();
struct tm otm;
gmtime_r(&ot, &otm);
@ -252,7 +251,7 @@ void log_format::check_for_new_year(std::vector<logline> &dst, exttm etm,
if (new_time == -1) {
continue;
}
iter->set_time(new_time);
ll.set_time(new_time);
}
}

View File

@ -537,7 +537,7 @@ void rl_callback(void *dummy, readline_curses *rc)
auto msg = result.unwrap();
if (!msg.empty()) {
prompt = "SQL Result: " + msg;
prompt = ok_prefix("SQL Result: " + msg);
if (dls.dls_rows.size() > 1) {
ensure_view(&lnav_data.ld_views[LNV_DB]);
}

View File

@ -15,15 +15,15 @@
},
"styles": {
"identifier": {
"background-color": "#2d2a2e"
"background-color": "$black"
},
"text": {
"color": "#f6f6f6",
"background-color": "#2d2a2e"
"background-color": "$black"
},
"alt-text": {
"color": "#f6f6f6",
"background-color": "#2d2a2e",
"background-color": "$black",
"bold": true
},
"ok": {