chore: fmt

pull/170/head
Valentin271 6 months ago
parent 0a1c65372c
commit f18d014332
No known key found for this signature in database
GPG Key ID: 77B4667C08D99D91

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

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

@ -1,4 +1,5 @@
use std::num::TryFromIntError;
use thiserror::Error;
#[derive(Error, Debug)]

@ -6,8 +6,7 @@ mod tree_iter;
mod treeitems_iter;
pub use crate::{
databasetree::DatabaseTree,
databasetree::MoveSelection,
databasetree::{DatabaseTree, MoveSelection},
item::{DatabaseTreeItem, TreeItemInfo},
};

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

@ -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")]

@ -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<OsStr>, 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(
|| {

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

@ -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<Connection>,
state: ListState,

@ -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<Table>,
input: Vec<char>,

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

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

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

@ -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<CommandInfo>,
visible: bool,

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

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

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

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

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

@ -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<String>,
pub rows: Vec<Vec<String>>,
@ -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());

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

@ -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<usize>,
row_count: Option<usize>,

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

@ -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<usize>,
max_top: Cell<usize>,

@ -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<PathBuf> {
#[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 =

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

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

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

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

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

@ -1,7 +1,7 @@
use crossterm::event;
use serde::Deserialize;
use std::fmt;
use crossterm::event;
use serde::Deserialize;
#[cfg(test)]
use serde::Serialize;

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

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

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

@ -1,5 +1,6 @@
use easy_cast::CastFloat;
use std::convert::TryFrom;
use easy_cast::CastFloat;
use tui::{
backend::Backend,
buffer::Buffer,

@ -1,4 +1,5 @@
use std::iter::Iterator;
use tui::{
backend::Backend,
buffer::Buffer,

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

@ -1,4 +1,5 @@
use std::ops::Range;
use syntect::{
highlighting::{
FontStyle, HighlightState, Highlighter, RangedHighlightIterator, Style, ThemeSet,

Loading…
Cancel
Save