Add support to view full log in json-navigator

This commit is contained in:
Jeremy Dormitzer 2020-06-03 17:55:57 -04:00
parent 9f80c68aa6
commit 720c84b4c5

View File

@ -4,7 +4,9 @@
;; Author: Jeremy Dormitzer <jdormit@Jeremys-MBP>
;; Version: 0.1.0
;; Package-Requires ((dash "2.17.0") (s "1.12.0"))
;; Package-Requires ((dash "2.17.0")
;; (s "1.12.0")
;; (json-navigator "0.1.1"))
;; Keywords: data
;; This program is free software; you can redistribute it and/or modify
@ -30,6 +32,7 @@
(require 'cl-lib)
(require 's)
(require 'dash)
(require 'json-navigator)
(defvar structlog-fields nil
"Currently selected structlog fields")
@ -97,13 +100,17 @@
(defun structlog--parse-json (raw)
"Parses the string `raw' as JSON and returns an alist"
(if (fboundp 'json-parse-string)
(json-parse-string raw
:object-type 'alist
:null-object nil
:false-object nil)
(json-parse-string raw :object-type 'alist)
(require 'json)
(json-read-from-string raw)))
(defun structlog--serialize-json (alist)
"Serializes the `alist' to a JSON string"
(if (fboundp 'json-serialize)
(json-serialize alist)
(require 'json)
(json-encode alist)))
(defun structlog--get-query-fields (query)
"Returns the fields selected by `query'"
(plist-get query :select))
@ -183,11 +190,20 @@
(new-query (read-string "Query: " query-str)))
(structlog-query new-query)))
(defun structlog-view-log-at-point ()
"Opens the log at point in a json-navigator buffer"
(interactive)
(let* ((log (tabulated-list-get-id))
(json (structlog--serialize-json log)))
(json-navigator-display-tree
(json-navigator--read-string json))))
(defvar structlog-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map tabulated-list-mode-map)
(define-key map "m" #'structlog-query)
(define-key map "M" #'structlog-edit-query)
(define-key map (kbd "RET") #'structlog-view-log-at-point)
map)
"Local keymap for `structlog-mode' buffers")
@ -195,6 +211,7 @@
(evil-define-key 'normal structlog-mode-map
"m" #'structlog-query
"M" #'structlog-edit-query
(kbd "RET") #'structlog-view-log-at-point
"S" #'tabulated-list-sort
"{" #'tabulated-list-narrow-current-column
"}" #'tabulated-list-widen-current-column))