From 11d95bc7f15c081cc4c017a8bef55fb270369438 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Mon, 28 Aug 2023 23:31:27 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20rustfmt=20with=20nightly=20options=20?= =?UTF-8?q?=E2=99=BB=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rustfmt.toml | 2 + rust-toolchain.toml | 2 +- src/app.rs | 140 +++++++++++++++++--------------------------- src/calendar.rs | 5 +- src/completion.rs | 21 +++---- src/config.rs | 8 +-- src/event.rs | 13 ++-- src/history.rs | 15 +++-- src/keyconfig.rs | 8 +-- src/main.rs | 34 +++++------ src/pane/context.rs | 34 ++++++----- src/pane/mod.rs | 11 ++-- src/pane/project.rs | 34 ++++++----- src/table.rs | 17 +++--- src/task_report.rs | 7 +-- src/utils.rs | 4 +- 16 files changed, 167 insertions(+), 188 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index d870fddb..db495491 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,4 @@ max_width = 150 tab_spaces = 2 +group_imports = "StdExternalCrate" +imports_granularity = "Crate" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 292fe499..5d56faf9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "stable" +channel = "nightly" diff --git a/src/app.rs b/src/app.rs index 82433b46..ba4c9791 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,94 +1,64 @@ -use crate::calendar::Calendar; -use crate::completion::{get_start_word_under_cursor, CompletionList}; -use crate::config; -use crate::config::Config; -use crate::event::Event; -use crate::help::Help; -use crate::keyconfig::KeyConfig; -use crate::scrollbar::Scrollbar; -use crate::table::{Row, Table, TableMode, TableState}; -use crate::task_report::TaskReportTable; -use crate::ui; -use crate::utils; - -use std::cmp::Ordering; -use std::collections::{HashMap, HashSet}; -use std::convert::TryInto; -use std::fs; -use std::path::Path; - -use std::io::Read; -use std::io::Write; - -use std::time::SystemTime; - -use ratatui::symbols::bar::FULL; -use task_hookrs::date::Date; -use task_hookrs::import::import; -use task_hookrs::status::TaskStatus; -use task_hookrs::task::Task; -use uuid::Uuid; - -use unicode_segmentation::Graphemes; -use unicode_segmentation::UnicodeSegmentation; -use unicode_width::UnicodeWidthStr; +use std::{ + borrow::Borrow, + cmp::Ordering, + collections::{HashMap, HashSet}, + convert::TryInto, + fs, io, + io::{Read, Write}, + path::Path, + sync::{mpsc, Arc, Mutex}, + time::{Duration, Instant, SystemTime}, +}; +use anyhow::{anyhow, Context as AnyhowContext, Result}; use chrono::{DateTime, Datelike, FixedOffset, Local, NaiveDate, NaiveDateTime, TimeZone, Timelike}; - -use anyhow::Context as AnyhowContext; -use anyhow::{anyhow, Result}; - -use std::sync::mpsc; - -use std::sync::{Arc, Mutex}; - +use crossterm::{ + event::{DisableMouseCapture, EnableMouseCapture}, + execute, + style::style, + terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, +}; +use futures::SinkExt; +use lazy_static::lazy_static; +use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; use ratatui::{ - backend::Backend, + backend::{Backend, CrosstermBackend}, layout::{Alignment, Constraint, Direction, Layout, Margin, Rect}, style::{Color, Modifier, Style}, + symbols::bar::FULL, terminal::Frame, text::{Line, Span, Text}, - widgets::{Block, BorderType, Borders, Clear, Gauge, LineGauge, List, ListItem, Paragraph, Wrap}, + widgets::{Block, BorderType, Borders, Clear, Gauge, LineGauge, List, ListItem, Paragraph, Tabs, Wrap}, + Terminal, }; -use std::time::Duration; - -use rustyline::history::SearchDirection as HistoryDirection; -use rustyline::line_buffer::LineBuffer; -use rustyline::At; -use rustyline::Editor; -use rustyline::Word; - -use crate::history::HistoryContext; - -use ratatui::{backend::CrosstermBackend, Terminal}; -use std::io; - use regex::Regex; - -use lazy_static::lazy_static; - -use crate::action::Action; -use crate::event::KeyCode; -use crate::pane::context::{ContextDetails, ContextsState}; -use crate::pane::project::ProjectsState; -use crate::pane::Pane; - -use crossterm::style::style; -use crossterm::{ - event::{DisableMouseCapture, EnableMouseCapture}, - execute, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, -}; - -use futures::SinkExt; -use std::borrow::Borrow; -use std::time::Instant; -use task_hookrs::project::Project; - +use rustyline::{history::SearchDirection as HistoryDirection, line_buffer::LineBuffer, At, Editor, Word}; +use task_hookrs::{date::Date, import::import, project::Project, status::TaskStatus, task::Task}; +use unicode_segmentation::{Graphemes, UnicodeSegmentation}; +use unicode_width::UnicodeWidthStr; +use uuid::Uuid; use versions::Versioning; -use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; -use ratatui::widgets::Tabs; +use crate::{ + action::Action, + calendar::Calendar, + completion::{get_start_word_under_cursor, CompletionList}, + config, + config::Config, + event::{Event, KeyCode}, + help::Help, + history::HistoryContext, + keyconfig::KeyConfig, + pane::{ + context::{ContextDetails, ContextsState}, + project::ProjectsState, + Pane, + }, + scrollbar::Scrollbar, + table::{Row, Table, TableMode, TableState}, + task_report::TaskReportTable, + ui, utils, +}; const MAX_LINE: usize = 4096; @@ -3731,13 +3701,11 @@ pub fn remove_tag(task: &mut Task, tag: &str) { #[cfg(test)] mod tests { + use std::{ffi::OsStr, fmt::Write, fs::File, io, path::Path}; + + use ratatui::{backend::TestBackend, buffer::Buffer}; + use super::*; - use ratatui::backend::TestBackend; - use ratatui::buffer::Buffer; - use std::ffi::OsStr; - use std::fs::File; - use std::path::Path; - use std::{fmt::Write, io}; /// Returns a string representation of the given buffer for debugging purpose. fn buffer_view(buffer: &Buffer) -> String { diff --git a/src/calendar.rs b/src/calendar.rs index 896cf08f..04d50566 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -5,8 +5,9 @@ use std::fmt; const COL_WIDTH: usize = 21; -use chrono::{format::Fixed, DateTime, Datelike, Duration, FixedOffset, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; +use std::cmp::min; +use chrono::{format::Fixed, DateTime, Datelike, Duration, FixedOffset, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; use ratatui::{ buffer::Buffer, layout::Rect, @@ -15,8 +16,6 @@ use ratatui::{ widgets::{Block, Widget}, }; -use std::cmp::min; - #[derive(Debug, Clone)] pub struct Calendar<'a> { pub block: Option>, diff --git a/src/completion.rs b/src/completion.rs index 0fa37eab..858c3d84 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -1,3 +1,5 @@ +use std::{error::Error, io}; + use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; use ratatui::{ layout::{Constraint, Corner, Direction, Layout}, @@ -6,16 +8,15 @@ use ratatui::{ widgets::{Block, Borders, List, ListItem, ListState}, Terminal, }; -use std::{error::Error, io}; - -use rustyline::highlight::{Highlighter, MatchingBracketHighlighter}; -use rustyline::hint::Hinter; -use rustyline::line_buffer::LineBuffer; -use rustyline::Context; -use rustyline::{error::ReadlineError, history::FileHistory}; - -use unicode_segmentation::Graphemes; -use unicode_segmentation::UnicodeSegmentation; +use rustyline::{ + error::ReadlineError, + highlight::{Highlighter, MatchingBracketHighlighter}, + hint::Hinter, + history::FileHistory, + line_buffer::LineBuffer, + Context, +}; +use unicode_segmentation::{Graphemes, UnicodeSegmentation}; use unicode_width::UnicodeWidthStr; pub fn get_start_word_under_cursor(line: &str, cursor_pos: usize) -> usize { diff --git a/src/config.rs b/src/config.rs index 86867c04..fa7afa1c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,12 +1,10 @@ +use std::{collections::HashMap, error::Error, str}; + use anyhow::{Context, Result}; use ratatui::{ style::{Color, Modifier, Style}, - symbols::bar::FULL, - symbols::line::DOUBLE_VERTICAL, + symbols::{bar::FULL, line::DOUBLE_VERTICAL}, }; -use std::collections::HashMap; -use std::error::Error; -use std::str; trait TaskWarriorBool { fn get_bool(&self) -> Option; diff --git a/src/event.rs b/src/event.rs index 800965b8..87047f54 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,12 +1,13 @@ -use crossterm::event::KeyEvent; +use crossterm::event::{ + KeyCode::{BackTab, Backspace, Char, Delete, Down, End, Enter, Esc, Home, Insert, Left, Null, PageDown, PageUp, Right, Tab, Up, F}, + KeyEvent, KeyModifiers, +}; use futures::StreamExt; use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; use serde::{Deserialize, Serialize}; -use tokio::{sync::mpsc, sync::oneshot, task::JoinHandle}; - -use crossterm::event::{ - KeyCode::{BackTab, Backspace, Char, Delete, Down, End, Enter, Esc, Home, Insert, Left, Null, PageDown, PageUp, Right, Tab, Up, F}, - KeyModifiers, +use tokio::{ + sync::{mpsc, oneshot}, + task::JoinHandle, }; #[derive(Debug, Clone, Copy)] diff --git a/src/history.rs b/src/history.rs index 60ba76ba..1b9aa52d 100644 --- a/src/history.rs +++ b/src/history.rs @@ -1,10 +1,13 @@ +use std::{ + fs::File, + path::{Path, PathBuf}, +}; + use anyhow::{anyhow, Result}; -use rustyline::error::ReadlineError; -use rustyline::history::DefaultHistory; -use rustyline::history::History; -use rustyline::history::SearchDirection; -use std::fs::File; -use std::path::{Path, PathBuf}; +use rustyline::{ + error::ReadlineError, + history::{DefaultHistory, History, SearchDirection}, +}; pub struct HistoryContext { history: DefaultHistory, diff --git a/src/keyconfig.rs b/src/keyconfig.rs index f686e327..e6d1256c 100644 --- a/src/keyconfig.rs +++ b/src/keyconfig.rs @@ -1,9 +1,9 @@ -use crate::event::KeyCode; +use std::{collections::HashSet, error::Error, hash::Hash}; + use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; -use std::collections::HashSet; -use std::error::Error; -use std::hash::Hash; + +use crate::event::KeyCode; #[derive(Serialize, Deserialize, Debug)] pub struct KeyConfig { diff --git a/src/main.rs b/src/main.rs index 6030b4e4..f47d328d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,18 +20,17 @@ mod task_report; mod ui; mod utils; -use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; -use log4rs::append::file::FileAppender; -use log4rs::config::{Appender, Config, Logger, Root}; -use log4rs::encode::pattern::PatternEncoder; -use std::env; -use std::error::Error; -use std::io::{self, Write}; -use std::panic; -use std::path::{Path, PathBuf}; -use std::time::Duration; +use std::{ + env, + error::Error, + io::{self, Write}, + panic, + path::{Path, PathBuf}, + time::Duration, +}; use anyhow::Result; +use app::{Mode, TaskwarriorTui}; use crossterm::{ cursor, event::{DisableMouseCapture, EnableMouseCapture, EventStream}, @@ -39,15 +38,16 @@ use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}, }; use futures::stream::{FuturesUnordered, StreamExt}; -use ratatui::{backend::CrosstermBackend, Terminal}; - +use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; +use log4rs::{ + append::file::FileAppender, + config::{Appender, Config, Logger, Root}, + encode::pattern::PatternEncoder, +}; use path_clean::PathClean; +use ratatui::{backend::CrosstermBackend, Terminal}; -use app::{Mode, TaskwarriorTui}; - -use crate::action::Action; -use crate::event::Event; -use crate::keyconfig::KeyConfig; +use crate::{action::Action, event::Event, keyconfig::KeyConfig}; const LOG_PATTERN: &str = "{d(%Y-%m-%d %H:%M:%S)} | {l} | {f}:{L} | {m}{n}"; diff --git a/src/pane/context.rs b/src/pane/context.rs index 5062d1d9..07a5daf7 100644 --- a/src/pane/context.rs +++ b/src/pane/context.rs @@ -1,14 +1,22 @@ -use anyhow::Context as AnyhowContext; -use anyhow::{anyhow, Result}; use std::fmt; +use anyhow::{anyhow, Context as AnyhowContext, Result}; + const NAME: &str = "Name"; const TYPE: &str = "Remaining"; const DEFINITION: &str = "Avg age"; const ACTIVE: &str = "Complete"; -use chrono::{Datelike, Duration, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; +use std::{ + cmp, + cmp::min, + collections::{HashMap, HashSet}, + error::Error, + process::{Command, Output}, +}; +use chrono::{Datelike, Duration, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; +use itertools::Itertools; use ratatui::{ buffer::Buffer, layout::{Alignment, Rect}, @@ -17,20 +25,16 @@ use ratatui::{ text::{Line, Span, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, StatefulWidget, Widget}, }; - -use crate::action::Action; -use crate::app::{Mode, TaskwarriorTui}; -use crate::event::KeyCode; -use crate::pane::Pane; -use crate::table::TableState; -use itertools::Itertools; -use std::cmp; -use std::cmp::min; -use std::collections::{HashMap, HashSet}; -use std::error::Error; -use std::process::{Command, Output}; use uuid::Uuid; +use crate::{ + action::Action, + app::{Mode, TaskwarriorTui}, + event::KeyCode, + pane::Pane, + table::TableState, +}; + #[derive(Debug, Clone, Default)] pub struct ContextDetails { pub name: String, diff --git a/src/pane/mod.rs b/src/pane/mod.rs index 21c3811d..ee1f1b30 100644 --- a/src/pane/mod.rs +++ b/src/pane/mod.rs @@ -1,9 +1,12 @@ +use std::ops::Index; + use anyhow::Result; -use crate::action::Action; -use crate::app::{Mode, TaskwarriorTui}; -use crate::event::KeyCode; -use std::ops::Index; +use crate::{ + action::Action, + app::{Mode, TaskwarriorTui}, + event::KeyCode, +}; pub mod context; pub mod project; diff --git a/src/pane/project.rs b/src/pane/project.rs index 1b12e1c9..5e379067 100644 --- a/src/pane/project.rs +++ b/src/pane/project.rs @@ -1,15 +1,22 @@ -use anyhow::Context as AnyhowContext; -use anyhow::{anyhow, Result}; use std::fmt; +use anyhow::{anyhow, Context as AnyhowContext, Result}; + const COL_WIDTH: usize = 21; const PROJECT_HEADER: &str = "Name"; const REMAINING_TASK_HEADER: &str = "Remaining"; const AVG_AGE_HEADER: &str = "Avg age"; const COMPLETE_HEADER: &str = "Complete"; -use chrono::{Datelike, Duration, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; +use std::{ + cmp::min, + collections::{HashMap, HashSet}, + error::Error, + process::{Command, Output}, +}; +use chrono::{Datelike, Duration, Local, Month, NaiveDate, NaiveDateTime, TimeZone}; +use itertools::Itertools; use ratatui::{ buffer::Buffer, layout::Rect, @@ -17,21 +24,18 @@ use ratatui::{ symbols, widgets::{Block, Widget}, }; - -use crate::action::Action; -use crate::app::{Mode, TaskwarriorTui}; -use crate::event::KeyCode; -use crate::pane::Pane; -use crate::table::TableState; -use crate::utils::Changeset; -use itertools::Itertools; -use std::cmp::min; -use std::collections::{HashMap, HashSet}; -use std::error::Error; -use std::process::{Command, Output}; use task_hookrs::project::Project; use uuid::Uuid; +use crate::{ + action::Action, + app::{Mode, TaskwarriorTui}, + event::KeyCode, + pane::Pane, + table::TableState, + utils::Changeset, +}; + pub struct ProjectsState { pub(crate) list: Vec, pub table_state: TableState, diff --git a/src/table.rs b/src/table.rs index 9f61fb45..b38b600f 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1,7 +1,13 @@ +use std::{ + collections::{HashMap, HashSet}, + fmt::Display, + iter::{self, Iterator}, +}; + use cassowary::{ strength::{MEDIUM, REQUIRED, WEAK}, + Expression, Solver, WeightedRelation::{EQ, GE, LE}, - {Expression, Solver}, }; use ratatui::{ buffer::Buffer, @@ -9,14 +15,7 @@ use ratatui::{ style::Style, widgets::{Block, StatefulWidget, Widget}, }; -use std::collections::HashSet; -use std::{ - collections::HashMap, - fmt::Display, - iter::{self, Iterator}, -}; -use unicode_segmentation::Graphemes; -use unicode_segmentation::UnicodeSegmentation; +use unicode_segmentation::{Graphemes, UnicodeSegmentation}; use unicode_width::UnicodeWidthStr; #[derive(Debug, Clone)] diff --git a/src/task_report.rs b/src/task_report.rs index 2ddb3e87..33572956 100644 --- a/src/task_report.rs +++ b/src/task_report.rs @@ -1,10 +1,9 @@ +use std::{error::Error, process::Command}; + use anyhow::Result; use chrono::{DateTime, Datelike, Local, NaiveDate, NaiveDateTime, TimeZone}; use itertools::join; -use std::error::Error; -use std::process::Command; -use task_hookrs::task::Task; -use task_hookrs::uda::UDAValue; +use task_hookrs::{task::Task, uda::UDAValue}; use unicode_truncate::UnicodeTruncateStr; use unicode_width::UnicodeWidthStr; diff --git a/src/utils.rs b/src/utils.rs index 426a252a..57f228ab 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,4 @@ -use rustyline::line_buffer::ChangeListener; -use rustyline::line_buffer::DeleteListener; -use rustyline::line_buffer::Direction; +use rustyline::line_buffer::{ChangeListener, DeleteListener, Direction}; /// Undo manager #[derive(Default)]