Skip to content

Commit

Permalink
style: linting
Browse files Browse the repository at this point in the history
should have little, if not no runtime impact. compiler probably already
changes the `&str` to `char` anyways.
  • Loading branch information
WilliamAnimate committed Nov 19, 2024
1 parent d878769 commit 7adb481
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use serde::Deserialize;

// TODO: better toml name?
#[cfg(target_os = "linux")]
static DEFAULT_CFG_PATH: &'static str = ".config/encore/encore.toml";
static DEFAULT_CFG_PATH: &str = ".config/encore/encore.toml";
#[cfg(target_os = "windows")]
static DEFAULT_CFG_PATH: &'static str = "AppData/Roaming/encore/encore.toml";
static DEFAULT_CFG_PATH: &str = "AppData/Roaming/encore/encore.toml";
#[cfg(target_os = "macos")]
static DEFAULT_CFG_PATH: &'static str = "Library/Preferences/encore/encore.toml";
static DEFAULT_CFG_PATH: &str = "Library/Preferences/encore/encore.toml";

#[derive(Debug, Default)]
#[cfg_attr(feature = "configuration", derive(serde::Deserialize))]
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Default for TomlPlaylist {
impl Config {
pub fn parse(to_parse: &encore::ConfigurationPath) -> Self {
#[cfg(not(feature = "configuration"))] {
return Config::default();
Config::default()
}

#[cfg(feature = "configuration")] {
Expand Down
4 changes: 2 additions & 2 deletions src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ static FILE_HEADERS: &[(&[u8], FileFormat, u64)] = &[
( b"RIFF", FileFormat::Audio, 0 ), // .wav
];

/// because `file-format is bloated
/// because `file-format` is bloated
/// i did it in 25 SLOC
pub fn check_file(file: &mut BufReader<File>) -> Result<&FileFormat, Box<dyn std::error::Error>> {
use std::io::SeekFrom;

let mut ret: &FileFormat = &FileFormat::Other;
for (header, format, header_offset) in FILE_HEADERS {
let mut buf = vec![0; header.len()];
if let Err(_) = file.seek(SeekFrom::Start(*header_offset)) {
if file.seek(SeekFrom::Start(*header_offset)).is_err() {
// possibly out of bounds
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/song.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub struct Song {

impl Song {
pub fn new() -> Song {
let (_stream, _stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&_stream_handle).unwrap();
let (stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let mut s = Song {
_stream_handle,
_stream,
_stream_handle: stream_handle,
_stream: stream,
sink,
total_duration: None,
};
Expand Down
54 changes: 27 additions & 27 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ impl Tui<'_> {
writeln!(self.handle, "current song index: {}, SONG_INDEX: {}, len: {}", self.cursor_index_queue, SONG_INDEX.load(Relaxed), songs.len());
self.handle.flush();
// TODO: make this only calculate once in determine_terminal_size, when size changes?
let opening_box = self.draw_box::<true>("queue", self.width);
let closing_box = self.draw_box::<false>("", self.width);
let opening_box1 = self.draw_box::<true>("", self.width);
let closing_box2 = self.draw_box::<false>("asdadsad", self.width);
let opening_box = draw_box::<true>("queue", self.width);
let closing_box = draw_box::<false>("", self.width);
let opening_box1 = draw_box::<true>("", self.width);
let closing_box2 = draw_box::<false>("asdadsad", self.width);

writeln!(self.handle, "{opening_box}");

Expand Down Expand Up @@ -159,7 +159,7 @@ impl Tui<'_> {
continue;
}

let line = songs[i + self.scrolling_offset].split("/").last().unwrap_or("");
let line = songs[i + self.scrolling_offset].split('/').last().unwrap_or("");
#[allow(unused_assignments)] let mut entry: String = String::with_capacity(self.width.into());
if i == self.cursor_index_queue {
entry = self.draw_highlighted_entry(line)?;
Expand All @@ -170,7 +170,7 @@ impl Tui<'_> {
}
write!(self.handle, "{closing_box}");

let line = songs[self.cursor_index_queue + self.scrolling_offset].split("/").last().unwrap_or("");
let line = songs[self.cursor_index_queue + self.scrolling_offset].split('/').last().unwrap_or("");
let line = self.draw_entry_centered(line)?;
// playback bar
write!(self.handle, "{opening_box1}");
Expand All @@ -191,7 +191,7 @@ impl Tui<'_> {
self.cursor_index_queue = songs.len() - 1;
SONG_INDEX.store(self.cursor_index_queue, Relaxed);
}
let song = songs[self.cursor_index_queue].split("/").last().unwrap_or("");
let song = songs[self.cursor_index_queue].split('/').last().unwrap_or("");

writeln!(self.handle, "{song}");
let current_len = format_time(crate::SONG_CURRENT_LEN.load(Relaxed));
Expand Down Expand Up @@ -281,24 +281,6 @@ impl Tui<'_> {
let out = format!("\x1B[48;2;245;194;231m\x1B[38;2;30;30;46m{text}");
Ok(box_draw_entry(&out, padding.unwrap()))
}

fn draw_box<const CLOSING: bool>(&self, text: &str, term_len: u16) -> String {
let first = if CLOSING { "╭─" } else { "╰" };
let adding = if CLOSING { 3 } else { 2 };
let closing = if CLOSING { "╮" } else { "╯" };

let trailing = if CLOSING {
"─".repeat((term_len - adding - text.len() as u16).into())
} else {
"─".repeat((term_len - adding).into())
};

if CLOSING {
format!("{}{}{}{}", first, text, trailing, closing)
} else {
format!("{}{}{}", first, trailing, closing)
}
}
}

impl Drop for Tui<'_> {
Expand All @@ -313,9 +295,9 @@ fn format_time(t: u64) -> String {
let secs = t % 60;

if hrs == 0 {
format!("{:02}:{:02}", mins, secs)
format!("{mins:02}:{secs:02}")
} else {
format!("{:02}:{:02}:{:02}", hrs, mins, secs)
format!("{hrs:02}:{mins:02}:{secs:02}")
}
}

Expand All @@ -328,3 +310,21 @@ fn box_draw_entry(text: &str, padding: usize) -> String {
format!("│{}{}{}", text, &" ".repeat(padding), "\x1B[0m│")
}

fn draw_box<const CLOSING: bool>(text: &str, term_len: u16) -> String {
let first = if CLOSING { "╭─" } else { "╰" };
let adding = if CLOSING { 3 } else { 2 };
let closing = if CLOSING { "╮" } else { "╯" };

let trailing = if CLOSING {
"─".repeat((term_len - adding - text.len() as u16).into())
} else {
"─".repeat((term_len - adding).into())
};

if CLOSING {
format!("{first}{text}{trailing}{closing}")
} else {
format!("{first}{trailing}{closing}")
}
}

0 comments on commit 7adb481

Please sign in to comment.