Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use promkit-{core, widgets} instead #84

Merged
merged 3 commits into from
Apr 1, 2025
Merged
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
60 changes: 22 additions & 38 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ async-trait = "0.1.88"
clap = { version = "4.5.34", features = ["derive"] }
duration-string = { version = "0.5.2", features = ["serde"] }
derive_builder = "0.20.2"
# See https://github.com/crossterm-rs/crossterm/issues/935
crossterm = { version = "0.28.1", features = ["use-dev-tty", "event-stream", "libc", "serde"] }
dirs = "6.0.0"
futures = "0.3.30"
jaq-core = "1.2.1"
jaq-interpret = "1.2.1"
jaq-parse = "1.0.2"
jaq-std = "1.2.1"
promkit = "0.8.0"
promkit-core = "0.1.0"
promkit-widgets = { version = "0.1.0", features = ["jsonstream", "listbox", "text", "texteditor"] }
serde = "1.0.219"
tokio = { version = "1.44.1", features = ["full"] }
tokio-stream = "0.1.16"
Expand Down
86 changes: 55 additions & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashSet;

use crossterm::{
use promkit_core::crossterm::{
event::{KeyCode, KeyModifiers},
style::{Attribute, Attributes, Color, ContentStyle},
};
use promkit::{style::StyleBuilder, text_editor::Mode};
use promkit_widgets::text_editor::Mode;
use serde::{Deserialize, Serialize};
use tokio::time::Duration;

Expand Down Expand Up @@ -45,22 +45,31 @@ impl Default for EditorConfig {
Self {
theme_on_focus: EditorTheme {
prefix: String::from("❯❯ "),
prefix_style: StyleBuilder::new().fgc(Color::Blue).build(),
active_char_style: StyleBuilder::new().bgc(Color::Magenta).build(),
inactive_char_style: StyleBuilder::new().build(),
prefix_style: ContentStyle {
foreground_color: Some(Color::Blue),
..Default::default()
},
active_char_style: ContentStyle {
background_color: Some(Color::Magenta),
..Default::default()
},
inactive_char_style: ContentStyle::default(),
},
theme_on_defocus: EditorTheme {
prefix: String::from("▼ "),
prefix_style: StyleBuilder::new()
.fgc(Color::Blue)
.attrs(Attributes::from(Attribute::Dim))
.build(),
active_char_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Dim))
.build(),
inactive_char_style: StyleBuilder::new()
.attrs(Attributes::from(Attribute::Dim))
.build(),
prefix_style: ContentStyle {
foreground_color: Some(Color::Blue),
attributes: Attributes::from(Attribute::Dim),
..Default::default()
},
active_char_style: ContentStyle {
attributes: Attributes::from(Attribute::Dim),
..Default::default()
},
inactive_char_style: ContentStyle {
attributes: Attributes::from(Attribute::Dim),
..Default::default()
},
},
mode: Mode::Insert,
word_break_chars: HashSet::from(['.', '|', '(', ')', '[', ']']),
Expand Down Expand Up @@ -106,17 +115,28 @@ impl Default for JsonConfig {
max_streams: None,
theme: JsonTheme {
indent: 2,
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(),
curly_brackets_style: ContentStyle {
attributes: Attributes::from(Attribute::Bold),
..Default::default()
},
square_brackets_style: ContentStyle {
attributes: Attributes::from(Attribute::Bold),
..Default::default()
},
key_style: ContentStyle {
foreground_color: Some(Color::Cyan),
..Default::default()
},
string_value_style: ContentStyle {
foreground_color: Some(Color::Green),
..Default::default()
},
number_value_style: ContentStyle::default(),
boolean_value_style: ContentStyle::default(),
null_value_style: ContentStyle {
foreground_color: Some(Color::Grey),
..Default::default()
},
},
}
}
Expand All @@ -143,11 +163,15 @@ impl Default for CompletionConfig {
cursor: String::from("❯ "),
search_result_chunk_size: 100,
search_load_chunk_size: 50000,
active_item_style: StyleBuilder::new()
.fgc(Color::Grey)
.bgc(Color::Yellow)
.build(),
inactive_item_style: StyleBuilder::new().fgc(Color::Grey).build(),
active_item_style: ContentStyle {
foreground_color: Some(Color::Grey),
background_color: Some(Color::Yellow),
..Default::default()
},
inactive_item_style: ContentStyle {
foreground_color: Some(Color::Grey),
..Default::default()
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/content_style.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crossterm::style::{Attribute, Attributes, Color, ContentStyle};
use promkit_core::crossterm::style::{Attribute, Attributes, Color, ContentStyle};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand Down
4 changes: 3 additions & 1 deletion src/config/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashSet;

use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
use promkit_core::crossterm::event::{
Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind,
};
use serde::{Deserialize, Serialize};

pub trait Matcher<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/config/text_editor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use promkit::text_editor::Mode;
use promkit_widgets::text_editor::Mode;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

pub mod text_editor_mode_serde {
Expand Down
35 changes: 24 additions & 11 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::{future::Future, pin::Pin};

use crossterm::{
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers},
style::Color,
use promkit_core::{
crossterm::{
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers},
style::{Color, ContentStyle},
},
Pane, PaneFactory,
};
use promkit::{
pane::Pane,
style::StyleBuilder,
use promkit_widgets::{
text::{self, Text},
text_editor, PaneFactory,
text_editor,
};

use crate::{
Expand Down Expand Up @@ -113,26 +114,38 @@ pub async fn edit<'a>(event: &'a Event, editor: &'a mut Editor) -> anyhow::Resul
"Loaded all ({}) suggestions",
result.load_state.loaded_item_len
));
editor.guide.style = StyleBuilder::new().fgc(Color::Green).build();
editor.guide.style = ContentStyle {
foreground_color: Some(Color::Green),
..Default::default()
};
} else {
editor.guide.text = Text::from(format!(
"Loaded partially ({}) suggestions",
result.load_state.loaded_item_len
));
editor.guide.style = StyleBuilder::new().fgc(Color::Green).build();
editor.guide.style = ContentStyle {
foreground_color: Some(Color::Green),
..Default::default()
};
}
editor.state.texteditor.replace(&head);
editor.handler = BOXED_SEARCHER_HANDLER;
}
None => {
editor.guide.text =
Text::from(format!("No suggestion found for '{}'", prefix));
editor.guide.style = StyleBuilder::new().fgc(Color::Yellow).build();
editor.guide.style = ContentStyle {
foreground_color: Some(Color::Yellow),
..Default::default()
};
}
},
Err(e) => {
editor.guide.text = Text::from(format!("Failed to lookup suggestions: {}", e));
editor.guide.style = StyleBuilder::new().fgc(Color::Yellow).build();
editor.guide.style = ContentStyle {
foreground_color: Some(Color::Yellow),
..Default::default()
};
}
}
}
Expand Down
Loading
Loading