diff --git a/database-tree/src/databasetree.rs b/database-tree/src/databasetree.rs index 02be20a..0471a86 100644 --- a/database-tree/src/databasetree.rs +++ b/database-tree/src/databasetree.rs @@ -1,9 +1,9 @@ +use std::{collections::BTreeSet, usize}; + use crate::{ databasetreeitems::DatabaseTreeItems, error::Result, item::DatabaseTreeItemKind, - tree_iter::TreeIterator, + tree_iter::TreeIterator, Database, Table, }; -use crate::{Database, Table}; -use std::{collections::BTreeSet, usize}; /// #[derive(Copy, Clone, Debug)] @@ -366,9 +366,10 @@ impl DatabaseTree { #[cfg(test)] mod test { - use crate::{Database, DatabaseTree, MoveSelection, Schema, Table}; use std::collections::BTreeSet; + use crate::{Database, DatabaseTree, MoveSelection, Schema, Table}; + impl Table { fn new(name: String) -> Self { Table { diff --git a/database-tree/src/databasetreeitems.rs b/database-tree/src/databasetreeitems.rs index 95659c4..ed8429e 100644 --- a/database-tree/src/databasetreeitems.rs +++ b/database-tree/src/databasetreeitems.rs @@ -1,11 +1,13 @@ -use crate::{error::Result, treeitems_iter::TreeItemsIterator}; -use crate::{item::DatabaseTreeItemKind, DatabaseTreeItem}; -use crate::{Child, Database}; use std::{ collections::{BTreeSet, HashMap}, usize, }; +use crate::{ + error::Result, item::DatabaseTreeItemKind, treeitems_iter::TreeItemsIterator, Child, Database, + DatabaseTreeItem, +}; + #[derive(Default)] pub struct DatabaseTreeItems { pub tree_items: Vec, diff --git a/database-tree/src/error.rs b/database-tree/src/error.rs index 8d5a0a4..00a2974 100644 --- a/database-tree/src/error.rs +++ b/database-tree/src/error.rs @@ -1,4 +1,5 @@ use std::num::TryFromIntError; + use thiserror::Error; #[derive(Error, Debug)] diff --git a/database-tree/src/lib.rs b/database-tree/src/lib.rs index 5997944..a862168 100644 --- a/database-tree/src/lib.rs +++ b/database-tree/src/lib.rs @@ -6,8 +6,7 @@ mod tree_iter; mod treeitems_iter; pub use crate::{ - databasetree::DatabaseTree, - databasetree::MoveSelection, + databasetree::{DatabaseTree, MoveSelection}, item::{DatabaseTreeItem, TreeItemInfo}, }; diff --git a/src/app.rs b/src/app.rs index 184bb55..c50d24d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,21 +1,19 @@ -use crate::clipboard::copy_to_clipboard; -use crate::components::{ - CommandInfo, Component as _, DrawableComponent as _, EventState, StatefulDrawableComponent, +use tui::{ + backend::Backend, + layout::{Constraint, Direction, Layout, Rect}, + Frame, }; -use crate::database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE}; -use crate::event::Key; + use crate::{ - components::tab::Tab, + clipboard::copy_to_clipboard, components::{ - command, ConnectionsComponent, DatabasesComponent, ErrorComponent, HelpComponent, - PropertiesComponent, RecordTableComponent, SqlEditorComponent, TabComponent, + command, tab::Tab, CommandInfo, Component as _, ConnectionsComponent, DatabasesComponent, + DrawableComponent as _, ErrorComponent, EventState, HelpComponent, PropertiesComponent, + RecordTableComponent, SqlEditorComponent, StatefulDrawableComponent, TabComponent, }, config::Config, -}; -use tui::{ - backend::Backend, - layout::{Constraint, Direction, Layout, Rect}, - Frame, + database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE}, + event::Key, }; pub enum Focus { diff --git a/src/cli.rs b/src/cli.rs index 37d0db0..5da2221 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,7 @@ -use crate::config::CliConfig; use structopt::StructOpt; +use crate::config::CliConfig; + /// A cross-platform TUI database management tool written in Rust #[derive(StructOpt, Debug)] #[structopt(name = "gobang")] diff --git a/src/clipboard.rs b/src/clipboard.rs index e54f6c4..650d939 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -1,8 +1,11 @@ -use anyhow::{anyhow, Result}; #[cfg(all(target_family = "unix", not(target_os = "macos")))] use std::ffi::OsStr; -use std::io::Write; -use std::process::{Command, Stdio}; +use std::{ + io::Write, + process::{Command, Stdio}, +}; + +use anyhow::{anyhow, Result}; fn execute_copy_command(command: Command, text: &str) -> Result<()> { let mut command = command; @@ -42,6 +45,7 @@ fn gen_command(path: impl AsRef, xclip_syntax: bool) -> Command { #[cfg(all(target_family = "unix", not(target_os = "macos")))] pub fn copy_to_clipboard(string: &str) -> Result<()> { use std::path::PathBuf; + use which::which; let (path, xclip_syntax) = which("xclip").ok().map_or_else( || { diff --git a/src/components/completion.rs b/src/components/completion.rs index 848c355..4a2bfe8 100644 --- a/src/components/completion.rs +++ b/src/components/completion.rs @@ -1,7 +1,3 @@ -use super::{Component, EventState, MovableComponent}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use tui::{ backend::Backend, @@ -11,6 +7,9 @@ use tui::{ Frame, }; +use super::{Component, EventState, MovableComponent}; +use crate::{components::command::CommandInfo, config::KeyConfig, event::Key}; + const RESERVED_WORDS_IN_WHERE_CLAUSE: &[&str] = &["IN", "AND", "OR", "NOT", "NULL", "IS"]; const ALL_RESERVED_WORDS: &[&str] = &[ "IN", "AND", "OR", "NOT", "NULL", "IS", "SELECT", "UPDATE", "DELETE", "FROM", "LIMIT", "WHERE", diff --git a/src/components/connections.rs b/src/components/connections.rs index 659f3db..aee3626 100644 --- a/src/components/connections.rs +++ b/src/components/connections.rs @@ -1,7 +1,3 @@ -use super::{Component, EventState, StatefulDrawableComponent}; -use crate::components::command::CommandInfo; -use crate::config::{Connection, KeyConfig}; -use crate::event::Key; use anyhow::Result; use tui::{ backend::Backend, @@ -12,6 +8,13 @@ use tui::{ Frame, }; +use super::{Component, EventState, StatefulDrawableComponent}; +use crate::{ + components::command::CommandInfo, + config::{Connection, KeyConfig}, + event::Key, +}; + pub struct ConnectionsComponent { connections: Vec, state: ListState, diff --git a/src/components/database_filter.rs b/src/components/database_filter.rs index 6aeea78..6e86439 100644 --- a/src/components/database_filter.rs +++ b/src/components/database_filter.rs @@ -1,6 +1,3 @@ -use super::{compute_character_width, Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::event::Key; use anyhow::Result; use database_tree::Table; use tui::{ @@ -13,6 +10,9 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; +use super::{compute_character_width, Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, event::Key}; + pub struct DatabaseFilterComponent { pub table: Option, input: Vec, diff --git a/src/components/databases.rs b/src/components/databases.rs index e4af306..e5d3948 100644 --- a/src/components/databases.rs +++ b/src/components/databases.rs @@ -1,17 +1,7 @@ -use super::{ - utils::scroll_vertical::VerticalScroll, Component, DatabaseFilterComponent, DrawableComponent, - EventState, -}; -use crate::components::command::{self, CommandInfo}; -use crate::config::{Connection, KeyConfig}; -use crate::database::Pool; -use crate::event::Key; -use crate::ui::common_nav; -use crate::ui::scrolllist::draw_list_block; +use std::{collections::BTreeSet, convert::From}; + use anyhow::Result; use database_tree::{Database, DatabaseTree, DatabaseTreeItem}; -use std::collections::BTreeSet; -use std::convert::From; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -21,6 +11,18 @@ use tui::{ Frame, }; +use super::{ + utils::scroll_vertical::VerticalScroll, Component, DatabaseFilterComponent, DrawableComponent, + EventState, +}; +use crate::{ + components::command::{self, CommandInfo}, + config::{Connection, KeyConfig}, + database::Pool, + event::Key, + ui::{common_nav, scrolllist::draw_list_block}, +}; + // ▸ const FOLDER_ICON_COLLAPSED: &str = "\u{25b8}"; // ▾ @@ -274,9 +276,10 @@ fn tree_nav(tree: &mut DatabaseTree, key: Key, key_config: &KeyConfig) -> bool { #[cfg(test)] mod test { - use super::{Color, Database, DatabaseTreeItem, DatabasesComponent, Span, Spans, Style}; use database_tree::Table; + use super::{Color, Database, DatabaseTreeItem, DatabasesComponent, Span, Spans, Style}; + #[test] fn test_tree_database_tree_item_to_span() { const WIDTH: u16 = 10; diff --git a/src/components/debug.rs b/src/components/debug.rs index 5098b75..3ae8f2f 100644 --- a/src/components/debug.rs +++ b/src/components/debug.rs @@ -1,7 +1,3 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use tui::{ backend::Backend, @@ -10,6 +6,9 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, config::KeyConfig, event::Key}; + pub struct DebugComponent { msg: String, visible: bool, diff --git a/src/components/error.rs b/src/components/error.rs index a9d123e..a8b4007 100644 --- a/src/components/error.rs +++ b/src/components/error.rs @@ -1,7 +1,3 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use tui::{ backend::Backend, @@ -11,6 +7,9 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, config::KeyConfig, event::Key}; + pub struct ErrorComponent { pub error: String, visible: bool, diff --git a/src/components/help.rs b/src/components/help.rs index 90a54fb..b0eb8f3 100644 --- a/src/components/help.rs +++ b/src/components/help.rs @@ -1,11 +1,7 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::event::Key; -use crate::version::Version; +use std::convert::From; + use anyhow::Result; use itertools::Itertools; -use std::convert::From; use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -15,6 +11,9 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, config::KeyConfig, event::Key, version::Version}; + pub struct HelpComponent { cmds: Vec, visible: bool, diff --git a/src/components/mod.rs b/src/components/mod.rs index ef70ecc..2b0c88d 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -18,11 +18,17 @@ pub mod utils; #[cfg(debug_assertions)] pub mod debug; +use std::convert::TryInto; + +use anyhow::Result; +use async_trait::async_trait; pub use command::{CommandInfo, CommandText}; pub use completion::CompletionComponent; pub use connections::ConnectionsComponent; pub use database_filter::DatabaseFilterComponent; pub use databases::DatabasesComponent; +#[cfg(debug_assertions)] +pub use debug::DebugComponent; pub use error::ErrorComponent; pub use help::HelpComponent; pub use properties::PropertiesComponent; @@ -33,17 +39,11 @@ pub use table::TableComponent; pub use table_filter::TableFilterComponent; pub use table_status::TableStatusComponent; pub use table_value::TableValueComponent; - -#[cfg(debug_assertions)] -pub use debug::DebugComponent; - -use crate::database::Pool; -use anyhow::Result; -use async_trait::async_trait; -use std::convert::TryInto; use tui::{backend::Backend, layout::Rect, Frame}; use unicode_width::UnicodeWidthChar; +use crate::database::Pool; + #[derive(PartialEq, Debug)] pub enum EventState { Consumed, diff --git a/src/components/properties.rs b/src/components/properties.rs index ff92322..6d3435a 100644 --- a/src/components/properties.rs +++ b/src/components/properties.rs @@ -1,10 +1,3 @@ -use super::{Component, EventState, StatefulDrawableComponent}; -use crate::clipboard::copy_to_clipboard; -use crate::components::command::{self, CommandInfo}; -use crate::components::TableComponent; -use crate::config::KeyConfig; -use crate::database::Pool; -use crate::event::Key; use anyhow::Result; use async_trait::async_trait; use database_tree::{Database, Table}; @@ -16,6 +9,18 @@ use tui::{ Frame, }; +use super::{Component, EventState, StatefulDrawableComponent}; +use crate::{ + clipboard::copy_to_clipboard, + components::{ + command::{self, CommandInfo}, + TableComponent, + }, + config::KeyConfig, + database::Pool, + event::Key, +}; + #[derive(Debug, PartialEq)] pub enum Focus { Column, diff --git a/src/components/record_table.rs b/src/components/record_table.rs index 8eae65c..c2a2279 100644 --- a/src/components/record_table.rs +++ b/src/components/record_table.rs @@ -1,8 +1,3 @@ -use super::{Component, EventState, StatefulDrawableComponent}; -use crate::components::command::CommandInfo; -use crate::components::{TableComponent, TableFilterComponent}; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use database_tree::{Database, Table as DTable}; use tui::{ @@ -11,6 +6,13 @@ use tui::{ Frame, }; +use super::{Component, EventState, StatefulDrawableComponent}; +use crate::{ + components::{command::CommandInfo, TableComponent, TableFilterComponent}, + config::KeyConfig, + event::Key, +}; + pub enum Focus { Table, Filter, diff --git a/src/components/sql_editor.rs b/src/components/sql_editor.rs index 8d56309..4e3dffb 100644 --- a/src/components/sql_editor.rs +++ b/src/components/sql_editor.rs @@ -1,12 +1,3 @@ -use super::{ - compute_character_width, CompletionComponent, Component, EventState, MovableComponent, - StatefulDrawableComponent, TableComponent, -}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::database::{ExecuteResult, Pool}; -use crate::event::Key; -use crate::ui::stateful_paragraph::{ParagraphState, StatefulParagraph}; use anyhow::Result; use async_trait::async_trait; use tui::{ @@ -18,6 +9,18 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; +use super::{ + compute_character_width, CompletionComponent, Component, EventState, MovableComponent, + StatefulDrawableComponent, TableComponent, +}; +use crate::{ + components::command::CommandInfo, + config::KeyConfig, + database::{ExecuteResult, Pool}, + event::Key, + ui::stateful_paragraph::{ParagraphState, StatefulParagraph}, +}; + struct QueryResult { updated_rows: u64, } diff --git a/src/components/tab.rs b/src/components/tab.rs index f6aae60..b4430ce 100644 --- a/src/components/tab.rs +++ b/src/components/tab.rs @@ -1,7 +1,3 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::{self, CommandInfo}; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use strum_macros::EnumIter; use tui::{ @@ -13,6 +9,13 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{ + components::command::{self, CommandInfo}, + config::KeyConfig, + event::Key, +}; + #[derive(Debug, Clone, Copy, EnumIter)] pub enum Tab { Records, diff --git a/src/components/table.rs b/src/components/table.rs index 6860261..1dbe3ea 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -1,13 +1,7 @@ -use super::{ - utils::scroll_vertical::VerticalScroll, Component, DrawableComponent, EventState, - StatefulDrawableComponent, TableStatusComponent, TableValueComponent, -}; -use crate::components::command::{self, CommandInfo}; -use crate::config::KeyConfig; -use crate::event::Key; +use std::convert::From; + use anyhow::Result; use database_tree::{Database, Table as DTable}; -use std::convert::From; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -17,6 +11,16 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; +use super::{ + utils::scroll_vertical::VerticalScroll, Component, DrawableComponent, EventState, + StatefulDrawableComponent, TableStatusComponent, TableValueComponent, +}; +use crate::{ + components::command::{self, CommandInfo}, + config::KeyConfig, + event::Key, +}; + pub struct TableComponent { pub headers: Vec, pub rows: Vec>, @@ -573,9 +577,10 @@ impl Component for TableComponent { #[cfg(test)] mod test { - use super::{KeyConfig, TableComponent}; use tui::layout::Constraint; + use super::{KeyConfig, TableComponent}; + #[test] fn test_headers() { let mut component = TableComponent::new(KeyConfig::default()); diff --git a/src/components/table_filter.rs b/src/components/table_filter.rs index 9875f24..fd285fe 100644 --- a/src/components/table_filter.rs +++ b/src/components/table_filter.rs @@ -1,10 +1,3 @@ -use super::{ - compute_character_width, CompletionComponent, Component, EventState, MovableComponent, - StatefulDrawableComponent, -}; -use crate::components::command::CommandInfo; -use crate::config::KeyConfig; -use crate::event::Key; use anyhow::Result; use database_tree::Table; use tui::{ @@ -17,6 +10,12 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; +use super::{ + compute_character_width, CompletionComponent, Component, EventState, MovableComponent, + StatefulDrawableComponent, +}; +use crate::{components::command::CommandInfo, config::KeyConfig, event::Key}; + pub struct TableFilterComponent { key_config: KeyConfig, pub table: Option
, diff --git a/src/components/table_status.rs b/src/components/table_status.rs index 0f187cd..9d483cc 100644 --- a/src/components/table_status.rs +++ b/src/components/table_status.rs @@ -1,6 +1,3 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::event::Key; use anyhow::Result; use database_tree::Table; use tui::{ @@ -12,6 +9,9 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, event::Key}; + pub struct TableStatusComponent { column_count: Option, row_count: Option, diff --git a/src/components/table_value.rs b/src/components/table_value.rs index 82c3cc2..e67ea4a 100644 --- a/src/components/table_value.rs +++ b/src/components/table_value.rs @@ -1,6 +1,3 @@ -use super::{Component, DrawableComponent, EventState}; -use crate::components::command::CommandInfo; -use crate::event::Key; use anyhow::Result; use tui::{ backend::Backend, @@ -10,6 +7,9 @@ use tui::{ Frame, }; +use super::{Component, DrawableComponent, EventState}; +use crate::{components::command::CommandInfo, event::Key}; + pub struct TableValueComponent { value: String, } diff --git a/src/components/utils/scroll_vertical.rs b/src/components/utils/scroll_vertical.rs index 0c2fb88..9db45f2 100644 --- a/src/components/utils/scroll_vertical.rs +++ b/src/components/utils/scroll_vertical.rs @@ -1,7 +1,9 @@ -use crate::ui::scrollbar::draw_scrollbar; use std::cell::Cell; + use tui::{backend::Backend, layout::Rect, Frame}; +use crate::ui::scrollbar::draw_scrollbar; + pub struct VerticalScroll { top: Cell, max_top: Cell, diff --git a/src/config.rs b/src/config.rs index 3d41831..816cf1f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,14 +1,16 @@ -use crate::log::LogLevel; -use crate::Key; -use serde::Deserialize; -use std::fmt; -use std::fs::File; -use std::io::{BufReader, Read}; -use std::path::{Path, PathBuf}; -use structopt::StructOpt; +use std::{ + fmt, + fs::File, + io::{BufReader, Read}, + path::{Path, PathBuf}, +}; +use serde::Deserialize; #[cfg(test)] use serde::Serialize; +use structopt::StructOpt; + +use crate::{log::LogLevel, Key}; #[derive(StructOpt, Debug)] pub struct CliConfig { @@ -325,10 +327,12 @@ fn expand_path(path: &Path) -> Option { #[cfg(test)] mod test { - use super::{expand_path, KeyConfig, Path, PathBuf}; - use serde_json::Value; use std::env; + use serde_json::Value; + + use super::{expand_path, KeyConfig, Path, PathBuf}; + #[test] fn test_overlappted_key() { let value: Value = diff --git a/src/database/mod.rs b/src/database/mod.rs index fe4ad25..a74adda 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -2,13 +2,12 @@ pub mod mysql; pub mod postgres; pub mod sqlite; +use async_trait::async_trait; +use database_tree::{Child, Database, Table}; pub use mysql::MySqlPool; pub use postgres::PostgresPool; pub use sqlite::SqlitePool; -use async_trait::async_trait; -use database_tree::{Child, Database, Table}; - pub const RECORDS_LIMIT_PER_PAGE: u8 = 200; #[async_trait] diff --git a/src/database/mysql.rs b/src/database/mysql.rs index 6fb7d73..6e14d78 100644 --- a/src/database/mysql.rs +++ b/src/database/mysql.rs @@ -1,13 +1,16 @@ -use crate::get_or_null; +use std::time::Duration; -use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use database_tree::{Child, Database, Table}; use futures::TryStreamExt; -use sqlx::mysql::{MySqlColumn, MySqlPoolOptions, MySqlRow}; -use sqlx::{Column as _, Row as _, TypeInfo as _}; -use std::time::Duration; +use sqlx::{ + mysql::{MySqlColumn, MySqlPoolOptions, MySqlRow}, + Column as _, Row as _, TypeInfo as _, +}; + +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use crate::get_or_null; pub struct MySqlPool { pool: sqlx::mysql::MySqlPool, diff --git a/src/database/postgres.rs b/src/database/postgres.rs index 5f308f9..7400bea 100644 --- a/src/database/postgres.rs +++ b/src/database/postgres.rs @@ -1,14 +1,17 @@ -use crate::get_or_null; +use std::time::Duration; -use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use database_tree::{Child, Database, Schema, Table}; use futures::TryStreamExt; use itertools::Itertools; -use sqlx::postgres::{PgColumn, PgPool, PgPoolOptions, PgRow}; -use sqlx::{Column as _, Row as _, TypeInfo as _}; -use std::time::Duration; +use sqlx::{ + postgres::{PgColumn, PgPool, PgPoolOptions, PgRow}, + Column as _, Row as _, TypeInfo as _, +}; + +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use crate::get_or_null; pub struct PostgresPool { pool: PgPool, diff --git a/src/database/sqlite.rs b/src/database/sqlite.rs index b4d625e..6b1dea8 100644 --- a/src/database/sqlite.rs +++ b/src/database/sqlite.rs @@ -1,13 +1,16 @@ -use crate::get_or_null; +use std::time::Duration; -use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::NaiveDateTime; use database_tree::{Child, Database, Table}; use futures::TryStreamExt; -use sqlx::sqlite::{SqliteColumn, SqlitePoolOptions, SqliteRow}; -use sqlx::{Column as _, Row as _, TypeInfo as _}; -use std::time::Duration; +use sqlx::{ + sqlite::{SqliteColumn, SqlitePoolOptions, SqliteRow}, + Column as _, Row as _, TypeInfo as _, +}; + +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use crate::get_or_null; pub struct SqlitePool { pool: sqlx::sqlite::SqlitePool, diff --git a/src/event/events.rs b/src/event/events.rs index a01e93d..4250d91 100644 --- a/src/event/events.rs +++ b/src/event/events.rs @@ -1,7 +1,9 @@ -use crate::event::Key; -use crossterm::event; use std::{sync::mpsc, thread, time::Duration}; +use crossterm::event; + +use crate::event::Key; + #[derive(Debug, Clone, Copy)] pub struct EventConfig { pub exit_key: Key, diff --git a/src/event/key.rs b/src/event/key.rs index c40240c..3e3c5d6 100644 --- a/src/event/key.rs +++ b/src/event/key.rs @@ -1,7 +1,7 @@ -use crossterm::event; -use serde::Deserialize; use std::fmt; +use crossterm::event; +use serde::Deserialize; #[cfg(test)] use serde::Serialize; diff --git a/src/main.rs b/src/main.rs index 221fb7c..0aa1952 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,16 +11,20 @@ mod version; #[macro_use] mod log; -use crate::app::App; -use crate::event::{Event, Key}; +use std::io; + use anyhow::Result; use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, ExecutableCommand, }; -use std::io; use tui::{backend::CrosstermBackend, Terminal}; +use crate::{ + app::App, + event::{Event, Key}, +}; + #[tokio::main] async fn main() -> anyhow::Result<()> { let value = crate::cli::parse(); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b3e3c50..374bccd 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,7 +1,7 @@ -use crate::config::KeyConfig; -use crate::event::Key; use database_tree::MoveSelection; +use crate::{config::KeyConfig, event::Key}; + pub mod reflow; pub mod scrollbar; pub mod scrolllist; diff --git a/src/ui/reflow.rs b/src/ui/reflow.rs index c699da3..2b04f3b 100644 --- a/src/ui/reflow.rs +++ b/src/ui/reflow.rs @@ -227,9 +227,10 @@ fn trim_offset(src: &str, mut offset: usize) -> &str { #[cfg(test)] mod test { - use super::*; use unicode_segmentation::UnicodeSegmentation; + use super::*; + enum Composer { WordWrapper { trim: bool }, LineTruncator, @@ -473,7 +474,8 @@ mod test { // to test double-width chars. // You are more than welcome to add word boundary detection based of alterations of // hiragana and katakana... - // This happens to also be a test case for mixed width because regular spaces are single width. + // This happens to also be a test case for mixed width because regular spaces are single + // width. let text = "コンピュ ータ上で文字を扱う場合、 典型的には文 字による 通信を行 う場合にその両端点では、"; let (word_wrapper, word_wrapper_width) = run_composer(Composer::WordWrapper { trim: true }, text, width); diff --git a/src/ui/scrollbar.rs b/src/ui/scrollbar.rs index a58972e..88869ab 100644 --- a/src/ui/scrollbar.rs +++ b/src/ui/scrollbar.rs @@ -1,5 +1,6 @@ -use easy_cast::CastFloat; use std::convert::TryFrom; + +use easy_cast::CastFloat; use tui::{ backend::Backend, buffer::Buffer, diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs index 45916af..39fba72 100644 --- a/src/ui/scrolllist.rs +++ b/src/ui/scrolllist.rs @@ -1,4 +1,5 @@ use std::iter::Iterator; + use tui::{ backend::Backend, buffer::Buffer, diff --git a/src/ui/stateful_paragraph.rs b/src/ui/stateful_paragraph.rs index db4f07a..2a23a8e 100644 --- a/src/ui/stateful_paragraph.rs +++ b/src/ui/stateful_paragraph.rs @@ -1,7 +1,8 @@ #![allow(dead_code)] -use easy_cast::Cast; use std::iter; + +use easy_cast::Cast; use tui::{ buffer::Buffer, layout::{Alignment, Rect}, diff --git a/src/ui/syntax_text.rs b/src/ui/syntax_text.rs index 235f65a..33007d7 100644 --- a/src/ui/syntax_text.rs +++ b/src/ui/syntax_text.rs @@ -1,4 +1,5 @@ use std::ops::Range; + use syntect::{ highlighting::{ FontStyle, HighlightState, Highlighter, RangedHighlightIterator, Style, ThemeSet,