Skip to content

Commit e6283a4

Browse files
committed
fix: use promkit-{core, widgets} instead of promkit
1 parent 2f2f196 commit e6283a4

File tree

3 files changed

+82
-37
lines changed

3 files changed

+82
-37
lines changed

src/config.rs

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,31 @@ impl Default for EditorConfig {
4545
Self {
4646
theme_on_focus: EditorTheme {
4747
prefix: String::from("❯❯ "),
48-
prefix_style: StyleBuilder::new().fgc(Color::Blue).build(),
49-
active_char_style: StyleBuilder::new().bgc(Color::Magenta).build(),
50-
inactive_char_style: StyleBuilder::new().build(),
48+
prefix_style: ContentStyle {
49+
foreground_color: Some(Color::Blue),
50+
..Default::default()
51+
},
52+
active_char_style: ContentStyle {
53+
background_color: Some(Color::Magenta),
54+
..Default::default()
55+
},
56+
inactive_char_style: ContentStyle::default(),
5157
},
5258
theme_on_defocus: EditorTheme {
5359
prefix: String::from("▼ "),
54-
prefix_style: StyleBuilder::new()
55-
.fgc(Color::Blue)
56-
.attrs(Attributes::from(Attribute::Dim))
57-
.build(),
58-
active_char_style: StyleBuilder::new()
59-
.attrs(Attributes::from(Attribute::Dim))
60-
.build(),
61-
inactive_char_style: StyleBuilder::new()
62-
.attrs(Attributes::from(Attribute::Dim))
63-
.build(),
60+
prefix_style: ContentStyle {
61+
foreground_color: Some(Color::Blue),
62+
attributes: Attributes::from(Attribute::Dim),
63+
..Default::default()
64+
},
65+
active_char_style: ContentStyle {
66+
attributes: Attributes::from(Attribute::Dim),
67+
..Default::default()
68+
},
69+
inactive_char_style: ContentStyle {
70+
attributes: Attributes::from(Attribute::Dim),
71+
..Default::default()
72+
},
6473
},
6574
mode: Mode::Insert,
6675
word_break_chars: HashSet::from(['.', '|', '(', ')', '[', ']']),
@@ -106,17 +115,28 @@ impl Default for JsonConfig {
106115
max_streams: None,
107116
theme: JsonTheme {
108117
indent: 2,
109-
curly_brackets_style: StyleBuilder::new()
110-
.attrs(Attributes::from(Attribute::Bold))
111-
.build(),
112-
square_brackets_style: StyleBuilder::new()
113-
.attrs(Attributes::from(Attribute::Bold))
114-
.build(),
115-
key_style: StyleBuilder::new().fgc(Color::Cyan).build(),
116-
string_value_style: StyleBuilder::new().fgc(Color::Green).build(),
117-
number_value_style: StyleBuilder::new().build(),
118-
boolean_value_style: StyleBuilder::new().build(),
119-
null_value_style: StyleBuilder::new().fgc(Color::Grey).build(),
118+
curly_brackets_style: ContentStyle {
119+
attributes: Attributes::from(Attribute::Bold),
120+
..Default::default()
121+
},
122+
square_brackets_style: ContentStyle {
123+
attributes: Attributes::from(Attribute::Bold),
124+
..Default::default()
125+
},
126+
key_style: ContentStyle {
127+
foreground_color: Some(Color::Cyan),
128+
..Default::default()
129+
},
130+
string_value_style: ContentStyle {
131+
foreground_color: Some(Color::Green),
132+
..Default::default()
133+
},
134+
number_value_style: ContentStyle::default(),
135+
boolean_value_style: ContentStyle::default(),
136+
null_value_style: ContentStyle {
137+
foreground_color: Some(Color::Grey),
138+
..Default::default()
139+
},
120140
},
121141
}
122142
}
@@ -143,11 +163,15 @@ impl Default for CompletionConfig {
143163
cursor: String::from("❯ "),
144164
search_result_chunk_size: 100,
145165
search_load_chunk_size: 50000,
146-
active_item_style: StyleBuilder::new()
147-
.fgc(Color::Grey)
148-
.bgc(Color::Yellow)
149-
.build(),
150-
inactive_item_style: StyleBuilder::new().fgc(Color::Grey).build(),
166+
active_item_style: ContentStyle {
167+
foreground_color: Some(Color::Grey),
168+
background_color: Some(Color::Yellow),
169+
..Default::default()
170+
},
171+
inactive_item_style: ContentStyle {
172+
foreground_color: Some(Color::Grey),
173+
..Default::default()
174+
},
151175
}
152176
}
153177
}

