mirror of
https://github.com/orhun/systeroid
synced 2024-10-15 03:42:18 +00:00
refactor(config): rename ColorConfig
to AppConfig
This commit is contained in:
parent
c97854424f
commit
6aa07aefc3
|
@ -16,8 +16,8 @@ macro_rules! map {
|
|||
pub struct Config {
|
||||
/// Sysctl configuration.
|
||||
pub sysctl: SysctlConfig,
|
||||
/// Color configuration.
|
||||
pub color: ColorConfig,
|
||||
/// Application configuration.
|
||||
pub color: AppConfig,
|
||||
}
|
||||
|
||||
/// Sysctl configuration.
|
||||
|
@ -29,7 +29,7 @@ pub struct SysctlConfig {
|
|||
|
||||
/// Sysctl configuration.
|
||||
#[derive(Debug)]
|
||||
pub struct ColorConfig {
|
||||
pub struct AppConfig {
|
||||
/// Whether if the colors are disabled.
|
||||
pub no_color: bool,
|
||||
/// Sections and the corresponding colors.
|
||||
|
@ -38,7 +38,7 @@ pub struct ColorConfig {
|
|||
pub default_color: Color,
|
||||
}
|
||||
|
||||
impl Default for ColorConfig {
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
no_color: false,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::config::{ColorConfig, SysctlConfig};
|
||||
use crate::config::{AppConfig, SysctlConfig};
|
||||
use crate::error::Result;
|
||||
use crate::parsers::parse_kernel_docs;
|
||||
use colored::*;
|
||||
|
@ -93,7 +93,7 @@ pub struct Parameter {
|
|||
|
||||
impl Parameter {
|
||||
/// Returns the parameter name with corresponding section colors.
|
||||
pub fn colored_name(&self, config: &ColorConfig) -> String {
|
||||
pub fn colored_name(&self, config: &AppConfig) -> String {
|
||||
let fields = self.name.split('.').collect::<Vec<&str>>();
|
||||
fields
|
||||
.iter()
|
||||
|
@ -117,7 +117,7 @@ impl Parameter {
|
|||
}
|
||||
|
||||
/// Prints the kernel parameter to given output.
|
||||
pub fn display_value<W: Write>(&self, config: &ColorConfig, output: &mut W) -> Result<()> {
|
||||
pub fn display_value<W: Write>(&self, config: &AppConfig, output: &mut W) -> Result<()> {
|
||||
if !config.no_color {
|
||||
writeln!(
|
||||
output,
|
||||
|
@ -164,7 +164,7 @@ impl Parameter {
|
|||
pub fn update_value<W: Write>(
|
||||
&mut self,
|
||||
new_value: &str,
|
||||
config: &ColorConfig,
|
||||
config: &AppConfig,
|
||||
output: &mut W,
|
||||
) -> Result<()> {
|
||||
let ctl = Ctl::new(&self.name)?;
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::env;
|
|||
use std::io::{self, Stdout};
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use systeroid_core::config::ColorConfig;
|
||||
use systeroid_core::config::AppConfig;
|
||||
use systeroid_core::error::Result;
|
||||
use systeroid_core::sysctl::Sysctl;
|
||||
|
||||
|
@ -11,19 +11,19 @@ use systeroid_core::sysctl::Sysctl;
|
|||
pub struct App<'a> {
|
||||
/// Sysctl manager.
|
||||
sysctl: &'a mut Sysctl,
|
||||
/// Color configuration.
|
||||
color_config: &'a ColorConfig,
|
||||
/// Configuration.
|
||||
config: &'a AppConfig,
|
||||
/// Standard output.
|
||||
stdout: Stdout,
|
||||
}
|
||||
|
||||
impl<'a> App<'a> {
|
||||
/// Constructs a new instance.
|
||||
pub fn new(sysctl: &'a mut Sysctl, color_config: &'a ColorConfig) -> Self {
|
||||
pub fn new(sysctl: &'a mut Sysctl, config: &'a AppConfig) -> Self {
|
||||
let stdout = io::stdout();
|
||||
Self {
|
||||
sysctl,
|
||||
color_config,
|
||||
config,
|
||||
stdout,
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ impl<'a> App<'a> {
|
|||
self.sysctl
|
||||
.parameters
|
||||
.iter()
|
||||
.try_for_each(|parameter| parameter.display_value(self.color_config, &mut self.stdout))
|
||||
.try_for_each(|parameter| parameter.display_value(self.config, &mut self.stdout))
|
||||
}
|
||||
|
||||
/// Updates the documentation for kernel parameters.
|
||||
|
@ -89,9 +89,9 @@ impl<'a> App<'a> {
|
|||
};
|
||||
if let Some(parameter) = self.sysctl.get_parameter(¶m_name) {
|
||||
if let Some(new_value) = new_value {
|
||||
parameter.update_value(&new_value, self.color_config, &mut self.stdout)?;
|
||||
parameter.update_value(&new_value, self.config, &mut self.stdout)?;
|
||||
} else {
|
||||
parameter.display_value(self.color_config, &mut self.stdout)?;
|
||||
parameter.display_value(self.config, &mut self.stdout)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue