mirror of
https://github.com/orhun/systeroid
synced 2024-07-23 19:34:58 +00:00
feat(tui): support changing the values of parameters
This commit is contained in:
parent
59001598e6
commit
a90fa2768f
|
@ -136,8 +136,33 @@ impl<'a> App<'a> {
|
|||
.and_then(|v| CopyOption::try_from(*v).ok())
|
||||
{
|
||||
self.copy_to_clipboard(copy_option)?;
|
||||
self.options = None;
|
||||
} else if let Some(parameter) = self.parameter_list.selected() {
|
||||
self.search_mode = false;
|
||||
self.input_time = None;
|
||||
self.input = Some(format!("set {} {}", parameter.name, parameter.value));
|
||||
}
|
||||
}
|
||||
Command::Set(param_name, new_value) => {
|
||||
if let Some(parameter) = self
|
||||
.parameter_list
|
||||
.items
|
||||
.iter_mut()
|
||||
.find(|param| param.name == param_name)
|
||||
{
|
||||
match parameter.update_value(&new_value, &self.sysctl.config, &mut Vec::new()) {
|
||||
Ok(()) => {
|
||||
self.run_command(Command::Refresh)?;
|
||||
}
|
||||
Err(e) => {
|
||||
self.input = Some(e.to_string());
|
||||
self.input_time = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.input = Some(String::from("Unknown parameter"));
|
||||
self.input_time = Some(Instant::now());
|
||||
}
|
||||
self.options = None;
|
||||
}
|
||||
Command::ScrollUp => {
|
||||
if let Some(options) = self.options.as_mut() {
|
||||
|
|
|
@ -6,6 +6,8 @@ use termion::event::Key;
|
|||
pub enum Command {
|
||||
/// Perform an action based on the selected entry.
|
||||
Select,
|
||||
/// Set the value of a parameter.
|
||||
Set(String, String),
|
||||
/// Scroll up on the widget.
|
||||
ScrollUp,
|
||||
/// Scroll down on the widget.
|
||||
|
@ -41,7 +43,17 @@ impl FromStr for Command {
|
|||
"copy" => Ok(Command::Copy),
|
||||
"refresh" => Ok(Command::Refresh),
|
||||
"exit" | "quit" | "q" | "q!" => Ok(Command::Exit),
|
||||
_ => Err(()),
|
||||
_ => {
|
||||
if s.starts_with("set") {
|
||||
let mut values = s.trim_start_matches("set").trim().split_whitespace();
|
||||
Ok(Command::Set(
|
||||
values.next().ok_or(())?.to_string(),
|
||||
values.next().ok_or(())?.to_string(),
|
||||
))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue