Skip to content

Commit a8935f7

Browse files
committed
Add command parser
1 parent 16c9c30 commit a8935f7

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/vonal_daemon/app.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct AppConfig {
1818

1919
pub struct App {
2020
pub config: AppConfig,
21-
query: String,
21+
pub query: String,
2222
prompt_icon: RetainedImage,
2323
plugin_manager: PluginManager,
2424
error: Option<String>,
@@ -135,16 +135,15 @@ impl App {
135135
}
136136

137137
fn render_search_bar(&mut self, ui: &mut egui::Ui, _ctx: &egui::Context, disable_cursor: bool) {
138-
ui.add(
139-
TextEdit::singleline(&mut self.query)
140-
.interactive(!disable_cursor)
141-
.id(Id::new(SEARCH_INPUT_ID))
142-
.frame(false)
143-
.hint_text(&self.config.placeholder)
144-
.font(FontSelection::FontId(FontId::proportional(20.)))
145-
.margin(vec2(0., 15.))
146-
.desired_width(f32::INFINITY),
147-
);
138+
let textbox = TextEdit::singleline(&mut self.query)
139+
.interactive(!disable_cursor)
140+
.id(Id::new(SEARCH_INPUT_ID))
141+
.frame(false)
142+
.hint_text(&self.config.placeholder)
143+
.font(FontSelection::FontId(FontId::proportional(20.)))
144+
.margin(vec2(0., 15.))
145+
.desired_width(f32::INFINITY);
146+
ui.add(textbox);
148147
ui.memory().request_focus(Id::new(SEARCH_INPUT_ID));
149148
}
150149

src/vonal_daemon/main.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,7 @@ fn handle_platform_event(
146146
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
147147
gl_window.window().request_redraw();
148148
}
149-
Event::UserEvent(UserEvent::CliCommand(command)) => match command.as_str() {
150-
"show" => show_window(&gl_window, true),
151-
"hide" => hide_window(&gl_window),
152-
"toggle" => {
153-
let show = !gl_window.window().is_visible().unwrap_or(false);
154-
show_window(&gl_window, show);
155-
}
156-
command => println!("Got command: {command:?}"),
157-
},
149+
Event::UserEvent(UserEvent::CliCommand(commands)) => parse_cli(commands, gl_window, app),
158150
Event::UserEvent(UserEvent::Quit) => control_flow.set_exit(),
159151
Event::UserEvent(UserEvent::ConfigEvent(event)) => match event {
160152
ConfigEvent::Created => println!("Config file created"),
@@ -187,6 +179,27 @@ fn handle_platform_event(
187179
}
188180
}
189181

182+
fn parse_cli(commands: String, gl_window: &GlutinWindowContext, app: &mut app::App) {
183+
let mut commands = commands.split(',');
184+
185+
while let Some(command) = commands.next() {
186+
match command {
187+
"show" => show_window(&gl_window, true),
188+
"hide" => hide_window(&gl_window),
189+
"toggle" => {
190+
let show = !gl_window.window().is_visible().unwrap_or(false);
191+
show_window(&gl_window, show);
192+
}
193+
"set_query" => {
194+
let query = commands.next().unwrap_or_default();
195+
app.query = query.into();
196+
gl_window.window().request_redraw();
197+
}
198+
command => println!("Got command: {command:?}"),
199+
}
200+
}
201+
}
202+
190203
fn hide_window(gl_window: &GlutinWindowContext) {
191204
gl_window.window().set_visible(false);
192205
}

0 commit comments

Comments
 (0)