From fbc64de60713c8e7f065ad36ca055be9bf4f1b8d Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 21 Feb 2025 12:42:51 +0100 Subject: [PATCH] Merge and reorder imports This change brings them in-line with the default settings of rust-analyzer. Originally, I disliked this style, but by now, I've grown used to it and prefer it slightly. Also, I like staying on the default path since I usually don't need to check the imports to see if rust-analyzer messed anything up (except for omitting the self:: when importing modules defined in the current module, grr :D). I've also come around to the idea of trailing mod definitions instead of putting them at the top: I would also put module definitions that contain code instead of referencing another file below the imports. It feels weird to have code above imports. So it just makes sense to do the same for all types of mod definitions. If rustfmt ever gains stable support for grouping imports, I'll probably use that instead. --- .vscode/settings.json | 2 +- cove-config/src/doc.rs | 3 +- cove-config/src/lib.rs | 19 ++++++----- cove-input/src/keys.rs | 7 ++-- cove-input/src/lib.rs | 7 ++-- cove-macro/src/document.rs | 3 +- cove-macro/src/key_group.rs | 3 +- cove-macro/src/util.rs | 7 ++-- cove/src/euph.rs | 8 ++--- cove/src/euph/room.rs | 24 ++++++------- cove/src/euph/small_message.rs | 3 +- cove/src/export.rs | 12 ++++--- cove/src/export/text.rs | 4 +-- cove/src/logger.rs | 10 +++--- cove/src/main.rs | 33 +++++++++--------- cove/src/store.rs | 5 +-- cove/src/ui.rs | 52 ++++++++++++++-------------- cove/src/ui/chat.rs | 32 +++++++++--------- cove/src/ui/chat/cursor.rs | 3 +- cove/src/ui/chat/tree.rs | 22 ++++++------ cove/src/ui/chat/tree/renderer.rs | 27 +++++++++------ cove/src/ui/chat/tree/scroll.rs | 16 +++++---- cove/src/ui/chat/tree/widgets.rs | 18 ++++++---- cove/src/ui/chat/widgets.rs | 6 ++-- cove/src/ui/euph/account.rs | 16 +++++---- cove/src/ui/euph/auth.rs | 10 +++--- cove/src/ui/euph/inspect.rs | 12 +++---- cove/src/ui/euph/links.rs | 15 +++++---- cove/src/ui/euph/nick.rs | 10 +++--- cove/src/ui/euph/nick_list.rs | 22 ++++++++---- cove/src/ui/euph/popup.rs | 6 ++-- cove/src/ui/euph/room.rs | 48 ++++++++++++++++---------- cove/src/ui/key_bindings.rs | 12 ++++--- cove/src/ui/rooms.rs | 56 +++++++++++++++++++------------ cove/src/ui/rooms/connect.rs | 13 ++++--- cove/src/ui/rooms/delete.rs | 13 ++++--- cove/src/ui/widgets.rs | 6 ++-- cove/src/ui/widgets/popup.rs | 6 ++-- cove/src/util.rs | 3 +- cove/src/vault.rs | 16 ++++----- cove/src/vault/euph.rs | 15 +++++---- 41 files changed, 332 insertions(+), 273 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a89179..4e428aa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "files.insertFinalNewline": true, "rust-analyzer.cargo.features": "all", "rust-analyzer.imports.granularity.enforce": true, - "rust-analyzer.imports.granularity.group": "module", + "rust-analyzer.imports.granularity.group": "crate", "rust-analyzer.imports.group.enable": true, "evenBetterToml.formatter.columnWidth": 100, } diff --git a/cove-config/src/doc.rs b/cove-config/src/doc.rs index 16ed3ac..35f6074 100644 --- a/cove-config/src/doc.rs +++ b/cove-config/src/doc.rs @@ -1,7 +1,6 @@ //! Auto-generate markdown documentation. -use std::collections::HashMap; -use std::path::PathBuf; +use std::{collections::HashMap, path::PathBuf}; use cove_input::KeyBinding; pub use cove_macro::Document; diff --git a/cove-config/src/lib.rs b/cove-config/src/lib.rs index 026ce9e..0d350ed 100644 --- a/cove-config/src/lib.rs +++ b/cove-config/src/lib.rs @@ -1,16 +1,17 @@ -pub mod doc; -mod euph; -mod keys; - -use std::io::ErrorKind; -use std::path::{Path, PathBuf}; -use std::{fs, io}; +use std::{ + fs, + io::{self, ErrorKind}, + path::{Path, PathBuf}, +}; use doc::Document; use serde::Deserialize; -pub use crate::euph::*; -pub use crate::keys::*; +pub use crate::{euph::*, keys::*}; + +pub mod doc; +mod euph; +mod keys; #[derive(Debug, thiserror::Error)] pub enum Error { diff --git a/cove-input/src/keys.rs b/cove-input/src/keys.rs index 7e5cfa0..8d2fdf1 100644 --- a/cove-input/src/keys.rs +++ b/cove-input/src/keys.rs @@ -1,10 +1,7 @@ -use std::fmt; -use std::num::ParseIntError; -use std::str::FromStr; +use std::{fmt, num::ParseIntError, str::FromStr}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; -use serde::{Deserialize, Deserializer, de::Error}; -use serde::{Serialize, Serializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error}; use serde_either::SingleOrVec; #[derive(Debug, thiserror::Error)] diff --git a/cove-input/src/lib.rs b/cove-input/src/lib.rs index c15c4c3..f6b2e92 100644 --- a/cove-input/src/lib.rs +++ b/cove-input/src/lib.rs @@ -1,7 +1,4 @@ -mod keys; - -use std::io; -use std::sync::Arc; +use std::{io, sync::Arc}; pub use cove_macro::KeyGroup; use crossterm::event::{Event, KeyEvent, KeyEventKind}; @@ -10,6 +7,8 @@ use toss::{Frame, Terminal, WidthDb}; pub use crate::keys::*; +mod keys; + pub struct KeyBindingInfo<'a> { pub name: &'static str, pub binding: &'a KeyBinding, diff --git a/cove-macro/src/document.rs b/cove-macro/src/document.rs index e8e248e..afec84d 100644 --- a/cove-macro/src/document.rs +++ b/cove-macro/src/document.rs @@ -1,7 +1,6 @@ use proc_macro2::TokenStream; use quote::quote; -use syn::spanned::Spanned; -use syn::{Data, DataEnum, DataStruct, DeriveInput, Field, Ident, LitStr}; +use syn::{Data, DataEnum, DataStruct, DeriveInput, Field, Ident, LitStr, spanned::Spanned}; use crate::util::{self, SerdeDefault}; diff --git a/cove-macro/src/key_group.rs b/cove-macro/src/key_group.rs index 84d8cff..832bfd3 100644 --- a/cove-macro/src/key_group.rs +++ b/cove-macro/src/key_group.rs @@ -1,7 +1,6 @@ use proc_macro2::TokenStream; use quote::quote; -use syn::spanned::Spanned; -use syn::{Data, DeriveInput}; +use syn::{Data, DeriveInput, spanned::Spanned}; use crate::util; diff --git a/cove-macro/src/util.rs b/cove-macro/src/util.rs index b7bf62a..d73b7ca 100644 --- a/cove-macro/src/util.rs +++ b/cove-macro/src/util.rs @@ -1,8 +1,9 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn::parse::Parse; -use syn::punctuated::Punctuated; -use syn::{Attribute, Expr, ExprLit, ExprPath, Field, Lit, LitStr, Path, Token, Type}; +use syn::{ + Attribute, Expr, ExprLit, ExprPath, Field, Lit, LitStr, Path, Token, Type, parse::Parse, + punctuated::Punctuated, +}; pub fn bail(span: Span, message: &str) -> syn::Result { Err(syn::Error::new(span, message)) diff --git a/cove/src/euph.rs b/cove/src/euph.rs index ab93753..d1fd872 100644 --- a/cove/src/euph.rs +++ b/cove/src/euph.rs @@ -1,7 +1,7 @@ -mod room; -mod small_message; -mod util; - pub use room::*; pub use small_message::*; pub use util::*; + +mod room; +mod small_message; +mod util; diff --git a/cove/src/euph/room.rs b/cove/src/euph/room.rs index 64ddfe6..17aafe4 100644 --- a/cove/src/euph/room.rs +++ b/cove/src/euph/room.rs @@ -1,21 +1,19 @@ // TODO Remove rl2dev-specific code -use std::convert::Infallible; -use std::time::Duration; +use std::{convert::Infallible, time::Duration}; -use euphoxide::api::packet::ParsedPacket; -use euphoxide::api::{ - Auth, AuthOption, Data, Log, Login, Logout, MessageId, Nick, Send, SendEvent, SendReply, Time, - UserId, +use euphoxide::{ + api::{ + Auth, AuthOption, Data, Log, Login, Logout, MessageId, Nick, Send, SendEvent, SendReply, + Time, UserId, packet::ParsedPacket, + }, + bot::instance::{ConnSnapshot, Event, Instance, InstanceConfig}, + conn::{self, ConnTx, Joined}, }; -use euphoxide::bot::instance::{ConnSnapshot, Event, Instance, InstanceConfig}; -use euphoxide::conn::{self, ConnTx, Joined}; -use log::{debug, error, info, warn}; -use tokio::select; -use tokio::sync::oneshot; +use log::{debug, info, warn}; +use tokio::{select, sync::oneshot}; -use crate::macros::logging_unwrap; -use crate::vault::EuphRoomVault; +use crate::{macros::logging_unwrap, vault::EuphRoomVault}; const LOG_INTERVAL: Duration = Duration::from_secs(10); diff --git a/cove/src/euph/small_message.rs b/cove/src/euph/small_message.rs index 994b0ae..20596fa 100644 --- a/cove/src/euph/small_message.rs +++ b/cove/src/euph/small_message.rs @@ -5,8 +5,7 @@ use euphoxide::api::{MessageId, Snowflake, Time}; use jiff::Timestamp; use toss::{Style, Styled}; -use crate::store::Msg; -use crate::ui::ChatMsg; +use crate::{store::Msg, ui::ChatMsg}; use super::util; diff --git a/cove/src/export.rs b/cove/src/export.rs index 0ad9414..80db7b6 100644 --- a/cove/src/export.rs +++ b/cove/src/export.rs @@ -1,13 +1,15 @@ //! Export logs from the vault to plain text files. +use std::{ + fs::File, + io::{self, BufWriter, Write}, +}; + +use crate::vault::{EuphRoomVault, EuphVault, RoomIdentifier}; + mod json; mod text; -use std::fs::File; -use std::io::{self, BufWriter, Write}; - -use crate::vault::{EuphRoomVault, EuphVault, RoomIdentifier}; - #[derive(Debug, Clone, Copy, clap::ValueEnum)] pub enum Format { /// Human-readable tree-structured messages. diff --git a/cove/src/export/text.rs b/cove/src/export/text.rs index 23a75d8..2ca6687 100644 --- a/cove/src/export/text.rs +++ b/cove/src/export/text.rs @@ -3,9 +3,7 @@ use std::io::Write; use euphoxide::api::MessageId; use unicode_width::UnicodeWidthStr; -use crate::euph::SmallMessage; -use crate::store::Tree; -use crate::vault::EuphRoomVault; +use crate::{euph::SmallMessage, store::Tree, vault::EuphRoomVault}; const TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; const TIME_EMPTY: &str = " "; diff --git a/cove/src/logger.rs b/cove/src/logger.rs index 5574960..940e1a9 100644 --- a/cove/src/logger.rs +++ b/cove/src/logger.rs @@ -1,6 +1,4 @@ -use std::convert::Infallible; -use std::sync::Arc; -use std::vec; +use std::{convert::Infallible, sync::Arc, vec}; use async_trait::async_trait; use crossterm::style::Stylize; @@ -10,8 +8,10 @@ use parking_lot::Mutex; use tokio::sync::mpsc; use toss::{Style, Styled}; -use crate::store::{Msg, MsgStore, Path, Tree}; -use crate::ui::ChatMsg; +use crate::{ + store::{Msg, MsgStore, Path, Tree}, + ui::ChatMsg, +}; #[derive(Debug, Clone)] pub struct LogMsg { diff --git a/cove/src/main.rs b/cove/src/main.rs index fe9a9c1..642b62e 100644 --- a/cove/src/main.rs +++ b/cove/src/main.rs @@ -1,6 +1,23 @@ // TODO Remove unnecessary Debug impls and compare compile times // TODO Invoke external notification command? +use std::path::PathBuf; + +use anyhow::Context; +use clap::Parser; +use cove_config::{Config, doc::Document}; +use directories::{BaseDirs, ProjectDirs}; +use log::info; +use tokio::sync::mpsc; +use toss::Terminal; + +use crate::{ + logger::Logger, + ui::Ui, + vault::Vault, + version::{NAME, VERSION}, +}; + mod euph; mod export; mod logger; @@ -11,22 +28,6 @@ mod util; mod vault; mod version; -use std::path::PathBuf; - -use anyhow::Context; -use clap::Parser; -use cove_config::Config; -use cove_config::doc::Document; -use directories::{BaseDirs, ProjectDirs}; -use log::info; -use tokio::sync::mpsc; -use toss::Terminal; - -use crate::logger::Logger; -use crate::ui::Ui; -use crate::vault::Vault; -use crate::version::{NAME, VERSION}; - #[derive(Debug, clap::Parser)] enum Command { /// Run the client interactively (default). diff --git a/cove/src/store.rs b/cove/src/store.rs index f6c85b7..f64f71e 100644 --- a/cove/src/store.rs +++ b/cove/src/store.rs @@ -1,7 +1,4 @@ -use std::collections::HashMap; -use std::fmt::Debug; -use std::hash::Hash; -use std::vec; +use std::{collections::HashMap, fmt::Debug, hash::Hash, vec}; use async_trait::async_trait; diff --git a/cove/src/ui.rs b/cove/src/ui.rs index 0263325..1c03834 100644 --- a/cove/src/ui.rs +++ b/cove/src/ui.rs @@ -1,3 +1,30 @@ +use std::{ + convert::Infallible, + io, + sync::{Arc, Weak}, + time::{Duration, Instant}, +}; + +use cove_config::Config; +use cove_input::InputEvent; +use jiff::tz::TimeZone; +use parking_lot::FairMutex; +use tokio::{ + sync::mpsc::{self, UnboundedReceiver, UnboundedSender, error::TryRecvError}, + task, +}; +use toss::{Terminal, WidgetExt, widgets::BoxedAsync}; + +use crate::{ + logger::{LogMsg, Logger}, + macros::logging_unwrap, + util::InfallibleExt, + vault::Vault, +}; + +pub use self::chat::ChatMsg; +use self::{chat::ChatState, rooms::Rooms, widgets::ListState}; + mod chat; mod euph; mod key_bindings; @@ -5,31 +32,6 @@ mod rooms; mod util; mod widgets; -use std::convert::Infallible; -use std::io; -use std::sync::{Arc, Weak}; -use std::time::{Duration, Instant}; - -use cove_config::Config; -use cove_input::InputEvent; -use jiff::tz::TimeZone; -use parking_lot::FairMutex; -use tokio::sync::mpsc::error::TryRecvError; -use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; -use tokio::task; -use toss::widgets::BoxedAsync; -use toss::{Terminal, WidgetExt}; - -use crate::logger::{LogMsg, Logger}; -use crate::macros::logging_unwrap; -use crate::util::InfallibleExt; -use crate::vault::Vault; - -pub use self::chat::ChatMsg; -use self::chat::ChatState; -use self::rooms::Rooms; -use self::widgets::ListState; - /// Time to spend batch processing events before redrawing the screen. const EVENT_PROCESSING_TIME: Duration = Duration::from_millis(1000 / 15); // 15 fps diff --git a/cove/src/ui/chat.rs b/cove/src/ui/chat.rs index 69f5e2b..405339b 100644 --- a/cove/src/ui/chat.rs +++ b/cove/src/ui/chat.rs @@ -1,24 +1,26 @@ +use cove_config::Keys; +use cove_input::InputEvent; +use jiff::{Timestamp, tz::TimeZone}; +use toss::{ + Styled, WidgetExt, + widgets::{BoxedAsync, EditorState}, +}; + +use crate::{ + store::{Msg, MsgStore}, + util, +}; + +use super::UiError; + +use self::{cursor::Cursor, tree::TreeViewState}; + mod blocks; mod cursor; mod renderer; mod tree; mod widgets; -use cove_config::Keys; -use cove_input::InputEvent; -use jiff::Timestamp; -use jiff::tz::TimeZone; -use toss::widgets::{BoxedAsync, EditorState}; -use toss::{Styled, WidgetExt}; - -use crate::store::{Msg, MsgStore}; -use crate::util; - -use self::cursor::Cursor; -use self::tree::TreeViewState; - -use super::UiError; - pub trait ChatMsg { fn time(&self) -> Option; fn styled(&self) -> (Styled, Styled); diff --git a/cove/src/ui/chat/cursor.rs b/cove/src/ui/chat/cursor.rs index 561f4ed..87bd8fc 100644 --- a/cove/src/ui/chat/cursor.rs +++ b/cove/src/ui/chat/cursor.rs @@ -1,7 +1,6 @@ //! Common cursor movement logic. -use std::collections::HashSet; -use std::hash::Hash; +use std::{collections::HashSet, hash::Hash}; use crate::store::{Msg, MsgStore, Tree}; diff --git a/cove/src/ui/chat/tree.rs b/cove/src/ui/chat/tree.rs index 9ac31f8..043e109 100644 --- a/cove/src/ui/chat/tree.rs +++ b/cove/src/ui/chat/tree.rs @@ -2,27 +2,27 @@ // TODO Focusing on sub-trees -mod renderer; -mod scroll; -mod widgets; - use std::collections::HashSet; use async_trait::async_trait; use cove_config::Keys; use cove_input::InputEvent; use jiff::tz::TimeZone; -use toss::widgets::EditorState; -use toss::{AsyncWidget, Frame, Pos, Size, WidgetExt, WidthDb}; +use toss::{AsyncWidget, Frame, Pos, Size, WidgetExt, WidthDb, widgets::EditorState}; -use crate::store::{Msg, MsgStore}; -use crate::ui::{ChatMsg, UiError, util}; -use crate::util::InfallibleExt; +use crate::{ + store::{Msg, MsgStore}, + ui::{UiError, util}, + util::InfallibleExt, +}; + +use super::{ChatMsg, Reaction, cursor::Cursor}; use self::renderer::{TreeContext, TreeRenderer}; -use super::Reaction; -use super::cursor::Cursor; +mod renderer; +mod scroll; +mod widgets; pub struct TreeViewState> { store: S, diff --git a/cove/src/ui/chat/tree/renderer.rs b/cove/src/ui/chat/tree/renderer.rs index 192e46c..142624e 100644 --- a/cove/src/ui/chat/tree/renderer.rs +++ b/cove/src/ui/chat/tree/renderer.rs @@ -1,19 +1,26 @@ //! A [`Renderer`] for message trees. -use std::collections::HashSet; -use std::convert::Infallible; +use std::{collections::HashSet, convert::Infallible}; use async_trait::async_trait; use jiff::tz::TimeZone; -use toss::widgets::{EditorState, Empty, Predrawn, Resize}; -use toss::{Size, Widget, WidthDb}; +use toss::{ + Size, Widget, WidthDb, + widgets::{EditorState, Empty, Predrawn, Resize}, +}; -use crate::store::{Msg, MsgStore, Tree}; -use crate::ui::ChatMsg; -use crate::ui::chat::blocks::{Block, Blocks, Range}; -use crate::ui::chat::cursor::Cursor; -use crate::ui::chat::renderer::{self, Renderer, overlaps}; -use crate::util::InfallibleExt; +use crate::{ + store::{Msg, MsgStore, Tree}, + ui::{ + ChatMsg, + chat::{ + blocks::{Block, Blocks, Range}, + cursor::Cursor, + renderer::{self, Renderer, overlaps}, + }, + }, + util::InfallibleExt, +}; use super::widgets; diff --git a/cove/src/ui/chat/tree/scroll.rs b/cove/src/ui/chat/tree/scroll.rs index 73e0e71..ab3ddae 100644 --- a/cove/src/ui/chat/tree/scroll.rs +++ b/cove/src/ui/chat/tree/scroll.rs @@ -1,12 +1,14 @@ -use toss::WidthDb; -use toss::widgets::EditorState; +use toss::{WidthDb, widgets::EditorState}; -use crate::store::{Msg, MsgStore}; -use crate::ui::ChatMsg; -use crate::ui::chat::cursor::Cursor; +use crate::{ + store::{Msg, MsgStore}, + ui::{ChatMsg, chat::cursor::Cursor}, +}; -use super::TreeViewState; -use super::renderer::{TreeContext, TreeRenderer}; +use super::{ + TreeViewState, + renderer::{TreeContext, TreeRenderer}, +}; impl TreeViewState where diff --git a/cove/src/ui/chat/tree/widgets.rs b/cove/src/ui/chat/tree/widgets.rs index bc807d7..d46920e 100644 --- a/cove/src/ui/chat/tree/widgets.rs +++ b/cove/src/ui/chat/tree/widgets.rs @@ -2,13 +2,19 @@ use std::convert::Infallible; use crossterm::style::Stylize; use jiff::tz::TimeZone; -use toss::widgets::{Boxed, EditorState, Join2, Join4, Join5, Text}; -use toss::{Style, Styled, WidgetExt}; +use toss::{ + Style, Styled, WidgetExt, + widgets::{Boxed, EditorState, Join2, Join4, Join5, Text}, +}; -use crate::store::Msg; -use crate::ui::ChatMsg; -use crate::ui::chat::widgets::{Indent, Seen, Time}; -use crate::util; +use crate::{ + store::Msg, + ui::{ + ChatMsg, + chat::widgets::{Indent, Seen, Time}, + }, + util, +}; pub const PLACEHOLDER: &str = "[...]"; diff --git a/cove/src/ui/chat/widgets.rs b/cove/src/ui/chat/widgets.rs index 43ad29e..e0e2fe5 100644 --- a/cove/src/ui/chat/widgets.rs +++ b/cove/src/ui/chat/widgets.rs @@ -2,8 +2,10 @@ use std::convert::Infallible; use crossterm::style::Stylize; use jiff::Zoned; -use toss::widgets::{Boxed, Empty, Text}; -use toss::{Frame, Pos, Size, Style, Widget, WidgetExt, WidthDb}; +use toss::{ + Frame, Pos, Size, Style, Widget, WidgetExt, WidthDb, + widgets::{Boxed, Empty, Text}, +}; use crate::util::InfallibleExt; diff --git a/cove/src/ui/euph/account.rs b/cove/src/ui/euph/account.rs index a982711..48731d9 100644 --- a/cove/src/ui/euph/account.rs +++ b/cove/src/ui/euph/account.rs @@ -1,14 +1,16 @@ use cove_config::Keys; use cove_input::InputEvent; use crossterm::style::Stylize; -use euphoxide::api::PersonalAccountView; -use euphoxide::conn; -use toss::widgets::{EditorState, Empty, Join3, Join4, Join5, Text}; -use toss::{Style, Widget, WidgetExt}; +use euphoxide::{api::PersonalAccountView, conn}; +use toss::{ + Style, Widget, WidgetExt, + widgets::{EditorState, Empty, Join3, Join4, Join5, Text}, +}; -use crate::euph::{self, Room}; -use crate::ui::widgets::Popup; -use crate::ui::{UiError, util}; +use crate::{ + euph::{self, Room}, + ui::{UiError, util, widgets::Popup}, +}; use super::popup::PopupResult; diff --git a/cove/src/ui/euph/auth.rs b/cove/src/ui/euph/auth.rs index 2fbc1c0..259e204 100644 --- a/cove/src/ui/euph/auth.rs +++ b/cove/src/ui/euph/auth.rs @@ -1,11 +1,11 @@ use cove_config::Keys; use cove_input::InputEvent; -use toss::Widget; -use toss::widgets::EditorState; +use toss::{Widget, widgets::EditorState}; -use crate::euph::Room; -use crate::ui::widgets::Popup; -use crate::ui::{UiError, util}; +use crate::{ + euph::Room, + ui::{UiError, util, widgets::Popup}, +}; use super::popup::PopupResult; diff --git a/cove/src/ui/euph/inspect.rs b/cove/src/ui/euph/inspect.rs index e2bcf33..b3c4e0e 100644 --- a/cove/src/ui/euph/inspect.rs +++ b/cove/src/ui/euph/inspect.rs @@ -1,13 +1,13 @@ use cove_config::Keys; use cove_input::InputEvent; use crossterm::style::Stylize; -use euphoxide::api::{Message, NickEvent, SessionView}; -use euphoxide::conn::SessionInfo; -use toss::widgets::Text; -use toss::{Style, Styled, Widget}; +use euphoxide::{ + api::{Message, NickEvent, SessionView}, + conn::SessionInfo, +}; +use toss::{Style, Styled, Widget, widgets::Text}; -use crate::ui::UiError; -use crate::ui::widgets::Popup; +use crate::ui::{UiError, widgets::Popup}; use super::popup::PopupResult; diff --git a/cove/src/ui/euph/links.rs b/cove/src/ui/euph/links.rs index b3e5fb4..14496a6 100644 --- a/cove/src/ui/euph/links.rs +++ b/cove/src/ui/euph/links.rs @@ -1,13 +1,16 @@ use cove_config::{Config, Keys}; use cove_input::InputEvent; -use crossterm::event::KeyCode; -use crossterm::style::Stylize; +use crossterm::{event::KeyCode, style::Stylize}; use linkify::{LinkFinder, LinkKind}; -use toss::widgets::{Join2, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{Join2, Text}, +}; -use crate::ui::widgets::{ListBuilder, ListState, Popup}; -use crate::ui::{UiError, key_bindings, util}; +use crate::ui::{ + UiError, key_bindings, util, + widgets::{ListBuilder, ListState, Popup}, +}; use super::popup::PopupResult; diff --git a/cove/src/ui/euph/nick.rs b/cove/src/ui/euph/nick.rs index 91bdd10..1940fac 100644 --- a/cove/src/ui/euph/nick.rs +++ b/cove/src/ui/euph/nick.rs @@ -1,12 +1,12 @@ use cove_config::Keys; use cove_input::InputEvent; use euphoxide::conn::Joined; -use toss::widgets::EditorState; -use toss::{Style, Widget}; +use toss::{Style, Widget, widgets::EditorState}; -use crate::euph::{self, Room}; -use crate::ui::widgets::Popup; -use crate::ui::{UiError, util}; +use crate::{ + euph::{self, Room}, + ui::{UiError, util, widgets::Popup}, +}; use super::popup::PopupResult; diff --git a/cove/src/ui/euph/nick_list.rs b/cove/src/ui/euph/nick_list.rs index 8401c80..e1e4e3d 100644 --- a/cove/src/ui/euph/nick_list.rs +++ b/cove/src/ui/euph/nick_list.rs @@ -1,14 +1,22 @@ use std::iter; use crossterm::style::{Color, Stylize}; -use euphoxide::api::{NickEvent, SessionId, SessionType, SessionView, UserId}; -use euphoxide::conn::{Joined, SessionInfo}; -use toss::widgets::{Background, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use euphoxide::{ + api::{NickEvent, SessionId, SessionType, SessionView, UserId}, + conn::{Joined, SessionInfo}, +}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{Background, Text}, +}; -use crate::euph; -use crate::ui::UiError; -use crate::ui::widgets::{ListBuilder, ListState}; +use crate::{ + euph, + ui::{ + UiError, + widgets::{ListBuilder, ListState}, + }, +}; pub fn widget<'a>( list: &'a mut ListState, diff --git a/cove/src/ui/euph/popup.rs b/cove/src/ui/euph/popup.rs index e9d4671..3f8caaa 100644 --- a/cove/src/ui/euph/popup.rs +++ b/cove/src/ui/euph/popup.rs @@ -1,11 +1,9 @@ use std::io; use crossterm::style::Stylize; -use toss::widgets::Text; -use toss::{Style, Styled, Widget}; +use toss::{Style, Styled, Widget, widgets::Text}; -use crate::ui::UiError; -use crate::ui::widgets::Popup; +use crate::ui::{UiError, widgets::Popup}; pub enum RoomPopup { Error { description: String, reason: String }, diff --git a/cove/src/ui/euph/room.rs b/cove/src/ui/euph/room.rs index eafd789..7d4b49c 100644 --- a/cove/src/ui/euph/room.rs +++ b/cove/src/ui/euph/room.rs @@ -3,26 +3,40 @@ use std::collections::VecDeque; use cove_config::{Config, Keys}; use cove_input::InputEvent; use crossterm::style::Stylize; -use euphoxide::api::{Data, Message, MessageId, PacketType, SessionId}; -use euphoxide::bot::instance::{Event, ServerConfig}; -use euphoxide::conn::{self, Joined, Joining, SessionInfo}; +use euphoxide::{ + api::{Data, Message, MessageId, PacketType, SessionId}, + bot::instance::{Event, ServerConfig}, + conn::{self, Joined, Joining, SessionInfo}, +}; use jiff::tz::TimeZone; -use tokio::sync::oneshot::error::TryRecvError; -use tokio::sync::{mpsc, oneshot}; -use toss::widgets::{BoxedAsync, EditorState, Join2, Layer, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use tokio::sync::{ + mpsc, + oneshot::{self, error::TryRecvError}, +}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{BoxedAsync, EditorState, Join2, Layer, Text}, +}; -use crate::euph; -use crate::macros::logging_unwrap; -use crate::ui::chat::{ChatState, Reaction}; -use crate::ui::widgets::ListState; -use crate::ui::{UiError, UiEvent, util}; -use crate::vault::EuphRoomVault; +use crate::{ + euph, + macros::logging_unwrap, + ui::{ + UiError, UiEvent, + chat::{ChatState, Reaction}, + util, + widgets::ListState, + }, + vault::EuphRoomVault, +}; -use super::account::AccountUiState; -use super::links::LinksState; -use super::popup::{PopupResult, RoomPopup}; -use super::{auth, inspect, nick, nick_list}; +use super::{ + account::AccountUiState, + auth, inspect, + links::LinksState, + nick, nick_list, + popup::{PopupResult, RoomPopup}, +}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Focus { diff --git a/cove/src/ui/key_bindings.rs b/cove/src/ui/key_bindings.rs index de3c889..daedc16 100644 --- a/cove/src/ui/key_bindings.rs +++ b/cove/src/ui/key_bindings.rs @@ -5,11 +5,15 @@ use std::convert::Infallible; use cove_config::{Config, Keys}; use cove_input::{InputEvent, KeyBinding, KeyBindingInfo, KeyGroupInfo}; use crossterm::style::Stylize; -use toss::widgets::{Either2, Join2, Padding, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{Either2, Join2, Padding, Text}, +}; -use super::widgets::{ListBuilder, ListState, Popup}; -use super::{UiError, util}; +use super::{ + UiError, util, + widgets::{ListBuilder, ListState, Popup}, +}; type Line = Either2, Text>>; type Builder = ListBuilder<'static, Infallible, Line>; diff --git a/cove/src/ui/rooms.rs b/cove/src/ui/rooms.rs index f26defa..a6e7b34 100644 --- a/cove/src/ui/rooms.rs +++ b/cove/src/ui/rooms.rs @@ -1,34 +1,46 @@ -mod connect; -mod delete; - -use std::collections::hash_map::Entry; -use std::collections::{HashMap, HashSet}; -use std::iter; -use std::sync::{Arc, Mutex}; -use std::time::Duration; +use std::{ + collections::{HashMap, HashSet, hash_map::Entry}, + iter, + sync::{Arc, Mutex}, + time::Duration, +}; use cove_config::{Config, Keys, RoomsSortOrder}; use cove_input::InputEvent; use crossterm::style::Stylize; -use euphoxide::api::SessionType; -use euphoxide::bot::instance::{Event, ServerConfig}; -use euphoxide::conn::{self, Joined}; +use euphoxide::{ + api::SessionType, + bot::instance::{Event, ServerConfig}, + conn::{self, Joined}, +}; use jiff::tz::TimeZone; use tokio::sync::mpsc; -use toss::widgets::{BoxedAsync, Empty, Join2, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{BoxedAsync, Empty, Join2, Text}, +}; -use crate::euph; -use crate::macros::logging_unwrap; -use crate::vault::{EuphVault, RoomIdentifier, Vault}; -use crate::version::{NAME, VERSION}; +use crate::{ + euph, + macros::logging_unwrap, + vault::{EuphVault, RoomIdentifier, Vault}, + version::{NAME, VERSION}, +}; -use self::connect::{ConnectResult, ConnectState}; -use self::delete::{DeleteResult, DeleteState}; +use super::{ + UiError, UiEvent, + euph::room::EuphRoom, + key_bindings, util, + widgets::{ListBuilder, ListState}, +}; -use super::euph::room::EuphRoom; -use super::widgets::{ListBuilder, ListState}; -use super::{UiError, UiEvent, key_bindings, util}; +use self::{ + connect::{ConnectResult, ConnectState}, + delete::{DeleteResult, DeleteState}, +}; + +mod connect; +mod delete; enum State { ShowList, diff --git a/cove/src/ui/rooms/connect.rs b/cove/src/ui/rooms/connect.rs index 4ad3c39..ce53775 100644 --- a/cove/src/ui/rooms/connect.rs +++ b/cove/src/ui/rooms/connect.rs @@ -1,12 +1,15 @@ use cove_config::Keys; use cove_input::InputEvent; use crossterm::style::Stylize; -use toss::widgets::{EditorState, Empty, Join2, Join3, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{EditorState, Empty, Join2, Join3, Text}, +}; -use crate::ui::widgets::Popup; -use crate::ui::{UiError, util}; -use crate::vault::RoomIdentifier; +use crate::{ + ui::{UiError, util, widgets::Popup}, + vault::RoomIdentifier, +}; #[derive(Clone, Copy, PartialEq, Eq)] enum Focus { diff --git a/cove/src/ui/rooms/delete.rs b/cove/src/ui/rooms/delete.rs index d5b6884..aafaad8 100644 --- a/cove/src/ui/rooms/delete.rs +++ b/cove/src/ui/rooms/delete.rs @@ -1,12 +1,15 @@ use cove_config::Keys; use cove_input::InputEvent; use crossterm::style::Stylize; -use toss::widgets::{EditorState, Empty, Join2, Text}; -use toss::{Style, Styled, Widget, WidgetExt}; +use toss::{ + Style, Styled, Widget, WidgetExt, + widgets::{EditorState, Empty, Join2, Text}, +}; -use crate::ui::widgets::Popup; -use crate::ui::{UiError, util}; -use crate::vault::RoomIdentifier; +use crate::{ + ui::{UiError, util, widgets::Popup}, + vault::RoomIdentifier, +}; pub struct DeleteState { id: RoomIdentifier, diff --git a/cove/src/ui/widgets.rs b/cove/src/ui/widgets.rs index aed063a..c00d26e 100644 --- a/cove/src/ui/widgets.rs +++ b/cove/src/ui/widgets.rs @@ -1,5 +1,5 @@ -mod list; -mod popup; - pub use self::list::*; pub use self::popup::*; + +mod list; +mod popup; diff --git a/cove/src/ui/widgets/popup.rs b/cove/src/ui/widgets/popup.rs index 40b41cb..559e283 100644 --- a/cove/src/ui/widgets/popup.rs +++ b/cove/src/ui/widgets/popup.rs @@ -1,5 +1,7 @@ -use toss::widgets::{Background, Border, Desync, Float, Layer2, Padding, Text}; -use toss::{Frame, Size, Style, Styled, Widget, WidgetExt, WidthDb}; +use toss::{ + Frame, Size, Style, Styled, Widget, WidgetExt, WidthDb, + widgets::{Background, Border, Desync, Float, Layer2, Padding, Text}, +}; type Body = Background>>; type Title = Float>>>; diff --git a/cove/src/util.rs b/cove/src/util.rs index ff8a05a..c6a572c 100644 --- a/cove/src/util.rs +++ b/cove/src/util.rs @@ -1,5 +1,4 @@ -use std::convert::Infallible; -use std::env; +use std::{convert::Infallible, env}; use jiff::tz::TimeZone; diff --git a/cove/src/vault.rs b/cove/src/vault.rs index 512dfd2..05bd1a5 100644 --- a/cove/src/vault.rs +++ b/cove/src/vault.rs @@ -1,16 +1,14 @@ +use std::{fs, path::Path}; + +use rusqlite::Connection; +use vault::{Action, tokio::TokioVault}; + +pub use self::euph::{EuphRoomVault, EuphVault, RoomIdentifier}; + mod euph; mod migrate; mod prepare; -use std::fs; -use std::path::Path; - -use rusqlite::Connection; -use vault::Action; -use vault::tokio::TokioVault; - -pub use self::euph::{EuphRoomVault, EuphVault, RoomIdentifier}; - #[derive(Debug, Clone)] pub struct Vault { tokio_vault: TokioVault, diff --git a/cove/src/vault/euph.rs b/cove/src/vault/euph.rs index 3e98590..931091c 100644 --- a/cove/src/vault/euph.rs +++ b/cove/src/vault/euph.rs @@ -1,15 +1,18 @@ -use std::str::FromStr; -use std::{fmt, mem}; +use std::{fmt, mem, str::FromStr}; use async_trait::async_trait; use cookie::{Cookie, CookieJar}; use euphoxide::api::{Message, MessageId, SessionId, SessionView, Snowflake, Time, UserId}; -use rusqlite::types::{FromSql, FromSqlError, ToSqlOutput, Value, ValueRef}; -use rusqlite::{Connection, OptionalExtension, Row, ToSql, Transaction, named_params, params}; +use rusqlite::{ + Connection, OptionalExtension, Row, ToSql, Transaction, named_params, params, + types::{FromSql, FromSqlError, ToSqlOutput, Value, ValueRef}, +}; use vault::Action; -use crate::euph::SmallMessage; -use crate::store::{MsgStore, Path, Tree}; +use crate::{ + euph::SmallMessage, + store::{MsgStore, Path, Tree}, +}; /// Wrapper for [`Snowflake`] that implements useful rusqlite traits. struct WSnowflake(Snowflake);