From 6745da4c715f56ac314429c3f567f64f36e3492a Mon Sep 17 00:00:00 2001 From: Soispha Date: Wed, 20 Sep 2023 19:22:56 +0200 Subject: [PATCH] style(treewide): Apply consistent formatting I just ran `cargo fmt -- --config reorder_imports=true,imports_granularity=Crate,group_imp orts=StdExternalCrate` --- src/accounts/mod.rs | 7 +++-- src/app/command_interface/command_list/mod.rs | 2 +- .../command_transfer_value/mod.rs | 1 - src/app/command_interface/mod.rs | 2 +- .../event_types/event/handlers/lua_command.rs | 5 +--- .../events/event_types/event/handlers/main.rs | 26 ++++++++++--------- .../event_types/event/handlers/matrix.rs | 5 +--- .../event_types/event/handlers/setup.rs | 5 +--- src/app/events/event_types/event/mod.rs | 6 ++--- src/app/events/event_types/mod.rs | 3 +-- src/app/mod.rs | 8 ++---- src/app/status.rs | 2 +- src/main.rs | 4 +-- src/ui/central/mod.rs | 6 ++--- src/ui/central/update/mod.rs | 10 ++++--- src/ui/central/update/widgets/mod.rs | 2 +- src/ui/central/update/widgets/room_info.rs | 3 ++- src/ui/central/update/widgets/rooms.rs | 2 +- src/ui/setup.rs | 2 +- 19 files changed, 43 insertions(+), 58 deletions(-) diff --git a/src/accounts/mod.rs b/src/accounts/mod.rs index 0b5a3a3..b9311eb 100644 --- a/src/accounts/mod.rs +++ b/src/accounts/mod.rs @@ -43,8 +43,7 @@ impl AccountsManager { return match config { Some(s) => { info!("Loading serialized AccountsManager"); - let accounts_data: AccountsData = - serde_json::from_str(&s)?; + let accounts_data: AccountsData = serde_json::from_str(&s)?; let mut clients = Vec::new(); clients.resize(accounts_data.accounts.len(), None); Ok(Self { @@ -94,12 +93,12 @@ impl AccountsManager { let session = match client.session() { Some(s) => s, - None => return Err(Error::msg("Failed to get session")) + None => return Err(Error::msg("Failed to get session")), }; let name = match client.account().get_display_name().await? { Some(n) => n, - None => return Err(Error::msg("Failed to get display name")) + None => return Err(Error::msg("Failed to get display name")), }; let account = Account { diff --git a/src/app/command_interface/command_list/mod.rs b/src/app/command_interface/command_list/mod.rs index fb93c7b..8237e6c 100644 --- a/src/app/command_interface/command_list/mod.rs +++ b/src/app/command_interface/command_list/mod.rs @@ -5,9 +5,9 @@ use language_macros::parse_command_enum; // TODO(@soispha): Should these paths be moved to the proc macro? // As they are not static, it could be easier for other people, // if they stay here. +use mlua::IntoLua; use crate::app::command_interface::command_transfer_value::CommandTransferValue; use crate::app::Event; -use mlua::IntoLua; parse_command_enum! { commands { diff --git a/src/app/command_interface/command_transfer_value/mod.rs b/src/app/command_interface/command_transfer_value/mod.rs index 77cde3a..44e16fc 100644 --- a/src/app/command_interface/command_transfer_value/mod.rs +++ b/src/app/command_interface/command_transfer_value/mod.rs @@ -1,6 +1,5 @@ use std::{collections::HashMap, fmt::Display}; -use mlua::FromLua; use serde::{Deserialize, Serialize}; pub mod type_conversions; diff --git a/src/app/command_interface/mod.rs b/src/app/command_interface/mod.rs index c359734..c2bc7c8 100644 --- a/src/app/command_interface/mod.rs +++ b/src/app/command_interface/mod.rs @@ -1,5 +1,5 @@ +pub mod command_list; pub mod command_transfer_value; pub mod lua_command_manager; -pub mod command_list; pub use command_list::*; diff --git a/src/app/events/event_types/event/handlers/lua_command.rs b/src/app/events/event_types/event/handlers/lua_command.rs index 9111330..959ddad 100644 --- a/src/app/events/event_types/event/handlers/lua_command.rs +++ b/src/app/events/event_types/event/handlers/lua_command.rs @@ -5,10 +5,7 @@ use crate::app::{events::event_types::EventStatus, App}; // This function is here mainly to reserve this spot for further processing of the lua command. // TODO(@Soispha): Move the lua executor thread code from app to this module -pub async fn handle( - app: &mut App<'_>, - command: String, -) -> Result { +pub async fn handle(app: &mut App<'_>, command: String) -> Result { trace!("Recieved ci command: `{command}`; executing.."); app.lua.execute_code(command).await; diff --git a/src/app/events/event_types/event/handlers/main.rs b/src/app/events/event_types/event/handlers/main.rs index 64bb632..acfe450 100644 --- a/src/app/events/event_types/event/handlers/main.rs +++ b/src/app/events/event_types/event/handlers/main.rs @@ -3,7 +3,12 @@ use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers} use crate::{ app::{ - command_interface::{Api, Command, Trinitrix, Ui}, + command_interface::{ + Api::{Exit, Ui, RoomMessageSend}, + Command, + Trinitrix::Api, + Ui::{CommandLineShow, CyclePlanes, CyclePlanesRev, SetModeInsert, SetModeNormal}, + }, events::event_types::{Event, EventStatus}, App, }, @@ -21,7 +26,7 @@ pub async fn handle_command( }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeNormal))), + Command::Trinitrix(Api(Ui(SetModeNormal))), None, )) .await?; @@ -65,10 +70,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R .. }) => { app.tx - .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Exit)), - None, - )) + .send(Event::CommandEvent(Command::Trinitrix(Api(Exit)), None)) .await?; } CrosstermEvent::Key(KeyEvent { @@ -76,7 +78,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CyclePlanes))), + Command::Trinitrix(Api(Ui(CyclePlanes))), None, )) .await?; @@ -87,7 +89,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CyclePlanesRev))), + Command::Trinitrix(Api(Ui(CyclePlanesRev))), None, )) .await?; @@ -98,7 +100,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CommandLineShow))), + Command::Trinitrix(Api(Ui(CommandLineShow))), None, )) .await?; @@ -109,7 +111,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeInsert))), + Command::Trinitrix(Api(Ui(SetModeInsert))), None, )) .await?; @@ -212,7 +214,7 @@ pub async fn handle_insert(app: &mut App<'_>, event: &CrosstermEvent) -> Result< }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeNormal))), + Command::Trinitrix(Api(Ui(SetModeNormal))), None, )) .await?; @@ -224,7 +226,7 @@ pub async fn handle_insert(app: &mut App<'_>, event: &CrosstermEvent) -> Result< }) => { app.tx .send(Event::CommandEvent( - Command::Trinitrix(Trinitrix::Api(Api::RoomMessageSend( + Command::Trinitrix(Api(RoomMessageSend( app.ui.message_compose.lines().join("\n"), ))), None, diff --git a/src/app/events/event_types/event/handlers/matrix.rs b/src/app/events/event_types/event/handlers/matrix.rs index 2a86034..a624a2c 100644 --- a/src/app/events/event_types/event/handlers/matrix.rs +++ b/src/app/events/event_types/event/handlers/matrix.rs @@ -3,10 +3,7 @@ use matrix_sdk::deserialized_responses::SyncResponse; use crate::app::{events::event_types::EventStatus, App}; -pub async fn handle( - app: &mut App<'_>, - sync: &SyncResponse, -) -> Result { +pub async fn handle(app: &mut App<'_>, sync: &SyncResponse) -> Result { for (m_room_id, m_room) in sync.rooms.join.iter() { let room = match app.status.get_room_mut(m_room_id) { Some(r) => r, diff --git a/src/app/events/event_types/event/handlers/setup.rs b/src/app/events/event_types/event/handlers/setup.rs index d879e99..ab16965 100644 --- a/src/app/events/event_types/event/handlers/setup.rs +++ b/src/app/events/event_types/event/handlers/setup.rs @@ -6,10 +6,7 @@ use crate::{ ui::setup, }; -pub async fn handle( - app: &mut App<'_>, - input_event: &CrosstermEvent, -) -> Result { +pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result { let ui = match &mut app.ui.setup_ui { Some(ui) => ui, None => bail!("SetupUI instance not found"), diff --git a/src/app/events/event_types/event/mod.rs b/src/app/events/event_types/event/mod.rs index 8535c01..dd2e131 100644 --- a/src/app/events/event_types/event/mod.rs +++ b/src/app/events/event_types/event/mod.rs @@ -5,16 +5,14 @@ use cli_log::trace; use crossterm::event::Event as CrosstermEvent; use tokio::sync::oneshot; +use self::handlers::{command, lua_command, main, matrix, setup}; +use super::EventStatus; use crate::app::{ command_interface::{command_transfer_value::CommandTransferValue, Command}, status::State, App, }; -use self::handlers::{command, lua_command, main, matrix, setup}; - -use super::EventStatus; - #[derive(Debug)] pub enum Event { InputEvent(CrosstermEvent), diff --git a/src/app/events/event_types/mod.rs b/src/app/events/event_types/mod.rs index 78356d6..b89c71c 100644 --- a/src/app/events/event_types/mod.rs +++ b/src/app/events/event_types/mod.rs @@ -1,5 +1,4 @@ pub mod event; pub mod event_status; -pub use self::event::*; -pub use self::event_status::*; +pub use self::{event::*, event_status::*}; diff --git a/src/app/mod.rs b/src/app/mod.rs index 3fb1ff6..dfd53cd 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -12,6 +12,7 @@ use matrix_sdk::Client; use tokio::sync::mpsc; use tokio_util::sync::CancellationToken; +use self::{command_interface::lua_command_manager::LuaCommandManager, events::event_types}; use crate::{ accounts::{Account, AccountsManager}, app::{ @@ -21,8 +22,6 @@ use crate::{ ui::{central, setup}, }; -use self::{command_interface::lua_command_manager::LuaCommandManager, events::event_types}; - pub struct App<'ui> { ui: central::UI<'ui>, accounts_manager: AccountsManager, @@ -84,10 +83,7 @@ impl App<'_> { .context("Failed to search for a config file")? { lua_config_file = Some(config_dir.join("init.lua")); - info!( - "Found config dir: `{}`", - config_dir.display() - ); + info!("Found config dir: `{}`", config_dir.display()); } else { warn!("No config dir found!"); } diff --git a/src/app/status.rs b/src/app/status.rs index 8b9168b..da0f607 100644 --- a/src/app/status.rs +++ b/src/app/status.rs @@ -156,7 +156,7 @@ impl Status { state: State::Normal, account_name: "".to_owned(), account_user_id: "".to_owned(), - client, + client, rooms, current_room_id: "".to_owned(), status_messages: vec![StatusMessage { diff --git a/src/main.rs b/src/main.rs index 964f61f..8c56f5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ -mod app; -mod ui; mod accounts; +mod app; mod cli; +mod ui; use clap::Parser; diff --git a/src/ui/central/mod.rs b/src/ui/central/mod.rs index c889406..a37d43c 100644 --- a/src/ui/central/mod.rs +++ b/src/ui/central/mod.rs @@ -16,12 +16,10 @@ use tui::{ Terminal, }; use tui_textarea::TextArea; - -use crate::ui::{terminal_prepare, textarea_inactivate, textarea_activate}; +pub use update::*; use super::setup; - -pub use update::*; +use crate::ui::{terminal_prepare, textarea_activate, textarea_inactivate}; #[derive(Clone, Copy, PartialEq)] pub enum InputPosition { diff --git a/src/ui/central/update/mod.rs b/src/ui/central/update/mod.rs index fcd06b0..76d56ea 100644 --- a/src/ui/central/update/mod.rs +++ b/src/ui/central/update/mod.rs @@ -1,13 +1,15 @@ use std::cmp; use anyhow::{Context, Result}; -use tui::{layout::{Constraint, Direction, Layout}, widgets::{Paragraph, Block, Borders}, style::{Style, Color}}; - -use crate::app::status::Status; +use tui::{ + layout::{Constraint, Direction, Layout}, + style::{Color, Style}, + widgets::{Block, Borders, Paragraph}, +}; use self::widgets::{command_monitor, messages, room_info, rooms, status}; - use super::UI; +use crate::app::status::Status; pub mod widgets; diff --git a/src/ui/central/update/widgets/mod.rs b/src/ui/central/update/widgets/mod.rs index d145b95..f35b656 100644 --- a/src/ui/central/update/widgets/mod.rs +++ b/src/ui/central/update/widgets/mod.rs @@ -1,5 +1,5 @@ +pub mod command_monitor; pub mod messages; pub mod room_info; pub mod rooms; pub mod status; -pub mod command_monitor; diff --git a/src/ui/central/update/widgets/room_info.rs b/src/ui/central/update/widgets/room_info.rs index 3563c55..599280c 100644 --- a/src/ui/central/update/widgets/room_info.rs +++ b/src/ui/central/update/widgets/room_info.rs @@ -1,7 +1,8 @@ use tui::{ + layout::Alignment, style::{Color, Style}, text::Text, - widgets::{Block, Borders, Paragraph}, layout::Alignment, + widgets::{Block, Borders, Paragraph}, }; use crate::{app::status::Room, ui::central::InputPosition}; diff --git a/src/ui/central/update/widgets/rooms.rs b/src/ui/central/update/widgets/rooms.rs index f981e96..feab3c9 100644 --- a/src/ui/central/update/widgets/rooms.rs +++ b/src/ui/central/update/widgets/rooms.rs @@ -1,7 +1,7 @@ use tui::{ style::{Color, Modifier, Style}, text::Span, - widgets::{Borders, List, ListItem, Block}, + widgets::{Block, Borders, List, ListItem}, }; use crate::{app::status::Status, ui::central::InputPosition}; diff --git a/src/ui/setup.rs b/src/ui/setup.rs index da339b2..b336452 100644 --- a/src/ui/setup.rs +++ b/src/ui/setup.rs @@ -3,7 +3,7 @@ use std::io::Stdout; use anyhow::Result; use tui::{ backend::CrosstermBackend, - layout::{Constraint, Direction, Layout, Alignment}, + layout::{Alignment, Constraint, Direction, Layout}, style::{Color, Modifier, Style}, text::Span, widgets::{Block, Borders, Paragraph},