Merge pull request #21 from race604/bin-and-lib-crate

reorganize code to bin and lib crate
This commit is contained in:
Jimmy 2022-09-02 23:03:51 +08:00 committed by GitHub
commit 584e4e8ae9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 19 additions and 14 deletions

View file

@ -19,7 +19,11 @@ clap = { version = "3.2.12", features = ["derive"] }
regex = "1.6.0" regex = "1.6.0"
chrono-tz = { version = "0.6.3", features = ["serde"] } chrono-tz = { version = "0.6.3", features = ["serde"] }
[lib]
name = "clock_tui"
path = "src/lib.rs"
[[bin]] [[bin]]
bench = false
path = "src/main.rs"
name = "tclock" name = "tclock"
path = "src/bin/main.rs"
bench = false

View file

@ -20,10 +20,10 @@ use self::modes::DurationFormat;
use self::modes::Stopwatch; use self::modes::Stopwatch;
use self::modes::Timer; use self::modes::Timer;
pub(crate) mod modes; pub mod modes;
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
pub(crate) enum Mode { pub enum Mode {
/// The clock mode displays the current time, the default mode. /// The clock mode displays the current time, the default mode.
Clock { Clock {
/// Custome timezone, for example "America/New_York", use local timezone if not specificed /// Custome timezone, for example "America/New_York", use local timezone if not specificed
@ -85,7 +85,7 @@ pub(crate) enum Mode {
#[derive(clap::Parser)] #[derive(clap::Parser)]
#[clap(name = "tclock", about = "A clock app in terminal", long_about = None)] #[clap(name = "tclock", about = "A clock app in terminal", long_about = None)]
pub(crate) struct App { pub struct App {
#[clap(subcommand)] #[clap(subcommand)]
pub mode: Option<Mode>, pub mode: Option<Mode>,
/// Foreground color of the clock, possible values are: /// Foreground color of the clock, possible values are:

View file

@ -8,7 +8,7 @@ use std::fmt::Write as _;
use chrono::Duration; use chrono::Duration;
pub(crate) use clock::Clock; pub(crate) use clock::Clock;
use clock_tui::bricks_text::BricksText; use crate::bricks_text::BricksText;
pub(crate) use countdown::Countdown; pub(crate) use countdown::Countdown;
pub(crate) use stopwatch::Stopwatch; pub(crate) use stopwatch::Stopwatch;
pub(crate) use timer::Timer; pub(crate) use timer::Timer;

View file

@ -1,6 +1,6 @@
use chrono::{Local, Utc}; use chrono::{Local, Utc};
use chrono_tz::Tz; use chrono_tz::Tz;
use clock_tui::bricks_text::BricksText; use crate::bricks_text::BricksText;
use tui::{layout::Rect, style::Style, widgets::Widget}; use tui::{layout::Rect, style::Style, widgets::Widget};
use super::render_centered; use super::render_centered;

View file

@ -1,5 +1,5 @@
use chrono::{DateTime, Duration, Local}; use chrono::{DateTime, Duration, Local};
use clock_tui::bricks_text::BricksText; use crate::bricks_text::BricksText;
use tui::{style::Style, widgets::Widget}; use tui::{style::Style, widgets::Widget};
use super::{format_duration, render_centered, DurationFormat}; use super::{format_duration, render_centered, DurationFormat};

View file

@ -1,5 +1,5 @@
use chrono::{DateTime, Duration, Local}; 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 tui::{buffer::Buffer, layout::Rect, style::Style, widgets::Widget};
use crate::app::Pause; use crate::app::Pause;

View file

@ -1,7 +1,7 @@
use std::{cell::RefCell, process::Command}; use std::{cell::RefCell, process::Command};
use chrono::{DateTime, Duration, Local}; 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 tui::{buffer::Buffer, layout::Rect, style::Style, widgets::Widget};
use crate::app::Pause; use crate::app::Pause;

View file

@ -4,7 +4,7 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use app::Mode; use clock_tui::app::Mode;
use clap::Parser; use clap::Parser;
use crossterm::{ use crossterm::{
event::{self, Event, KeyCode}, event::{self, Event, KeyCode},
@ -16,11 +16,11 @@ use tui::{
Terminal, Terminal,
}; };
mod app; use clock_tui::app::App;
fn run_app<B: Backend>( fn run_app<B: Backend>(
terminal: &mut Terminal<B>, terminal: &mut Terminal<B>,
app: &mut app::App, app: &mut App,
tick_rate: Duration, tick_rate: Duration,
) -> io::Result<()> { ) -> io::Result<()> {
let mut last_tick = Instant::now(); let mut last_tick = Instant::now();
@ -49,7 +49,7 @@ fn run_app<B: Backend>(
} }
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let mut app = app::App::parse(); let mut app = App::parse();
app.init_app(); app.init_app();
// setup terminal // setup terminal

View file

@ -1 +1,2 @@
pub mod app;
pub mod bricks_text; pub mod bricks_text;