refactor(tui): use consistent naming for kernel parameters

This commit is contained in:
Orhun Parmaksız 2022-01-10 20:24:39 +03:00
parent a0b4c593f8
commit e7e622fa8d
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
2 changed files with 17 additions and 17 deletions

View File

@ -18,8 +18,8 @@ pub struct App<'a> {
pub input: Option<String>,
/// Time tracker for measuring the time for clearing the input.
pub input_time: Option<Instant>,
/// List of sysctl variables.
pub variable_list: StatefulTable<Parameter>,
/// List of sysctl parameters.
pub parameter_list: StatefulTable<Parameter>,
/// Sysctl controller.
sysctl: &'a mut Sysctl,
}
@ -31,7 +31,7 @@ impl<'a> App<'a> {
running: true,
input: None,
input_time: None,
variable_list: StatefulTable::with_items(sysctl.parameters.clone()),
parameter_list: StatefulTable::with_items(sysctl.parameters.clone()),
sysctl,
}
}
@ -45,10 +45,10 @@ impl<'a> App<'a> {
pub fn run_command(&mut self, command: Command) -> Result<()> {
match command {
Command::ScrollUp => {
self.variable_list.previous();
self.parameter_list.previous();
}
Command::ScrollDown => {
self.variable_list.next();
self.parameter_list.next();
}
Command::ProcessInput => {
if self.input_time.is_some() {
@ -89,7 +89,7 @@ impl<'a> App<'a> {
Command::Refresh => {
self.input = None;
*self.sysctl = Sysctl::init(self.sysctl.config.clone())?;
self.variable_list = StatefulTable::with_items(self.sysctl.parameters.clone());
self.parameter_list = StatefulTable::with_items(self.sysctl.parameters.clone());
}
Command::Exit => {
self.running = false;

View File

@ -18,16 +18,16 @@ pub fn render<B: Backend>(frame: &mut Frame<'_, B>, app: &mut App) {
.direction(Direction::Vertical)
.constraints([Constraint::Min(rect.height - 3), Constraint::Min(3)].as_ref())
.split(chunks[0]);
render_variable_list(frame, chunks[0], app);
render_parameter_list(frame, chunks[0], app);
render_input_prompt(frame, chunks[1], rect.height - 2, app);
}
render_variable_documentation(frame, chunks[1], app);
render_parameter_documentation(frame, chunks[1], app);
}
/// Renders the list that contains the sysctl variables.
fn render_variable_list<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &mut App) {
/// Renders the list that contains the sysctl parameters.
fn render_parameter_list<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &mut App) {
let max_width = app
.variable_list
.parameter_list
.items
.iter()
.map(|p| p.name.len())
@ -35,7 +35,7 @@ fn render_variable_list<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &
.and_then(|v| u16::try_from(v).ok())
.unwrap_or(1);
let minimize_rows = rect.width < max_width + 10;
let rows = app.variable_list.items.iter().map(|item| {
let rows = app.parameter_list.items.iter().map(|item| {
Row::new(if minimize_rows {
vec![Cell::from(format!("{} = {}", item.name, item.value))]
} else {
@ -63,17 +63,17 @@ fn render_variable_list<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &
[Constraint::Min(max_width), Constraint::Percentage(100)]
}),
rect,
&mut app.variable_list.state,
&mut app.parameter_list.state,
);
}
/// Renders the documentation of the selected sysctl variable.
fn render_variable_documentation<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &mut App) {
/// Renders the documentation of the selected sysctl parameter.
fn render_parameter_documentation<B: Backend>(frame: &mut Frame<'_, B>, rect: Rect, app: &mut App) {
frame.render_widget(
Paragraph::new(
app.variable_list
app.parameter_list
.selected()
.and_then(|variable| variable.get_documentation())
.and_then(|parameter| parameter.get_documentation())
.unwrap_or_else(|| String::from("No documentation available")),
)
.block(