Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 52 additions & 34 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
Expand Up @@ -34,8 +34,8 @@ jaq-json = { version = "1.1.3", features = ["serde_json"] }
jaq-std = "2.1.2"

[dependencies.promkit-widgets]
version = "0.5.0"
features = ["jsonstream", "listbox", "serde", "spinner", "status", "texteditor"]
version = "0.10.0"
features = ["json", "listbox", "serde", "spinner", "text", "texteditor"]
default-features = false

# The profile that 'cargo dist' will build with
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ inactive_char_style = "attr=dim"
# max_streams =

# JSON display settings
# Uses promkit_widgets::jsonstream::Config directly
# Uses promkit_widgets::json::Config directly
[json.stream]
# Number of spaces to use for indentation
indent = 2
Expand Down
2 changes: 1 addition & 1 deletion default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inactive_char_style = "attr=dim"
# max_streams =

# JSON display settings
# Uses promkit_widgets::jsonstream::Config directly
# Uses promkit_widgets::json::Config directly
[json.stream]
# Number of spaces to use for indentation
indent = 2
Expand Down
9 changes: 4 additions & 5 deletions src/completion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::BTreeSet, sync::Arc};

use promkit_widgets::{
core::{crossterm::event::Event, grapheme::StyledGraphemes, Widget},
core::{crossterm::event::Event, CreatedGraphemes, Widget},
listbox::{self, Listbox},
};
use tokio::{
Expand Down Expand Up @@ -133,8 +133,8 @@ impl CompletionNavigator {
}

/// Create graphemes for rendering the completion navigator.
pub fn create_graphemes(&self, width: u16, height: u16) -> StyledGraphemes {
self.state.create_graphemes(width, height)
pub fn create_graphemes(&self) -> CreatedGraphemes {
self.state.create_graphemes()
Comment on lines +136 to +137
}

/// Returns true when the cursor is close enough to the visible tail
Expand Down Expand Up @@ -252,7 +252,6 @@ pub fn start_completion_task(
loop {
tokio::select! {
Some(action) = action_rx.recv() => {
let area = shared_ctx.area().await;
let completion_view = {
let mut completion = shared_completion.write().await;
match action {
Expand Down Expand Up @@ -296,7 +295,7 @@ pub fn start_completion_task(
completion.clear_session_state();
}
}
completion.create_graphemes(area.0, area.1)
completion.create_graphemes()
};

shared_renderer
Expand Down
42 changes: 40 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use promkit_widgets::{core::crossterm::event::Event, jsonstream, listbox, text_editor};
use promkit_widgets::{core::crossterm::event::Event, json, listbox, text_editor};
use serde::{Deserialize, Serialize};
use termcfg::crossterm_config::event_set_serde;
use tokio::time::Duration;
Expand All @@ -17,7 +17,7 @@ pub struct EditorConfig {
#[derive(Serialize, Deserialize)]
pub struct JsonConfig {
pub max_streams: Option<usize>,
pub stream: jsonstream::Config,
pub stream: json::Config,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -140,3 +140,41 @@ impl Config {
toml::from_str(content).map_err(Into::into)
}
}

#[cfg(test)]
mod tests {
use super::*;
use promkit_widgets::{core::crossterm::style::Color, json::config::OverflowMode};

#[test]
fn loads_existing_default_config_with_new_widget_defaults() {
let config = Config::load_from(DEFAULT_CONFIG).unwrap();
assert_eq!(config.editor.on_focus.prefix, "❯❯ ");
assert!(config.editor.on_focus.continuation_prefix.is_empty());
assert_eq!(config.json.stream.indent, 2);
assert_eq!(config.json.stream.overflow_mode, OverflowMode::Wrap);
assert!(!config.json.stream.show_line_numbers);
assert_eq!(config.completion.listbox.lines, Some(3));
}

#[test]
fn preserves_custom_styles_in_existing_config() {
let custom = DEFAULT_CONFIG
.replace("❯❯ ", "jq ❯ ")
.replace("indent = 2", "indent = 4")
.replace("key_style = \"fg=cyan\"", "key_style = \"fg=#FF79C6\"")
.replace("cursor = \"❯ \"", "cursor = \"→ \"");
let config = Config::load_from(&custom).unwrap();
assert_eq!(config.editor.on_focus.prefix, "jq ❯ ");
assert_eq!(config.json.stream.indent, 4);
assert_eq!(
config.json.stream.key_style.foreground_color,
Some(Color::Rgb {
r: 255,
g: 121,
b: 198
})
);
assert_eq!(config.completion.listbox.cursor, "→ ");
}
}
Loading
Loading