Skip to content

Commit e1a4d68

Browse files
authored
Merge pull request #44 from ynqa/v0.2.3/main
v0.2.3
2 parents a141a07 + 3ccf277 commit e1a4d68

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jnv"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
authors = ["ynqa <[email protected]>"]
55
edition = "2021"
66
description = "JSON navigator and interactive filter leveraging jq"
@@ -13,7 +13,7 @@ anyhow = "1.0.82"
1313
clap = { version = "4.5.4", features = ["derive"] }
1414
gag = "1.0.0"
1515
j9 = "0.1.3"
16-
promkit = "0.4.0"
16+
promkit = "0.4.3"
1717
radix_trie = "0.2.1"
1818

1919
# The profile that 'cargo dist' will build with

src/jnv.rs

+43-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ fn run_jq(query: &str, json_stream: &[serde_json::Value]) -> anyhow::Result<Vec<
8383
Ok(jq_ret)
8484
}
8585

86+
pub struct JsonTheme {
87+
/// Style for {}.
88+
pub curly_brackets_style: ContentStyle,
89+
/// Style for [].
90+
pub square_brackets_style: ContentStyle,
91+
/// Style for "key".
92+
pub key_style: ContentStyle,
93+
/// Style for string values.
94+
pub string_value_style: ContentStyle,
95+
/// Style for number values.
96+
pub number_value_style: ContentStyle,
97+
/// Style for boolean values.
98+
pub boolean_value_style: ContentStyle,
99+
/// Style for null values.
100+
pub null_value_style: ContentStyle,
101+
102+
/// Attribute for the selected line.
103+
pub active_item_attribute: Attribute,
104+
/// Attribute for unselected lines.
105+
pub inactive_item_attribute: Attribute,
106+
107+
/// Number of lines available for rendering.
108+
pub lines: Option<usize>,
109+
110+
/// The number of spaces used for indentation in the rendered JSON structure.
111+
/// This value multiplies with the indentation level of a JSON element to determine
112+
/// the total indentation space. For example, an `indent` value of 4 means each
113+
/// indentation level will be 4 spaces wide.
114+
pub indent: usize,
115+
}
116+
86117
pub struct Jnv {
87118
input_stream: Vec<serde_json::Value>,
88119

@@ -112,7 +143,7 @@ impl Jnv {
112143
filter_editor: text_editor::State,
113144
hint_message: text::State,
114145
suggestions: listbox::State,
115-
json_theme: json::Theme,
146+
json_theme: JsonTheme,
116147
json_expand_depth: Option<usize>,
117148
json_limit_length: Option<usize>,
118149
no_hint: bool,
@@ -163,7 +194,17 @@ impl Jnv {
163194
suggestions,
164195
json: json::State {
165196
stream: JsonStream::new(input_stream.clone(), json_expand_depth),
166-
theme: json_theme,
197+
curly_brackets_style: json_theme.curly_brackets_style,
198+
square_brackets_style: json_theme.square_brackets_style,
199+
key_style: json_theme.key_style,
200+
string_value_style: json_theme.string_value_style,
201+
number_value_style: json_theme.number_value_style,
202+
boolean_value_style: json_theme.boolean_value_style,
203+
null_value_style: json_theme.null_value_style,
204+
active_item_attribute: json_theme.active_item_attribute,
205+
inactive_item_attribute: json_theme.inactive_item_attribute,
206+
lines: json_theme.lines,
207+
indent: json_theme.indent,
167208
},
168209
trie,
169210
suggest,

src/jnv/keymap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn default(event: &Event, jnv: &mut crate::jnv::Jnv) -> anyhow::Result<Promp
2323
jnv.suggestions.listbox = Listbox::from_iter(candidates);
2424
filter_editor
2525
.texteditor
26-
.replace(&jnv.suggestions.listbox.get());
26+
.replace(&jnv.suggestions.listbox.get().to_string());
2727

2828
jnv.keymap.borrow_mut().switch("on_suggest");
2929
}
@@ -245,7 +245,7 @@ pub fn on_suggest(event: &Event, jnv: &mut crate::jnv::Jnv) -> anyhow::Result<Pr
245245
jnv.suggestions.listbox.forward();
246246
query_editor_after_mut
247247
.texteditor
248-
.replace(&jnv.suggestions.listbox.get());
248+
.replace(&jnv.suggestions.listbox.get().to_string());
249249
}
250250

251251
Event::Key(KeyEvent {
@@ -257,7 +257,7 @@ pub fn on_suggest(event: &Event, jnv: &mut crate::jnv::Jnv) -> anyhow::Result<Pr
257257
jnv.suggestions.listbox.backward();
258258
query_editor_after_mut
259259
.texteditor
260-
.replace(&jnv.suggestions.listbox.get());
260+
.replace(&jnv.suggestions.listbox.get().to_string());
261261
}
262262

263263
_ => {

src/main.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use clap::Parser;
1010

1111
use promkit::{
1212
crossterm::style::{Attribute, Attributes, Color},
13-
json, listbox,
13+
listbox,
1414
style::StyleBuilder,
1515
text, text_editor,
1616
};
1717

1818
mod jnv;
19-
use jnv::Jnv;
19+
use jnv::{Jnv, JsonTheme};
2020
mod trie;
2121

2222
/// JSON navigator and interactive filter leveraging jq
@@ -187,15 +187,17 @@ fn main() -> Result<()> {
187187
let suggestions = listbox::State {
188188
listbox: listbox::Listbox::from_iter(Vec::<String>::new()),
189189
cursor: String::from("❯ "),
190-
active_item_style: StyleBuilder::new()
191-
.fgc(Color::Grey)
192-
.bgc(Color::Yellow)
193-
.build(),
194-
inactive_item_style: StyleBuilder::new().fgc(Color::Grey).build(),
190+
active_item_style: Some(
191+
StyleBuilder::new()
192+
.fgc(Color::Grey)
193+
.bgc(Color::Yellow)
194+
.build(),
195+
),
196+
inactive_item_style: Some(StyleBuilder::new().fgc(Color::Grey).build()),
195197
lines: Some(args.suggestion_list_length),
196198
};
197199

198-
let json_theme = json::Theme {
200+
let json_theme = JsonTheme {
199201
curly_brackets_style: StyleBuilder::new()
200202
.attrs(Attributes::from(Attribute::Bold))
201203
.build(),

0 commit comments

Comments
 (0)