Compare commits

..

16 Commits

Author SHA1 Message Date
Christoph J. Scherr a7ba7f9e34 docs: admit that this is a github project now 2024-10-16 21:21:19 +02:00
Christoph J. Scherr 74f1df69c2 chore: bump version to v0.3.1 2024-10-16 20:48:31 +02:00
Christoph J. Scherr bd801282f2 chore: add system deps to release cd for compilation 2024-10-16 20:42:37 +02:00
Christoph J. Scherr cf4e8b6011 Merge branch 'devel'
Rust CI / cargo CI (push) Has been cancelled Details
Release-plz / Release-plz release (push) Has been cancelled Details
Release-plz / Release-plz PR (push) Has been cancelled Details
2024-10-16 20:40:38 +02:00
Christoph J. Scherr b0c605452a chore: add system deps for ci
Rust CI / cargo CI (push) Waiting to run Details
Release-plz / Release-plz release (push) Waiting to run Details
Release-plz / Release-plz PR (push) Waiting to run Details
2024-10-16 20:36:29 +02:00
Christoph J. Scherr 18135c15d7 Merge branch 'master' into devel
Rust CI / cargo CI (push) Has been cancelled Details
2024-10-16 20:31:30 +02:00
Christoph J. Scherr 4a9eac6091 chore: change ci/cd to use github and deploy with cd from now
Rust CI / cargo CI (push) Waiting to run Details
Release-plz / Release-plz release (push) Waiting to run Details
Release-plz / Release-plz PR (push) Waiting to run Details
2024-10-16 20:29:26 +02:00
Christoph J. Scherr 757fe6b7b2 chore: bump to v0.3.1-alpha.0
cargo devel CI / cargo CI (push) Successful in 1m45s Details
2024-09-05 11:38:02 +02:00
Christoph J. Scherr 140123c124 fix: crashed when no timebar was requested because we unwrapped for the creation of Ui Data #26
cargo devel CI / cargo CI (push) Has been cancelled Details
2024-09-05 11:35:51 +02:00
Christoph J. Scherr 04c570243c fix(timebar): shortened format and refactored
cargo devel CI / cargo CI (push) Successful in 1m43s Details
2024-09-03 20:39:08 +02:00
Christoph J. Scherr 89a636589d chore: some more clippy findings
cargo devel CI / cargo CI (push) Successful in 1m47s Details
2024-09-03 19:16:25 +02:00
Christoph J. Scherr 2f306304b3 chore: clippy findings
cargo devel CI / cargo CI (push) Successful in 1m44s Details
2024-09-03 19:14:34 +02:00
Christoph J. Scherr 23a417a9f9 chore: bump version
cargo devel CI / cargo CI (push) Has been cancelled Details
2024-09-03 19:13:28 +02:00
Christoph J. Scherr 1b07e481f2 feat(timebar)!: add timer and add additional information to the ui #22
cargo devel CI / cargo CI (push) Has been cancelled Details
2024-09-03 19:13:13 +02:00
Christoph J. Scherr 12efcf45a8 Merge branch 'master' into devel
cargo devel CI / cargo CI (push) Successful in 1m43s Details
2024-07-26 10:57:03 +02:00
Christoph J. Scherr 77020571f8 docs: update screenshot
cargo devel CI / cargo CI (push) Successful in 1m57s Details
2024-07-26 10:44:32 +02:00
9 changed files with 157 additions and 27 deletions

7
.github/dependabot.yaml vendored Normal file
View File

@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
# Check for updates every Monday
schedule:
interval: "weekly"

View File

