Skip to content

Commit

Permalink
chg: Dim at un-selected lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 25, 2024
1 parent 30edd6c commit a99719d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
10 changes: 2 additions & 8 deletions src/core/json/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::any::Any;
use crate::{
crossterm::{
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers},
style::{Color, ContentStyle},
style::{Attribute, Attributes, ContentStyle},
},
grapheme::{trim, Graphemes},
pane::Pane,
Expand Down Expand Up @@ -34,11 +34,6 @@ pub struct Renderer {
/// Style for boolean values.
pub boolean_value_style: ContentStyle,

/// Style for the selected line.
pub active_item_background_color: Color,
/// Style for un-selected lines.
pub inactive_item_background_color: Color,

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

Expand Down Expand Up @@ -178,10 +173,9 @@ impl Renderable for Renderer {
.map(|(i, kind)| {
if i == self.json.position() {
Graphemes::from_iter([Graphemes::from(" ".repeat(indent(kind))), syntax(kind)])
.stylize_all_backgrounds(self.active_item_background_color)
} else {
Graphemes::from_iter([Graphemes::from(" ".repeat(indent(kind))), syntax(kind)])
.stylize_all_backgrounds(self.inactive_item_background_color)
.stylize_all_attributes(Attributes::from(Attribute::Dim))
}
})
.collect::<Vec<Graphemes>>();
Expand Down
8 changes: 8 additions & 0 deletions src/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use std::{
ops::{Deref, DerefMut},
};

use crossterm::style::Attributes;
use unicode_width::UnicodeWidthChar;

use crate::crossterm::style::{Color, ContentStyle};
Expand Down Expand Up @@ -122,6 +123,13 @@ impl Graphemes {
self
}

pub fn stylize_all_attributes(mut self, attrs: Attributes) -> Self {
for grapheme in &mut self.0 {
grapheme.style.attributes = attrs;
}
self
}

pub fn styled_display(&self) -> StyledGraphemesDisplay<'_> {
StyledGraphemesDisplay { graphemes: self }
}
Expand Down
14 changes: 0 additions & 14 deletions src/preset/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ impl Json {
string_value_style: Style::new().fgc(Color::DarkGreen).build(),
number_value_style: Style::new().build(),
boolean_value_style: Style::new().build(),
active_item_background_color: Color::DarkYellow,
inactive_item_background_color: Color::Reset,
lines: Default::default(),
indent: 2,
},
Expand All @@ -59,18 +57,6 @@ impl Json {
self
}

/// Sets the background color for active items in the JSON rendering.
pub fn active_item_background_color(mut self, color: Color) -> Self {
self.json_renderer.active_item_background_color = color;
self
}

/// Sets the background color for inactive items in the JSON rendering.
pub fn inactive_item_background_color(mut self, color: Color) -> Self {
self.json_renderer.inactive_item_background_color = color;
self
}

/// Sets the number of lines to be used for rendering the JSON data.
pub fn json_lines(mut self, lines: usize) -> Self {
self.json_renderer.lines = Some(lines);
Expand Down

0 comments on commit a99719d

Please sign in to comment.