style(treewide): Apply consistent formatting

I just ran `cargo fmt -- --config reorder_imports=true,imports_granularity=Crate,group_imp
orts=StdExternalCrate`
This commit is contained in:
Benedikt Peetz 2023-09-20 19:22:56 +02:00
parent 27d00c564c
commit 6745da4c71
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
19 changed files with 43 additions and 58 deletions

View File

@ -43,8 +43,7 @@ impl AccountsManager {
return match config { return match config {
Some(s) => { Some(s) => {
info!("Loading serialized AccountsManager"); info!("Loading serialized AccountsManager");
let accounts_data: AccountsData = let accounts_data: AccountsData = serde_json::from_str(&s)?;
serde_json::from_str(&s)?;
let mut clients = Vec::new(); let mut clients = Vec::new();
clients.resize(accounts_data.accounts.len(), None); clients.resize(accounts_data.accounts.len(), None);
Ok(Self { Ok(Self {
@ -94,12 +93,12 @@ impl AccountsManager {
let session = match client.session() { let session = match client.session() {
Some(s) => s, 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? { let name = match client.account().get_display_name().await? {
Some(n) => n, 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 { let account = Account {

View File

@ -5,9 +5,9 @@ use language_macros::parse_command_enum;
// TODO(@soispha): Should these paths be moved to the proc macro? // TODO(@soispha): Should these paths be moved to the proc macro?
// As they are not static, it could be easier for other people, // As they are not static, it could be easier for other people,
// if they stay here. // if they stay here.
use mlua::IntoLua;
use crate::app::command_interface::command_transfer_value::CommandTransferValue; use crate::app::command_interface::command_transfer_value::CommandTransferValue;
use crate::app::Event; use crate::app::Event;
use mlua::IntoLua;
parse_command_enum! { parse_command_enum! {
commands { commands {

View File

@ -1,6 +1,5 @@
use std::{collections::HashMap, fmt::Display}; use std::{collections::HashMap, fmt::Display};
use mlua::FromLua;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod type_conversions; pub mod type_conversions;

View File

@ -1,5 +1,5 @@
pub mod command_list;
pub mod command_transfer_value; pub mod command_transfer_value;
pub mod lua_command_manager; pub mod lua_command_manager;
pub mod command_list;
pub use command_list::*; pub use command_list::*;

View File

@ -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. // 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 // TODO(@Soispha): Move the lua executor thread code from app to this module
pub async fn handle( pub async fn handle(app: &mut App<'_>, command: String) -> Result<EventStatus> {
app: &mut App<'_>,
command: String,
) -> Result<EventStatus> {
trace!("Recieved ci command: `{command}`; executing.."); trace!("Recieved ci command: `{command}`; executing..");
app.lua.execute_code(command).await; app.lua.execute_code(command).await;

View File

@ -3,7 +3,12 @@ use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers}
use crate::{ use crate::{
app::{ 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}, events::event_types::{Event, EventStatus},
App, App,
}, },
@ -21,7 +26,7 @@ pub async fn handle_command(
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeNormal))), Command::Trinitrix(Api(Ui(SetModeNormal))),
None, None,
)) ))
.await?; .await?;
@ -65,10 +70,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R
.. ..
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(Command::Trinitrix(Api(Exit)), None))
Command::Trinitrix(Trinitrix::Api(Api::Exit)),
None,
))
.await?; .await?;
} }
CrosstermEvent::Key(KeyEvent { CrosstermEvent::Key(KeyEvent {
@ -76,7 +78,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CyclePlanes))), Command::Trinitrix(Api(Ui(CyclePlanes))),
None, None,
)) ))
.await?; .await?;
@ -87,7 +89,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CyclePlanesRev))), Command::Trinitrix(Api(Ui(CyclePlanesRev))),
None, None,
)) ))
.await?; .await?;
@ -98,7 +100,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::CommandLineShow))), Command::Trinitrix(Api(Ui(CommandLineShow))),
None, None,
)) ))
.await?; .await?;
@ -109,7 +111,7 @@ pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> R
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeInsert))), Command::Trinitrix(Api(Ui(SetModeInsert))),
None, None,
)) ))
.await?; .await?;
@ -212,7 +214,7 @@ pub async fn handle_insert(app: &mut App<'_>, event: &CrosstermEvent) -> Result<
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::Ui(Ui::SetModeNormal))), Command::Trinitrix(Api(Ui(SetModeNormal))),
None, None,
)) ))
.await?; .await?;
@ -224,7 +226,7 @@ pub async fn handle_insert(app: &mut App<'_>, event: &CrosstermEvent) -> Result<
}) => { }) => {
app.tx app.tx
.send(Event::CommandEvent( .send(Event::CommandEvent(
Command::Trinitrix(Trinitrix::Api(Api::RoomMessageSend( Command::Trinitrix(Api(RoomMessageSend(
app.ui.message_compose.lines().join("\n"), app.ui.message_compose.lines().join("\n"),
))), ))),
None, None,

View File

@ -3,10 +3,7 @@ use matrix_sdk::deserialized_responses::SyncResponse;
use crate::app::{events::event_types::EventStatus, App}; use crate::app::{events::event_types::EventStatus, App};
pub async fn handle( pub async fn handle(app: &mut App<'_>, sync: &SyncResponse) -> Result<EventStatus> {
app: &mut App<'_>,
sync: &SyncResponse,
) -> Result<EventStatus> {
for (m_room_id, m_room) in sync.rooms.join.iter() { for (m_room_id, m_room) in sync.rooms.join.iter() {
let room = match app.status.get_room_mut(m_room_id) { let room = match app.status.get_room_mut(m_room_id) {
Some(r) => r, Some(r) => r,

View File

@ -6,10 +6,7 @@ use crate::{
ui::setup, ui::setup,
}; };
pub async fn handle( pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<EventStatus> {
app: &mut App<'_>,
input_event: &CrosstermEvent,
) -> Result<EventStatus> {
let ui = match &mut app.ui.setup_ui { let ui = match &mut app.ui.setup_ui {
Some(ui) => ui, Some(ui) => ui,
None => bail!("SetupUI instance not found"), None => bail!("SetupUI instance not found"),

View File

@ -5,16 +5,14 @@ use cli_log::trace;
use crossterm::event::Event as CrosstermEvent; use crossterm::event::Event as CrosstermEvent;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use self::handlers::{command, lua_command, main, matrix, setup};
use super::EventStatus;
use crate::app::{ use crate::app::{
command_interface::{command_transfer_value::CommandTransferValue, Command}, command_interface::{command_transfer_value::CommandTransferValue, Command},
status::State, status::State,
App, App,
}; };
use self::handlers::{command, lua_command, main, matrix, setup};
use super::EventStatus;
#[derive(Debug)] #[derive(Debug)]
pub enum Event { pub enum Event {
InputEvent(CrosstermEvent), InputEvent(CrosstermEvent),

View File

@ -1,5 +1,4 @@
pub mod event; pub mod event;
pub mod event_status; pub mod event_status;
pub use self::event::*; pub use self::{event::*, event_status::*};
pub use self::event_status::*;

View File

@ -12,6 +12,7 @@ use matrix_sdk::Client;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
use self::{command_interface::lua_command_manager::LuaCommandManager, events::event_types};
use crate::{ use crate::{
accounts::{Account, AccountsManager}, accounts::{Account, AccountsManager},
app::{ app::{
@ -21,8 +22,6 @@ use crate::{
ui::{central, setup}, ui::{central, setup},
}; };
use self::{command_interface::lua_command_manager::LuaCommandManager, events::event_types};
pub struct App<'ui> { pub struct App<'ui> {
ui: central::UI<'ui>, ui: central::UI<'ui>,
accounts_manager: AccountsManager, accounts_manager: AccountsManager,
@ -84,10 +83,7 @@ impl App<'_> {
.context("Failed to search for a config file")? .context("Failed to search for a config file")?
{ {
lua_config_file = Some(config_dir.join("init.lua")); lua_config_file = Some(config_dir.join("init.lua"));
info!( info!("Found config dir: `{}`", config_dir.display());
"Found config dir: `{}`",
config_dir.display()
);
} else { } else {
warn!("No config dir found!"); warn!("No config dir found!");
} }

View File

@ -156,7 +156,7 @@ impl Status {
state: State::Normal, state: State::Normal,
account_name: "".to_owned(), account_name: "".to_owned(),
account_user_id: "".to_owned(), account_user_id: "".to_owned(),
client, client,
rooms, rooms,
current_room_id: "".to_owned(), current_room_id: "".to_owned(),
status_messages: vec![StatusMessage { status_messages: vec![StatusMessage {

View File

@ -1,7 +1,7 @@
mod app;
mod ui;
mod accounts; mod accounts;
mod app;
mod cli; mod cli;
mod ui;
use clap::Parser; use clap::Parser;

View File

@ -16,12 +16,10 @@ use tui::{
Terminal, Terminal,
}; };
use tui_textarea::TextArea; use tui_textarea::TextArea;
pub use update::*;
use crate::ui::{terminal_prepare, textarea_inactivate, textarea_activate};
use super::setup; use super::setup;
use crate::ui::{terminal_prepare, textarea_activate, textarea_inactivate};
pub use update::*;
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
pub enum InputPosition { pub enum InputPosition {

View File

@ -1,13 +1,15 @@
use std::cmp; use std::cmp;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use tui::{layout::{Constraint, Direction, Layout}, widgets::{Paragraph, Block, Borders}, style::{Style, Color}}; use tui::{
layout::{Constraint, Direction, Layout},
use crate::app::status::Status; style::{Color, Style},
widgets::{Block, Borders, Paragraph},
};
use self::widgets::{command_monitor, messages, room_info, rooms, status}; use self::widgets::{command_monitor, messages, room_info, rooms, status};
use super::UI; use super::UI;
use crate::app::status::Status;
pub mod widgets; pub mod widgets;

View File

@ -1,5 +1,5 @@
pub mod command_monitor;
pub mod messages; pub mod messages;
pub mod room_info; pub mod room_info;
pub mod rooms; pub mod rooms;
pub mod status; pub mod status;
pub mod command_monitor;

View File

@ -1,7 +1,8 @@
use tui::{ use tui::{
layout::Alignment,
style::{Color, Style}, style::{Color, Style},
text::Text, text::Text,
widgets::{Block, Borders, Paragraph}, layout::Alignment, widgets::{Block, Borders, Paragraph},
}; };
use crate::{app::status::Room, ui::central::InputPosition}; use crate::{app::status::Room, ui::central::InputPosition};

View File

@ -1,7 +1,7 @@
use tui::{ use tui::{
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
text::Span, text::Span,
widgets::{Borders, List, ListItem, Block}, widgets::{Block, Borders, List, ListItem},
}; };
use crate::{app::status::Status, ui::central::InputPosition}; use crate::{app::status::Status, ui::central::InputPosition};

View File

@ -3,7 +3,7 @@ use std::io::Stdout;
use anyhow::Result; use anyhow::Result;
use tui::{ use tui::{
backend::CrosstermBackend, backend::CrosstermBackend,
layout::{Constraint, Direction, Layout, Alignment}, layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
text::Span, text::Span,
widgets::{Block, Borders, Paragraph}, widgets::{Block, Borders, Paragraph},