forked from protiumx/rq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70f0c22
commit 6ff49bb
Showing
6 changed files
with
100 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::{components::response_panel::SaveOption, event::Event}; | ||
|
||
use super::InputComponent; | ||
|
||
pub struct InputBuilder { | ||
content: String, | ||
cursor: Option<usize>, | ||
typ: InputType, | ||
} | ||
|
||
pub enum InputType { | ||
FileName(SaveOption), | ||
VarValue(String), | ||
} | ||
|
||
impl InputBuilder { | ||
pub fn new(typ: InputType) -> Self { | ||
Self { | ||
content: String::new(), | ||
cursor: None, | ||
typ, | ||
} | ||
} | ||
|
||
pub fn with_content(self, content: String) -> Self { | ||
Self { content, ..self } | ||
} | ||
|
||
pub fn with_cursor(self, cursor: usize) -> Self { | ||
Self { | ||
cursor: Some(cursor), | ||
..self | ||
} | ||
} | ||
|
||
fn build_component(&self) -> InputComponent { | ||
let input = InputComponent::from(&self.content); | ||
|
||
match self.cursor { | ||
Some(i) => input.with_cursor(i), | ||
None => input, | ||
} | ||
} | ||
|
||
pub fn build(self) -> InputComponent { | ||
let input = self.build_component(); | ||
|
||
match self.typ { | ||
InputType::FileName(save_option) => input.with_confirm_callback(move |value| { | ||
Event::emit(Event::InputConfirm); | ||
Event::emit(Event::Save((value, save_option))); | ||
}), | ||
InputType::VarValue(name) => input.with_confirm_callback(move |value| { | ||
Event::emit(Event::InputConfirm); | ||
Event::emit(Event::UpdateVar((name.clone(), value))); | ||
}), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters