From f4ca196d476acd20dfffe79cfea176b7fef59878 Mon Sep 17 00:00:00 2001 From: race604 Date: Fri, 2 Sep 2022 21:41:56 +0800 Subject: [PATCH] re-orginize code to bin and lib crate --- Cargo.toml | 8 ++++++-- src/app.rs | 6 +++--- src/app/modes.rs | 2 +- src/app/modes/clock.rs | 2 +- src/app/modes/countdown.rs | 2 +- src/app/modes/stopwatch.rs | 2 +- src/app/modes/timer.rs | 2 +- src/{ => bin}/main.rs | 8 ++++---- src/lib.rs | 1 + 9 files changed, 19 insertions(+), 14 deletions(-) rename src/{ => bin}/main.rs (95%) diff --git a/Cargo.toml b/Cargo.toml index 2397fac..ca31a6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,11 @@ clap = { version = "3.2.12", features = ["derive"] } regex = "1.6.0" chrono-tz = { version = "0.6.3", features = ["serde"] } +[lib] +name = "clock_tui" +path = "src/lib.rs" + [[bin]] -bench = false -path = "src/main.rs" name = "tclock" +path = "src/bin/main.rs" +bench = false diff --git a/src/app.rs b/src/app.rs index d5a8aa6..bca702e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -20,10 +20,10 @@ use self::modes::DurationFormat; use self::modes::Stopwatch; use self::modes::Timer; -pub(crate) mod modes; +pub mod modes; #[derive(Debug, Subcommand)] -pub(crate) enum Mode { +pub enum Mode { /// The clock mode displays the current time, the default mode. Clock { /// Custome timezone, for example "America/New_York", use local timezone if not specificed @@ -85,7 +85,7 @@ pub(crate) enum Mode { #[derive(clap::Parser)] #[clap(name = "tclock", about = "A clock app in terminal", long_about = None)] -pub(crate) struct App { +pub struct App { #[clap(subcommand)] pub mode: Option, /// Foreground color of the clock, possible values are: diff --git a/src/app/modes.rs b/src/app/modes.rs index 462d310..6f980b9 100644 --- a/src/app/modes.rs +++ b/src/app/modes.rs @@ -8,7 +8,7 @@ use std::fmt::Write as _; use chrono::Duration; pub(crate) use clock::Clock; -use clock_tui::bricks_text::BricksText; +use crate::bricks_text::BricksText; pub(crate) use countdown::Countdown; pub(crate) use stopwatch::Stopwatch; pub(crate) use timer::Timer; diff --git a/src/app/modes/clock.rs b/src/app/modes/clock.rs index fc17a9a..97fd0d9 100644 --- a/src/app/modes/clock.rs +++ b/src/app/modes/clock.rs @@ -1,6 +1,6 @@ use chrono::{Local, Utc}; use chrono_tz::Tz; -use clock_tui::bricks_text::BricksText; +use crate::bricks_text::BricksText; use tui::{layout::Rect, style::Style, widgets::Widget}; use super::render_centered; diff --git a/src/app/modes/countdown.rs b/src/app/modes/countdown.rs index 9fce3e7..ca8b4ac 100644 --- a/src/app/modes/countdown.rs +++ b/src/app/modes/countdown.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Duration, Local}; -use clock_tui::bricks_text::BricksText; +use crate::bricks_text::BricksText; use tui::{style::Style, widgets::Widget}; use super::{format_duration, render_centered, DurationFormat}; diff --git a/src/app/modes/stopwatch.rs b/src/app/modes/stopwatch.rs index e3cc9e8..06f0aa9 100644 --- a/src/app/modes/stopwatch.rs +++ b/src/app/modes/stopwatch.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Duration, Local}; -use clock_tui::bricks_text::BricksText; +use crate::bricks_text::BricksText; use tui::{buffer::Buffer, layout::Rect, style::Style, widgets::Widget}; use crate::app::Pause; diff --git a/src/app/modes/timer.rs b/src/app/modes/timer.rs index 0c59dca..fcd0a50 100644 --- a/src/app/modes/timer.rs +++ b/src/app/modes/timer.rs @@ -1,7 +1,7 @@ use std::{cell::RefCell, process::Command}; use chrono::{DateTime, Duration, Local}; -use clock_tui::bricks_text::BricksText; +use crate::bricks_text::BricksText; use tui::{buffer::Buffer, layout::Rect, style::Style, widgets::Widget}; use crate::app::Pause; diff --git a/src/main.rs b/src/bin/main.rs similarity index 95% rename from src/main.rs rename to src/bin/main.rs index 781f73c..02b53fa 100644 --- a/src/main.rs +++ b/src/bin/main.rs @@ -4,7 +4,7 @@ use std::{ time::{Duration, Instant}, }; -use app::Mode; +use clock_tui::app::Mode; use clap::Parser; use crossterm::{ event::{self, Event, KeyCode}, @@ -16,11 +16,11 @@ use tui::{ Terminal, }; -mod app; +use clock_tui::app::App; fn run_app( terminal: &mut Terminal, - app: &mut app::App, + app: &mut App, tick_rate: Duration, ) -> io::Result<()> { let mut last_tick = Instant::now(); @@ -49,7 +49,7 @@ fn run_app( } fn main() -> Result<(), Box> { - let mut app = app::App::parse(); + let mut app = App::parse(); app.init_app(); // setup terminal diff --git a/src/lib.rs b/src/lib.rs index 2b82456..7f0012d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,2 @@ +pub mod app; pub mod bricks_text;