Skip to content

Commit

Permalink
[sql] support doing an UPDATE on the lnav_top_view SQL view
Browse files Browse the repository at this point in the history
  • Loading branch information
tstack committed May 15, 2024
1 parent 984e133 commit 54b391e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Bug Fixes:
overlay for log messages.

Maintenance:
* You can now do an `UPDATE` on the `lnav_top_view` SQL view.
This makes it easier to write queries that manipulate the
current view.
* Upgrade to C++17


Expand Down
16 changes: 16 additions & 0 deletions src/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ SELECT *
FROM lnav_views
WHERE name = (SELECT name FROM lnav_view_stack ORDER BY rowid DESC LIMIT 1);

CREATE TRIGGER lnav_top_view_update
INSTEAD OF UPDATE ON lnav_top_view
BEGIN
UPDATE lnav_views
SET top = NEW.top,
left = NEW.left,
top_time = NEW.top_time,
paused = NEW.paused,
search = NEW.search,
filtering = NEW.filtering,
movement = NEW.movement,
selection = NEW.selection,
options = NEW.options
WHERE name = NEW.name;
END;

CREATE VIEW lnav_file_demux_metadata AS
SELECT filepath, jget(content, '/demux_meta') AS metadata
FROM lnav_file_metadata
Expand Down
14 changes: 7 additions & 7 deletions src/keymaps/default-keymap.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
"command": ":reset-session"
},
"x18": {
"command": ";UPDATE lnav_views SET movement = (CASE movement WHEN 'top' THEN 'cursor' ELSE 'top' END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET movement = (CASE movement WHEN 'top' THEN 'cursor' ELSE 'top' END)"
},
"x04": {
"command": ";UPDATE lnav_views SET top = top + (height / 2), selection = (CASE movement WHEN 'top' THEN selection ELSE top + (height / 2) + (selection - top) END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET top = top + (height / 2), selection = (CASE movement WHEN 'top' THEN selection ELSE top + (height / 2) + (selection - top) END)"
},
"x15": {
"command": ";UPDATE lnav_views SET top = max(0, top - (height / 2)), selection = (CASE movement WHEN 'top' THEN selection ELSE max(0, top - (height / 2) + (selection - top)) END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET top = max(0, top - (height / 2)), selection = (CASE movement WHEN 'top' THEN selection ELSE max(0, top - (height / 2) + (selection - top)) END)"
},
"x3d": {
"command": ";UPDATE lnav_views SET paused = 1 - paused"
Expand Down Expand Up @@ -130,17 +130,17 @@
"alt-msg": "${keymap_def_scroll_horiz}"
},
"x54": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.row-time-offset', CASE jget(options, '/row-time-offset', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.row-time-offset', CASE jget(options, '/row-time-offset', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)",
"alt-msg": "${keymap_def_time_offset}"
},
"x70": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.row-details', CASE jget(options, '/row-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.row-details', CASE jget(options, '/row-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)"
},
"x78": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.hidden-fields', CASE jget(options, '/hidden-fields', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.hidden-fields', CASE jget(options, '/hidden-fields', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)"
},
"x17": {
"command": ";UPDATE lnav_views SET options = json_set(options, '$.word-wrap', CASE jget(options, '/word-wrap', 'none') WHEN 'none' THEN 'normal' ELSE 'none' END) WHERE name = (SELECT name FROM lnav_top_view)"
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.word-wrap', CASE jget(options, '/word-wrap', 'none') WHEN 'none' THEN 'normal' ELSE 'none' END)"
},
"x75": {
"command": ":next-mark",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4774,7 +4774,7 @@
"default": {
"x04": {
"id": "",
"command": ";UPDATE lnav_views SET top = top + (height / 2), selection = (CASE movement WHEN 'top' THEN selection ELSE top + (height / 2) + (selection - top) END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET top = top + (height / 2), selection = (CASE movement WHEN 'top' THEN selection ELSE top + (height / 2) + (selection - top) END)",
"alt-msg": ""
},
"x06": {
Expand All @@ -4794,17 +4794,17 @@
},
"x15": {
"id": "",
"command": ";UPDATE lnav_views SET top = max(0, top - (height / 2)), selection = (CASE movement WHEN 'top' THEN selection ELSE max(0, top - (height / 2) + (selection - top)) END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET top = max(0, top - (height / 2)), selection = (CASE movement WHEN 'top' THEN selection ELSE max(0, top - (height / 2) + (selection - top)) END)",
"alt-msg": ""
},
"x17": {
"id": "",
"command": ";UPDATE lnav_views SET options = json_set(options, '$.word-wrap', CASE jget(options, '/word-wrap', 'none') WHEN 'none' THEN 'normal' ELSE 'none' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.word-wrap', CASE jget(options, '/word-wrap', 'none') WHEN 'none' THEN 'normal' ELSE 'none' END)",
"alt-msg": ""
},
"x18": {
"id": "",
"command": ";UPDATE lnav_views SET movement = (CASE movement WHEN 'top' THEN 'cursor' ELSE 'top' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET movement = (CASE movement WHEN 'top' THEN 'cursor' ELSE 'top' END)",
"alt-msg": ""
},
"x21": {
Expand Down Expand Up @@ -4919,7 +4919,7 @@
},
"x54": {
"id": "",
"command": ";UPDATE lnav_views SET options = json_set(options, '$.row-time-offset', CASE jget(options, '/row-time-offset', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.row-time-offset', CASE jget(options, '/row-time-offset', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)",
"alt-msg": "${keymap_def_time_offset}"
},
"x55": {
Expand Down Expand Up @@ -4974,7 +4974,7 @@
},
"x70": {
"id": "",
"command": ";UPDATE lnav_views SET options = json_set(options, '$.row-details', CASE jget(options, '/row-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.row-details', CASE jget(options, '/row-details', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)",
"alt-msg": ""
},
"x71": {
Expand All @@ -4999,7 +4999,7 @@
},
"x78": {
"id": "",
"command": ";UPDATE lnav_views SET options = json_set(options, '$.hidden-fields', CASE jget(options, '/hidden-fields', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END) WHERE name = (SELECT name FROM lnav_top_view)",
"command": ";UPDATE lnav_top_view SET options = json_set(options, '$.hidden-fields', CASE jget(options, '/hidden-fields', 'hide') WHEN 'hide' THEN 'show' ELSE 'hide' END)",
"alt-msg": ""
},
"x7b": {
Expand Down

0 comments on commit 54b391e

Please sign in to comment.