Cleaned up imports a bit and added rustfmt.toml

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent 0d4e283c21
commit 155675b596
6 changed files with 182 additions and 179 deletions
+10
View File
@@ -0,0 +1,10 @@
tab_spaces=2
edition = "2021"
reorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
reorder_modules = true
merge_derives = true
use_field_init_shorthand = true
format_macro_matchers = true
format_macro_bodies = true
+5 -9
View File
@@ -7,8 +7,8 @@ use crate::app::radarr::RadarrData;
use super::network::RadarrEvent;
pub mod radarr;
pub(crate) mod key_binding;
pub mod radarr;
#[derive(Debug)]
pub struct App {
@@ -22,11 +22,7 @@ pub struct App {
}
impl App {
pub fn new(
network_tx: Sender<RadarrEvent>,
tick_until_poll: u64,
config: AppConfig
) -> Self {
pub fn new(network_tx: Sender<RadarrEvent>, tick_until_poll: u64, config: AppConfig) -> Self {
App {
network_tx: Some(network_tx),
tick_until_poll,
@@ -66,7 +62,7 @@ impl Default for App {
tick_until_poll: 0,
tick_count: 0,
config: AppConfig::default(),
data: Data::default()
data: Data::default(),
}
}
}
@@ -85,7 +81,7 @@ pub struct AppConfig {
pub struct RadarrConfig {
pub host: String,
pub port: Option<u16>,
pub api_token: String
pub api_token: String,
}
impl Default for RadarrConfig {
@@ -93,7 +89,7 @@ impl Default for RadarrConfig {
RadarrConfig {
host: "localhost".to_string(),
port: Some(7878),
api_token: "".to_string()
api_token: "".to_string(),
}
}
}
+4 -3
View File
@@ -10,12 +10,12 @@ use crate::event::Key;
pub enum InputEvent<T> {
KeyEvent(T),
Tick
Tick,
}
pub struct Events {
_tx: Sender<InputEvent<Key>>,
rx: Receiver<InputEvent<Key>>
rx: Receiver<InputEvent<Key>>,
}
impl Events {
@@ -27,7 +27,8 @@ impl Events {
thread::spawn(move || {
let mut last_tick = Instant::now();
loop {
let timeout = tick_rate.checked_sub(last_tick.elapsed())
let timeout = tick_rate
.checked_sub(last_tick.elapsed())
.unwrap_or_else(|| Duration::from_secs(0));
if event::poll(timeout).unwrap() {
if let CrosstermEvent::Key(key) = event::read().unwrap() {
+7 -4
View File
@@ -6,14 +6,14 @@ use crossterm::event::{KeyCode, KeyEvent};
#[derive(Debug, PartialEq, Eq)]
pub enum Key {
Char(char),
Unknown
Unknown,
}
impl Display for Key {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self {
Key::Char(c) => write!(f, "<{}>", c),
_ => write!(f, "<{:?}>", self)
_ => write!(f, "<{:?}>", self),
}
}
}
@@ -25,7 +25,7 @@ impl From<KeyEvent> for Key {
code: KeyCode::Char(c),
..
} => Key::Char(c),
_ => Key::Unknown
_ => Key::Unknown,
}
}
}
@@ -43,6 +43,9 @@ mod tests {
#[test]
fn test_key_from() {
assert_eq!(Key::from(KeyEvent::from(KeyCode::Char('q'))), Key::Char('q'))
assert_eq!(
Key::from(KeyEvent::from(KeyCode::Char('q'))),
Key::Char('q')
)
}
}
+8 -15
View File
@@ -1,16 +1,17 @@
use std::io;
use std::sync::Arc;
use std::time::{Duration, Instant};
use anyhow::Result;
use clap::Parser;
use crossterm::execute;
use crossterm::terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen};
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
};
use log::{debug, info};
use tokio::sync::{mpsc, Mutex};
use tokio::sync::mpsc::Receiver;
use tui::Terminal;
use tokio::sync::{mpsc, Mutex};
use tui::backend::CrosstermBackend;
use tui::Terminal;
use utils::init_logging_config;
@@ -29,9 +30,7 @@ mod utils;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
}
struct Cli {}
#[tokio::main]
async fn main() -> Result<()> {
@@ -41,11 +40,7 @@ async fn main() -> Result<()> {
let config = confy::load("managarr", "config")?;
let (sync_network_tx, sync_network_rx) = mpsc::channel(500);
let app = Arc::new(Mutex::new(App::new(
sync_network_tx,
5000 / 250,
config
)));
let app = Arc::new(Mutex::new(App::new(sync_network_tx, 5000 / 250, config)));
let app_nw = Arc::clone(&app);
@@ -91,9 +86,7 @@ async fn simple_ui(app: &Arc<Mutex<App>>) -> Result<()> {
break;
}
}
InputEvent::Tick => {
app.on_tick().await
}
InputEvent::Tick => app.on_tick().await,
}
}
+2 -2
View File
@@ -10,13 +10,13 @@ pub(crate) mod radarr;
#[derive(Debug, Eq, PartialEq, Hash)]
pub enum RadarrEvent {
HealthCheck,
GetOverview
GetOverview,
}
pub struct Network<'a> {
pub client: Client,
pub app: &'a Arc<Mutex<App>>
pub app: &'a Arc<Mutex<App>>,
}
impl<'a> Network<'a> {