Skip to content

Commit

Permalink
create json theme out of jnv constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Apr 21, 2024
1 parent 5a878a7 commit 8561eee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
20 changes: 2 additions & 18 deletions src/jnv.rs
Expand Up @@ -105,9 +105,9 @@ impl Jnv {
filter_editor: text_editor::State,
hint_message: text::State,
suggestions: listbox::State,
json_theme: json::Theme,
json_expand_depth: Option<usize>,
no_hint: bool,
indent: usize,
) -> Result<Prompt<Self>> {
let input_stream = deserialize_json(&input)?;

Expand Down Expand Up @@ -155,23 +155,7 @@ impl Jnv {
suggestions,
json: json::State {
stream: JsonStream::new(input_stream.clone(), json_expand_depth),
theme: json::Theme {
curly_brackets_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Bold))
.build(),
square_brackets_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Bold))
.build(),
key_style: StyleBuilder::new().fgc(Color::Cyan).build(),
string_value_style: StyleBuilder::new().fgc(Color::Green).build(),
number_value_style: StyleBuilder::new().build(),
boolean_value_style: StyleBuilder::new().build(),
null_value_style: StyleBuilder::new().fgc(Color::Grey).build(),
active_item_attribute: Attribute::Bold,
inactive_item_attribute: Attribute::Dim,
lines: Default::default(),
indent,
},
theme: json_theme,
},
trie,
suggest,
Expand Down
22 changes: 20 additions & 2 deletions src/main.rs
Expand Up @@ -10,7 +10,7 @@ use clap::Parser;

use promkit::{
crossterm::style::{Attribute, Attributes, Color},
listbox,
json, listbox,
style::StyleBuilder,
text, text_editor,
};
Expand Down Expand Up @@ -183,14 +183,32 @@ fn main() -> Result<()> {
lines: Some(args.suggestion_list_length),
};

let json_theme = json::Theme {
curly_brackets_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Bold))
.build(),
square_brackets_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Bold))
.build(),
key_style: StyleBuilder::new().fgc(Color::Cyan).build(),
string_value_style: StyleBuilder::new().fgc(Color::Green).build(),
number_value_style: StyleBuilder::new().build(),
boolean_value_style: StyleBuilder::new().build(),
null_value_style: StyleBuilder::new().fgc(Color::Grey).build(),
active_item_attribute: Attribute::Bold,
inactive_item_attribute: Attribute::Dim,
lines: Default::default(),
indent: args.indent,
};

let mut prompt = Jnv::try_new(
input,
filter_editor,
hint_message,
suggestions,
json_theme,
args.json_expand_depth,
args.no_hint,
args.indent,
)?;
let _ = prompt.run()?;
Ok(())
Expand Down

0 comments on commit 8561eee

Please sign in to comment.