src/editor.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{future::Future, pin::Pin};
33
use promkit_core::{
44
crossterm::{
55
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers},
6-
style::Color,
6+
style::{Color, ContentStyle},
77
},
88
Pane, PaneFactory,
99
};
@@ -114,26 +114,38 @@ pub async fn edit<'a>(event: &'a Event, editor: &'a mut Editor) -> anyhow::Resul
114114
"Loaded all ({}) suggestions",
115115
result.load_state.loaded_item_len
116116
));
117-
editor.guide.style = StyleBuilder::new().fgc(Color::Green).build();
117+
editor.guide.style = ContentStyle {
118+
foreground_color: Some(Color::Green),
119+
..Default::default()
120+
};
118121
} else {
119122
editor.guide.text = Text::from(format!(
120123
"Loaded partially ({}) suggestions",
121124
result.load_state.loaded_item_len
122125
));
123-
editor.guide.style = StyleBuilder::new().fgc(Color::Green).build();
126+
editor.guide.style = ContentStyle {
127+
foreground_color: Some(Color::Green),
128+
..Default::default()
129+
};
124130
}
125131
editor.state.texteditor.replace(&head);
126132
editor.handler = BOXED_SEARCHER_HANDLER;
127133
}
128134
None => {
129135
editor.guide.text =
130136
Text::from(format!("No suggestion found for '{}'", prefix));
131-
editor.guide.style = StyleBuilder::new().fgc(Color::Yellow).build();
137+
editor.guide.style = ContentStyle {
138+
foreground_color: Some(Color::Yellow),
139+
..Default::default()
140+
};
132141
}
133142
},
134143
Err(e) => {
135144
editor.guide.text = Text::from(format!("Failed to lookup suggestions: {}", e));
136-
editor.guide.style = StyleBuilder::new().fgc(Color::Yellow).build();
145+
editor.guide.style = ContentStyle {
146+
foreground_color: Some(Color::Yellow),
147+
..Default::default()
148+
};
137149
}
138150
}
139151
}

src/prompt.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ fn copy_to_clipboard(content: &str) -> text::State {
7676
// https://github.com/1Password/arboard/issues/153
7777
Err(e) => text::State {
7878
text: Text::from(format!("Failed to setup clipboard: {}", e)),
79-
style: StyleBuilder::new().fgc(Color::Red).build(),
79+
style: ContentStyle {
80+
foreground_color: Some(Color::Red),
81+
..Default::default()
82+
},
8083
..Default::default()
8184
},
8285
}
@@ -195,7 +198,10 @@ pub async fn run<T: ViewProvider + SearchProvider>(
195198
let size = terminal::size()?;
196199
pane = text::State {
197200
text: Text::from("Failed to copy while rendering is in progress.".to_string()),
198-
style: StyleBuilder::new().fgc(Color::Yellow).build(),
201+
style: ContentStyle {
202+
foreground_color: Some(Color::Yellow),
203+
..Default::default()
204+
},
199205
..Default::default()
200206
}.create_pane(size.0, size.1);
201207
}
@@ -226,7 +232,10 @@ pub async fn run<T: ViewProvider + SearchProvider>(
226232
let size = terminal::size()?;
227233
pane = text::State {
228234
text: Text::from("Failed to switch pane while rendering is in progress.".to_string()),
229-
style: StyleBuilder::new().fgc(Color::Yellow).build(),
235+
style: ContentStyle {
236+
foreground_color: Some(Color::Yellow),
237+
..Default::default()
238+
},
230239
..Default::default()
231240
}.create_pane(size.0, size.1);
232241
}

0 commit comments

Comments
 (0)