forked from trinitrix/core
1
0
Fork 0

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 {
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 {

View File

@ -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 {

View File

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

View File

@ -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::*;

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

View File

@ -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,

View File

@ -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<EventStatus> {
pub async fn handle(app: &mut App<'_>, sync: &SyncResponse) -> Result<EventStatus> {
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,

View File

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

View File

@ -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),

View File

@ -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::*};

View File

@ -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!");
}

View File

@ -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 {

View File

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

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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};

View File

@ -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};

View File

@ -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},