Skip to content

Commit

Permalink
Merge pull request #44 from ynqa/v0.2.3/main
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
ynqa authored May 26, 2024
2 parents a141a07 + 3ccf277 commit e1a4d68
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jnv"
version = "0.2.2"
version = "0.2.3"
authors = ["ynqa <[email protected]>"]
edition = "2021"
description = "JSON navigator and interactive filter leveraging jq"
Expand All @@ -13,7 +13,7 @@ anyhow = "1.0.82"
clap = { version = "4.5.4", features = ["derive"] }
gag = "1.0.0"
j9 = "0.1.3"
promkit = "0.4.0"
promkit = "0.4.3"
radix_trie = "0.2.1"

# The profile that 'cargo dist' will build with
Expand Down
45 changes: 43 additions & 2 deletions src/jnv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,37 @@ fn run_jq(query: &str, json_stream: &[serde_json::Value]) -> anyhow::Result<Vec<
Ok(jq_ret)
}

pub struct JsonTheme {
/// Style for {}.
pub curly_brackets_style: ContentStyle,
/// Style for [].
pub square_brackets_style: ContentStyle,
/// Style for "key".
pub key_style: ContentStyle,
/// Style for string values.
pub string_value_style: ContentStyle,
/// Style for number values.
pub number_value_style: ContentStyle,
/// Style for boolean values.
pub boolean_value_style: ContentStyle,
/// Style for null values.
pub null_value_style: ContentStyle,

/// Attribute for the selected line.
pub active_item_attribute: Attribute,
/// Attribute for unselected lines.
pub inactive_item_attribute: Attribute,

/// Number of lines available for rendering.
pub lines: Option<usize>,

/// The number of spaces used for indentation in the rendered JSON structure.
/// This value multiplies with the indentation level of a JSON element to determine
/// the total indentation space. For example, an `indent` value of 4 means each
/// indentation level will be 4 spaces wide.
pub indent: usize,
}

pub struct Jnv {
input_stream: Vec<serde_json::Value>,

Expand Down Expand Up @@ -112,7 +143,7 @@ impl Jnv {
filter_editor: text_editor::State,
hint_message: text::State,
suggestions: listbox::State,
json_theme: json::Theme,
json_theme: JsonTheme,
json_expand_depth: Option<usize>,
json_limit_length: Option<usize>,
no_hint: bool,
Expand Down Expand Up @@ -163,7 +194,17 @@ impl Jnv {
suggestions,
json: json::State {
stream: JsonStream::new(input_stream.clone(), json_expand_depth),
theme: json_theme,
curly_brackets_style: json_theme.curly_brackets_style,
square_brackets_style: json_theme.square_brackets_style,
key_style: json_theme.key_style,
string_value_style: json_theme.string_value_style,
number_value_style: json_theme.number_value_style,
boolean_value_style: json_theme.boolean_value_style,
null_value_style: json_theme.null_value_style,
active_item_attribute: json_theme.active_item_attribute,
inactive_item_attribute: json_theme.inactive_item_attribute,
lines: json_theme.lines,
indent: json_theme.indent,
},
trie,
suggest,
Expand Down
6 changes: 3 additions & 3 deletions src/jnv/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn default(event: &Event, jnv: &mut crate::jnv::Jnv) -> anyhow::Result<Promp
jnv.suggestions.listbox = Listbox::from_iter(candidates);
filter_editor
.texteditor
.replace(&jnv.suggestions.listbox.get());
.replace(&jnv.suggestions.listbox.get().to_string());

jnv.keymap.borrow_mut().switch("on_suggest");
}
Expand Down Expand Up @@ -245,7 +245,7 @@ pub fn on_suggest(event: &Event, jnv: &mut crate::jnv::Jnv) -> anyhow::Result<Pr
jnv.suggestions.listbox.forward();
query_editor_after_mut
.texteditor
.replace(&jnv.suggestions.listbox.get());
.replace(&jnv.suggestions.listbox.get().to_string());
}

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

_ => {
Expand Down
18 changes: 10 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use clap::Parser;

use promkit::{
crossterm::style::{Attribute, Attributes, Color},
json, listbox,
listbox,
style::StyleBuilder,
text, text_editor,
};

mod jnv;
use jnv::Jnv;
use jnv::{Jnv, JsonTheme};
mod trie;

/// JSON navigator and interactive filter leveraging jq
Expand Down Expand Up @@ -187,15 +187,17 @@ fn main() -> Result<()> {
let suggestions = listbox::State {
listbox: listbox::Listbox::from_iter(Vec::<String>::new()),
cursor: String::from("❯ "),
active_item_style: StyleBuilder::new()
.fgc(Color::Grey)
.bgc(Color::Yellow)
.build(),
inactive_item_style: StyleBuilder::new().fgc(Color::Grey).build(),
active_item_style: Some(
StyleBuilder::new()
.fgc(Color::Grey)
.bgc(Color::Yellow)
.build(),
),
inactive_item_style: Some(StyleBuilder::new().fgc(Color::Grey).build()),
lines: Some(args.suggestion_list_length),
};

let json_theme = json::Theme {
let json_theme = JsonTheme {
curly_brackets_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Bold))
.build(),
Expand Down

0 comments on commit e1a4d68

Please sign in to comment.