@ -1,12 +1,19 @@
name: cargo devel CI name: Rust CI
on: on:
pull_request:
branches:
- '**'
push: push:
branches: branches:
- '**' - '**'
# - '!master' # - '!master'
env:
CARGO_TERM_COLOR: always
jobs: jobs:
format: CI:
runs-on: ubuntu-latest
name: cargo CI name: cargo CI
permissions: permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the # Give the default GITHUB_TOKEN write permission to commit and push the
@ -16,15 +23,11 @@ jobs:
- name: get repo - name: get repo
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: install rust - name: install rust
uses: https://github.com/dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
- name: install additional rust things - name: install additional rust things
run: | run: |
rustup component add rustfmt rustup component add rustfmt
rustup component add clippy rustup component add clippy
- name: install additional system dependencies
run: |
apt update
apt install libdbus-1-dev libasound2-dev -y
- name: config custom registry - name: config custom registry
run: | run: |
mkdir -p ~/.cargo/ mkdir -p ~/.cargo/
@ -34,15 +37,19 @@ jobs:
echo '[registries.cscherr]' >> ~/.cargo/config.toml echo '[registries.cscherr]' >> ~/.cargo/config.toml
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
cat ~/.cargo/config.toml cat ~/.cargo/config.toml
- name: install additional system dependencies
run: sudo apt-get install -y libasound2-dev libdbus-1-dev
- name: cargo clippy check - name: cargo clippy check
run: cargo clippy --all-features --all-targets --workspace run: cargo clippy --all-features --all-targets --workspace
- name: cargo clippy fix - name: cargo clippy fix
run: cargo clippy --fix --all-features --all-targets --workspace run: cargo clippy --fix --all-features --all-targets --workspace
- name: cargo fmt - name: cargo fmt
run: cargo fmt --all run: cargo fmt --all
- name: cargo test
run: cargo test --all-features --all-targets --workspace
- name: commit back to repository - name: commit back to repository
uses: https://github.com/stefanzweifel/git-auto-commit-action@v5 uses: stefanzweifel/git-auto-commit-action@v5
with: with:
# Optional. Commit message for the created commit. # Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes" # Defaults to "Apply automatic changes"
commit_message: automatic cargo CI changes commit_message: "ci: automatic Rust CI changes"

56
.github/workflows/release.yaml vendored Normal file
View File

@ -0,0 +1,56 @@
name: Release-plz
permissions:
pull-requests: write
contents: write
on:
push:
branches:
- master
- main
jobs:
# Release unpublished packages.
release-plz-release:
name: Release-plz release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: install additional system dependencies
run: sudo apt-get install -y libasound2-dev libdbus-1-dev
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Create a PR with the new versions and changelog, preparing the next release.
release-plz-pr:
name: Release-plz PR
runs-on: ubuntu-latest
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

View File

@ -1,6 +1,6 @@
[package] [package]
name = "crock" name = "crock"
version = "0.2.1" version = "0.3.1"
edition = "2021" edition = "2021"
publish = true publish = true
authors = ["Christoph J. Scherr <software@cscherr.de>"] authors = ["Christoph J. Scherr <software@cscherr.de>"]

View File

@ -2,15 +2,15 @@
![Project badge](https://img.shields.io/badge/language-Rust-blue.svg) ![Project badge](https://img.shields.io/badge/language-Rust-blue.svg)
![Crates.io License](https://img.shields.io/crates/l/crock) ![Crates.io License](https://img.shields.io/crates/l/crock)
![Gitea Release](https://img.shields.io/gitea/v/release/PlexSheep/crock?gitea_url=https%3A%2F%2Fgit.cscherr.de) ![GitHub Release](https://img.shields.io/github/v/release/PlexSheep/crock)
![Gitea language count](https://img.shields.io/gitea/languages/count/PlexSheep/crock?gitea_url=https%3A%2F%2Fgit.cscherr.de) ![GitHub language count](https://img.shields.io/github/languages/count/PlexSheep/crock)
A little clock for your terminal, written in rust. A little clock for your terminal, written in rust.
![screenshot](data/media/screenshot.png) ![screenshot](data/media/screenshot.png)
* [Original Repository](https://git.cscherr.de/PlexSheep/crock) * [GitHub](https://github.com/PlexSheep/crock)
* [GitHub Mirror](https://github.com/PlexSheep/crock)
* [crates.io](https://crates.io/crates/crock) * [crates.io](https://crates.io/crates/crock)
## Compilation ## Compilation

View File

@ -30,7 +30,7 @@ use ui::Data;
/// Make your terminal into a big clock /// Make your terminal into a big clock
#[derive(Parser, Debug, Clone)] #[derive(Parser, Debug, Clone)]
#[command(help_template = HELP_TEMPLATE, author, version)] #[command(help_template = HELP_TEMPLATE, author, version)]
#[clap(group( ArgGroup::new("timebarlen") .args(&["minute","day", "hour", "custom", "countdown"]),))] #[clap(group( ArgGroup::new("timebarlen") .args(&["minute","day", "hour", "custom", "countdown", "timer"]),))]
#[allow(clippy::struct_excessive_bools)] // the struct is for cli parsing and we already use an #[allow(clippy::struct_excessive_bools)] // the struct is for cli parsing and we already use an
// ArgGroup // ArgGroup
pub struct Clock { pub struct Clock {
@ -82,6 +82,8 @@ impl Clock {
Some(TimeBarLength::Day) Some(TimeBarLength::Day)
} else if self.hour { } else if self.hour {
Some(TimeBarLength::Hour) Some(TimeBarLength::Hour)
} else if self.timer {
Some(TimeBarLength::Timer)
} else if self.countdown.is_some() { } else if self.countdown.is_some() {
Some(TimeBarLength::Countup( Some(TimeBarLength::Countup(
self.countdown.unwrap().as_secs() as i64 self.countdown.unwrap().as_secs() as i64
@ -111,11 +113,12 @@ impl Clock {
if let Some(len) = self.timebar_len() { if let Some(len) = self.timebar_len() {
let since_last_reset = Local::now().signed_duration_since(self.last_reset.unwrap()); let since_last_reset = Local::now().signed_duration_since(self.last_reset.unwrap());
match len { match len {
TimeBarLength::Countup(_) => { TimeBarLength::Countup(_) | TimeBarLength::Timer => {
// the count up should not reset. If the time is over, just keep it at 100% // the count up should not reset. If the time is over, just keep it at 100%
} }
TimeBarLength::Custom(_) => { TimeBarLength::Custom(_) => {
if since_last_reset.num_seconds() >= 1 // BUG: this is not consistent, sometimes leads to wrong seconds
if since_last_reset.num_milliseconds() >= 100
&& since_last_reset.num_seconds() >= len.as_secs() && since_last_reset.num_seconds() >= len.as_secs()
{ {
self.last_reset = Some(Local::now().round_subsecs(0)); self.last_reset = Some(Local::now().round_subsecs(0));
@ -123,19 +126,34 @@ impl Clock {
} }
TimeBarLength::Minute => { TimeBarLength::Minute => {
if since_last_reset.num_seconds() >= 1 && Local::now().second() == 0 { if since_last_reset.num_seconds() >= 1 && Local::now().second() == 0 {
self.last_reset = Some(Local::now().round_subsecs(0)); self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
debug!("reset the time of the time bar (minute)"); debug!("reset the time of the time bar (minute)");
} }
} }
TimeBarLength::Hour => { TimeBarLength::Hour => {
if since_last_reset.num_minutes() >= 1 && Local::now().minute() == 0 { if since_last_reset.num_minutes() >= 1 && Local::now().minute() == 0 {
self.last_reset = Some(Local::now().round_subsecs(0)); self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
debug!("reset the time of the time bar (hour)"); debug!("reset the time of the time bar (hour)");
} }
} }
TimeBarLength::Day => { TimeBarLength::Day => {
if since_last_reset.num_hours() >= 1 && Local::now().hour() == 0 { if since_last_reset.num_hours() >= 1 && Local::now().hour() == 0 {
self.last_reset = Some(Local::now().round_subsecs(0)); self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
debug!("reset the time of the time bar (day)"); debug!("reset the time of the time bar (day)");
} }
} }
@ -147,7 +165,7 @@ impl Clock {
if let Some(len) = self.timebar_len() { if let Some(len) = self.timebar_len() {
trace!("Local Time: {}", Local::now()); trace!("Local Time: {}", Local::now());
match len { match len {
TimeBarLength::Custom(_) | TimeBarLength::Countup(_) => { TimeBarLength::Custom(_) | TimeBarLength::Countup(_) | TimeBarLength::Timer => {
self.last_reset = Some(Local::now()); self.last_reset = Some(Local::now());
} }
TimeBarLength::Minute => { TimeBarLength::Minute => {
@ -204,7 +222,7 @@ impl Clock {
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let tick_rate = std::time::Duration::from_millis(100); let tick_rate = std::time::Duration::from_millis(100);
let mut last_tick = Instant::now(); let mut last_tick = Instant::now();
let mut uidata: Data = Data::default(); let mut uidata: Data = Data::new(self.timebar_len());
self.setup()?; self.setup()?;
loop { loop {
let raw_time = chrono::Local::now().round_subsecs(0); let raw_time = chrono::Local::now().round_subsecs(0);
@ -404,7 +422,7 @@ impl Clock {
.split(r); .split(r);
#[allow(clippy::cast_sign_loss)] #[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
let hlen_date: u16 = (f32::from(part[1].width) * 0.35) as u16; let hlen_date: u16 = (f32::from(part[1].width) * 0.32) as u16;
let subparts = Layout::default() let subparts = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([ .constraints([

View File

@ -4,6 +4,7 @@ use chrono::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimeBarLength { pub enum TimeBarLength {
Timer,
Minute, Minute,
Hour, Hour,
Custom(i64), Custom(i64),
@ -19,6 +20,7 @@ impl TimeBarLength {
Self::Minute => 60, Self::Minute => 60,
Self::Day => 24 * 60 * 60, Self::Day => 24 * 60 * 60,
Self::Hour => 60 * 60, Self::Hour => 60 * 60,
Self::Timer => 1,
Self::Custom(secs) | Self::Countup(secs) => secs, Self::Custom(secs) | Self::Countup(secs) => secs,
} }
} }
@ -38,6 +40,9 @@ impl Default for TimeBarLength {
impl Display for TimeBarLength { impl Display for TimeBarLength {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if *self == Self::Timer {
return write!(f, "");
}
let buf = match self { let buf = match self {
Self::Minute => humantime::Duration::from( Self::Minute => humantime::Duration::from(
Duration::minutes(1) Duration::minutes(1)
@ -59,6 +64,7 @@ impl Display for TimeBarLength {
.to_std() .to_std()
.expect("could not convert chrono time to std time"), .expect("could not convert chrono time to std time"),
), ),
Self::Timer => unreachable!(),
}; };
write!(f, "{buf}") write!(f, "{buf}")
} }

View File

@ -8,18 +8,38 @@ use crate::clock::timebar::TimeBarLength;
use super::Clock; use super::Clock;
pub const TIME_FORMAT: &str = "%H:%M:%S";
pub const TIME_FORMAT_SHORT: &str = "%H:%M";
// TODO: make this a ringbuffer with a custom struct inside? // TODO: make this a ringbuffer with a custom struct inside?
#[derive(Debug, Clone, PartialEq, Default)] #[derive(Debug, Clone, PartialEq)]
pub struct Data { pub struct Data {
now: [DateTime<Local>; 2], now: [DateTime<Local>; 2],
fdate: [String; 2], fdate: [String; 2],
ftime: [String; 2], ftime: [String; 2],
timebar_ratio: [Option<f64>; 2], timebar_ratio: [Option<f64>; 2],
timebar_type: Option<TimeBarLength>,
started_at: DateTime<Local>,
idx: usize, idx: usize,
} }
impl Data { impl Data {
pub fn new(timebar_type: Option<TimeBarLength>) -> Self {
let mut this = Self {
now: [DateTime::default(); 2],
fdate: [String::new(), String::new()],
ftime: [String::new(), String::new()],
timebar_ratio: [Option::default(); 2],
started_at: Local::now(),
idx: usize::default(),
timebar_type,
};
this.started_at = this.started_at.round_subsecs(0);
this
}
pub fn update( pub fn update(
&mut self, &mut self,
now: DateTime<Local>, now: DateTime<Local>,
@ -71,6 +91,9 @@ impl Data {
#[inline] #[inline]
#[allow(clippy::missing_const_for_fn)] // no it's not const #[allow(clippy::missing_const_for_fn)] // no it's not const
pub fn timebar_ratio(&self) -> Option<f64> { pub fn timebar_ratio(&self) -> Option<f64> {
if self.timebar_type.is_some() && self.timebar_type.unwrap() == TimeBarLength::Timer {
return Some(0.0);
}
self.timebar_ratio[self.idx] self.timebar_ratio[self.idx]
} }
} }
@ -171,8 +194,21 @@ pub fn timebarw_label<'a>(
// example with `-o` #17 // example with `-o` #17
.checked_add_signed(len.into()) .checked_add_signed(len.into())
.expect("could not calculate when the countdown finishes") .expect("could not calculate when the countdown finishes")
.format("%H:%M:%S"); .format(TIME_FORMAT_SHORT);
Paragraph::new(format!("{time_now} / {len} ({until})"))
let text: String = match clock.timebar_len().unwrap() {
TimeBarLength::Timer => format!("{} + {time_now}", data.started_at.format(TIME_FORMAT)),
TimeBarLength::Countup(_) | TimeBarLength::Custom(_) => format!(
"{time_now} / {len} | {} -> {until}",
last_reset.format(TIME_FORMAT_SHORT)
),
_ => format!(
"{time_now} / {len} | {} -> {until}",
last_reset.with_second(0).unwrap().format(TIME_FORMAT_SHORT)
),
};
Paragraph::new(text)
.alignment(Alignment::Center) .alignment(Alignment::Center)
.block( .block(
Block::default().padding(Padding::right(if inner_rect.width > 80 { Block::default().padding(Padding::right(if inner_rect.width > 80 {

View File

@ -90,7 +90,7 @@ fn mock_tests() {
info!("0s=0.0"); info!("0s=0.0");
} }
{ {
let mut data = Data::default(); let mut data = Data::new(None);
let now = Local::now(); let now = Local::now();
data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1)); data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1));
assert_eq!(data.timebar_ratio(), Some(0.1)); assert_eq!(data.timebar_ratio(), Some(0.1));