chore: remove returns because it's bad code style (i've read that on stack overflow)
This commit is contained in:
@@ -23,15 +23,13 @@ pub fn load_from_file(path: PathBuf, debug_mode: bool) -> Config {
|
||||
let mut ini = Ini::new();
|
||||
ini.load(&path.to_str().unwrap()).unwrap();
|
||||
|
||||
let config = Config {
|
||||
Config {
|
||||
be_polite: ini.getbool("general", "polite").unwrap().unwrap(),
|
||||
fps: ini.getuint("general", "fps").unwrap().unwrap(),
|
||||
color: load_color(&ini, debug_mode),
|
||||
time_format: ini.get("format", "time").unwrap(),
|
||||
date_format: ini.get("format", "date").unwrap(),
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_default_config(path: PathBuf) -> () {
|
||||
@@ -47,19 +45,17 @@ fn load_color(ini: &Ini, debug_mode: bool) -> ComputableColor {
|
||||
match color_mode.as_str() {
|
||||
"term" => {
|
||||
let color = ini.getint("styling", "color_term").unwrap().unwrap();
|
||||
return ComputableColor::from(load_term_color(color));
|
||||
ComputableColor::from(load_term_color(color))
|
||||
}
|
||||
"hex" => {
|
||||
let color = ini.get("styling", "color_hex").unwrap();
|
||||
return ComputableColor::from(load_hex_color(&color));
|
||||
ComputableColor::from(load_hex_color(&color))
|
||||
}
|
||||
"ansi" => {
|
||||
let color = ini.getint("styling", "color_ansi").unwrap().unwrap();
|
||||
return ComputableColor::from(load_ansi_color(color));
|
||||
}
|
||||
"gradient" => {
|
||||
return load_gradient(ini, debug_mode);
|
||||
ComputableColor::from(load_ansi_color(color))
|
||||
}
|
||||
"gradient" => load_gradient(ini, debug_mode),
|
||||
_ => panic!("ERROR: Invalid color mode: {}", color_mode),
|
||||
}
|
||||
}
|
||||
@@ -88,15 +84,15 @@ fn load_term_color(value: i64) -> Color {
|
||||
|
||||
fn load_hex_color(value: &str) -> Color {
|
||||
let rgb = parse_hex_color(value);
|
||||
return Color::Rgb {
|
||||
Color::Rgb {
|
||||
r: rgb.0,
|
||||
g: rgb.1,
|
||||
b: rgb.2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn load_ansi_color(value: i64) -> Color {
|
||||
return Color::AnsiValue(value.try_into().unwrap());
|
||||
Color::AnsiValue(value.try_into().unwrap())
|
||||
}
|
||||
|
||||
fn load_gradient(ini: &Ini, debug_mode: bool) -> ComputableColor {
|
||||
@@ -131,5 +127,5 @@ fn load_gradient(ini: &Ini, debug_mode: bool) -> ComputableColor {
|
||||
.try_into()
|
||||
.unwrap()
|
||||
};
|
||||
return generate_gradient(keys, steps - 1);
|
||||
generate_gradient(keys, steps - 1)
|
||||
}
|
||||
|
||||
@@ -136,5 +136,5 @@ fn main() -> io::Result<()> {
|
||||
println!("CTRL-C pressed, bye!\n");
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Chronometer {
|
||||
}
|
||||
|
||||
fn is_paused(&self) -> bool {
|
||||
return self.start_time.is_none();
|
||||
self.start_time.is_none()
|
||||
}
|
||||
|
||||
fn elapsed(&self) -> Duration {
|
||||
@@ -146,7 +146,7 @@ pub fn main_loop(config: &mut Config) -> io::Result<()> {
|
||||
thread::sleep(Duration::from_millis(1000 / config.fps));
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_frame(
|
||||
@@ -202,5 +202,5 @@ fn render_frame(
|
||||
rendering::draw_text(text, x, y, color)?;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ pub fn main_loop(config: &mut Config) -> io::Result<()> {
|
||||
thread::sleep(Duration::from_millis(1000 / config.fps));
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_frame(config: &Config) -> io::Result<()> {
|
||||
@@ -73,5 +73,5 @@ fn render_frame(config: &Config) -> io::Result<()> {
|
||||
let y = height / 2 + symbols::SYMBOL_HEIGHT as i16 / 2 + 2;
|
||||
rendering::draw_text(&date, x, y - 1, color)?;
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ pub fn print_debug_infos(config: &mut Config) -> io::Result<()> {
|
||||
writeln!(stdout)?;
|
||||
queue!(stdout, style::ResetColor)?;
|
||||
let _ = stdout.flush();
|
||||
return Ok(());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_debug_label(key: &str) -> io::Result<()> {
|
||||
@@ -60,5 +61,5 @@ fn print_debug_label(key: &str) -> io::Result<()> {
|
||||
write!(stdout, "{}: ", key)?;
|
||||
queue!(stdout, style::ResetColor)?;
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl Timer {
|
||||
}
|
||||
|
||||
fn is_paused(&self) -> bool {
|
||||
return self.end_time.is_none();
|
||||
self.end_time.is_none()
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
@@ -116,7 +116,7 @@ pub fn main_loop(config: &mut Config, duration: &str) -> io::Result<()> {
|
||||
thread::sleep(Duration::from_millis(1000 / config.fps));
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_frame(config: &Config, timer: &Timer) -> io::Result<()> {
|
||||
@@ -146,5 +146,5 @@ fn render_frame(config: &Config, timer: &Timer) -> io::Result<()> {
|
||||
rendering::draw_text(text, x, y, color)?;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ pub struct ComputableColor {
|
||||
|
||||
impl ComputableColor {
|
||||
pub fn from(color: Color) -> ComputableColor {
|
||||
return ComputableColor {
|
||||
ComputableColor {
|
||||
values: vec![color],
|
||||
current: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self) -> () {
|
||||
@@ -18,27 +18,26 @@ impl ComputableColor {
|
||||
}
|
||||
|
||||
pub fn get_value(&self) -> Color {
|
||||
return *self.values.get(self.current).unwrap();
|
||||
*self.values.get(self.current).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_keys_count(&self) -> usize {
|
||||
return self.values.len();
|
||||
self.values.len()
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp01(v: f32) -> f32 {
|
||||
return if v < 0.0 {
|
||||
if v < 0.0 {
|
||||
0.0
|
||||
} else if v > 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
v
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn lerp(a: u8, b: u8, t: f32) -> u8 {
|
||||
let v = a as f32 + (b as f32 - a as f32) as f32 * clamp01(t);
|
||||
return v as u8;
|
||||
(a as f32 + (b as f32 - a as f32) as f32 * clamp01(t)) as u8
|
||||
}
|
||||
|
||||
pub fn generate_gradient(keys: Vec<(u8, u8, u8)>, steps: usize) -> ComputableColor {
|
||||
@@ -61,10 +60,10 @@ pub fn generate_gradient(keys: Vec<(u8, u8, u8)>, steps: usize) -> ComputableCol
|
||||
}
|
||||
}
|
||||
|
||||
return ComputableColor {
|
||||
ComputableColor {
|
||||
values: gradient,
|
||||
current: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_hex_color(value: &str) -> (u8, u8, u8) {
|
||||
@@ -91,5 +90,5 @@ pub fn parse_hex_color(value: &str) -> (u8, u8, u8) {
|
||||
let g = u8::from_str_radix(&value[2..4], 16).unwrap();
|
||||
let b = u8::from_str_radix(&value[4..6], 16).unwrap();
|
||||
|
||||
return (r, g, b);
|
||||
(r, g, b)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn draw_time(time: &str, color: Color) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn draw_text(mut string: &str, mut x: i16, y: i16, color: Color) -> io::Result<()> {
|
||||
@@ -63,7 +63,8 @@ pub fn draw_text(mut string: &str, mut x: i16, y: i16, color: Color) -> io::Resu
|
||||
style::SetAttribute(Attribute::Bold)
|
||||
)?;
|
||||
write!(stdout, "{}", string)?;
|
||||
return Ok(());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw_time_width(time: &str) -> i16 {
|
||||
@@ -113,5 +114,5 @@ fn draw_time_symbol(symbol: char, x: i16, y: i16, color: Color) -> io::Result<()
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ pub fn format_duration(duration: time::Duration) -> String {
|
||||
let minutes = (seconds % 3600) / 60;
|
||||
let seconds = seconds % 60;
|
||||
|
||||
return format!("{:02}:{:02}:{:02}", hours, minutes, seconds);
|
||||
format!("{:02}:{:02}:{:02}", hours, minutes, seconds)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user