Merge pull request #44 from ynqa/v0.2.3/main

v0.2.3
This commit is contained in:
ynqa
2024-05-26 18:00:37 +09:00
committed by GitHub
5 changed files with 61 additions and 18 deletions
Generated
+3 -3
View File
@@ -350,7 +350,7 @@ dependencies = [
[[package]]
name = "jnv"
version = "0.2.2"
version = "0.2.3"
dependencies = [
"anyhow",
"clap",
@@ -503,9 +503,9 @@ dependencies = [
[[package]]
name = "promkit"
version = "0.4.0"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25c21f295a5492afa96e0635c1c8d9f0bcb1d485c5494f40a150a3e11cd026a4"
checksum = "e56210f382d72931a48f2e14013b7543cb4a2e524a70cf8924cf81ef8fa4f338"
dependencies = [
"anyhow",
"crossterm",
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "jnv"
version = "0.2.2"
version = "0.2.3"
authors = ["ynqa <un.pensiero.vano@gmail.com>"]
edition = "2021"
description = "JSON navigator and interactive filter leveraging jq"
@@ -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
+43 -2
View File
@@ -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>,
@@ -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,
@@ -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,
+3 -3
View File
@@ -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");
}
@@ -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 {
@@ -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());
}
_ => {
+10 -8
View File
@@ -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
@@ -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(),