Compare commits

..

No commits in common. "master" and "v0.3.0" have entirely different histories.

8 changed files with 32 additions and 117 deletions

View File

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

View File

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

View File

@ -1,56 +0,0 @@
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]
name = "crock"
version = "0.3.1"
version = "0.3.0"
edition = "2021"
publish = true
authors = ["Christoph J. Scherr <software@cscherr.de>"]

View File

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

View File

@ -70,6 +70,8 @@ pub struct Clock {
pub(crate) last_reset: Option<DateTime<Local>>,
#[clap(skip)]
pub(crate) did_notify: bool,
#[clap(skip)]
pub(crate) started_at: DateTime<Local>,
}
impl Clock {
@ -117,8 +119,7 @@ impl Clock {
// the count up should not reset. If the time is over, just keep it at 100%
}
TimeBarLength::Custom(_) => {
// BUG: this is not consistent, sometimes leads to wrong seconds
if since_last_reset.num_milliseconds() >= 100
if since_last_reset.num_seconds() >= 1
&& since_last_reset.num_seconds() >= len.as_secs()
{
self.last_reset = Some(Local::now().round_subsecs(0));
@ -126,34 +127,19 @@ impl Clock {
}
TimeBarLength::Minute => {
if since_last_reset.num_seconds() >= 1 && Local::now().second() == 0 {
self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
self.last_reset = Some(Local::now().round_subsecs(0));
debug!("reset the time of the time bar (minute)");
}
}
TimeBarLength::Hour => {
if since_last_reset.num_minutes() >= 1 && Local::now().minute() == 0 {
self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
self.last_reset = Some(Local::now().round_subsecs(0));
debug!("reset the time of the time bar (hour)");
}
}
TimeBarLength::Day => {
if since_last_reset.num_hours() >= 1 && Local::now().hour() == 0 {
self.last_reset = Some(
Local::now()
.round_subsecs(0)
.with_second(1)
.expect("tried to use a time that does not exist"),
);
self.last_reset = Some(Local::now().round_subsecs(0));
debug!("reset the time of the time bar (day)");
}
}
@ -222,7 +208,7 @@ impl Clock {
) -> anyhow::Result<()> {
let tick_rate = std::time::Duration::from_millis(100);
let mut last_tick = Instant::now();
let mut uidata: Data = Data::new(self.timebar_len());
let mut uidata: Data = Data::new(self.timebar_len().unwrap());
self.setup()?;
loop {
let raw_time = chrono::Local::now().round_subsecs(0);
@ -422,7 +408,7 @@ impl Clock {
.split(r);
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)]
let hlen_date: u16 = (f32::from(part[1].width) * 0.32) as u16;
let hlen_date: u16 = (f32::from(part[1].width) * 0.35) as u16;
let subparts = Layout::default()
.direction(Direction::Horizontal)
.constraints([

View File

@ -9,7 +9,6 @@ use crate::clock::timebar::TimeBarLength;
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?
#[derive(Debug, Clone, PartialEq)]
@ -19,21 +18,21 @@ pub struct Data {
ftime: [String; 2],
timebar_ratio: [Option<f64>; 2],
timebar_type: Option<TimeBarLength>,
timebar_type: TimeBarLength,
started_at: DateTime<Local>,
idx: usize,
}
impl Data {
pub fn new(timebar_type: Option<TimeBarLength>) -> Self {
pub fn new(timebar_type: TimeBarLength) -> Self {
let mut this = Self {
now: [DateTime::default(); 2],
now: [Default::default(); 2],
fdate: [String::new(), String::new()],
ftime: [String::new(), String::new()],
timebar_ratio: [Option::default(); 2],
timebar_ratio: [Default::default(); 2],
started_at: Local::now(),
idx: usize::default(),
idx: Default::default(),
timebar_type,
};
@ -91,7 +90,7 @@ impl Data {
#[inline]
#[allow(clippy::missing_const_for_fn)] // no it's not const
pub fn timebar_ratio(&self) -> Option<f64> {
if self.timebar_type.is_some() && self.timebar_type.unwrap() == TimeBarLength::Timer {
if self.timebar_type == TimeBarLength::Timer {
return Some(0.0);
}
self.timebar_ratio[self.idx]
@ -194,17 +193,17 @@ pub fn timebarw_label<'a>(
// example with `-o` #17
.checked_add_signed(len.into())
.expect("could not calculate when the countdown finishes")
.format(TIME_FORMAT_SHORT);
.format(TIME_FORMAT);
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)
last_reset.format(TIME_FORMAT)
),
_ => format!(
"{time_now} / {len} | {} -> {until}",
last_reset.with_second(0).unwrap().format(TIME_FORMAT_SHORT)
last_reset.with_second(0).unwrap().format(TIME_FORMAT)
),
};

View File

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