Compare commits

...

11 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
8 changed files with 117 additions and 32 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:
pull_request:
branches:
- '**'
push:
branches:
- '**'
# - '!master'
env:
CARGO_TERM_COLOR: always
jobs:
format:
CI:
runs-on: ubuntu-latest
name: cargo CI
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
@ -16,15 +23,11 @@ jobs:
- name: get repo
uses: actions/checkout@v4
- name: install rust
uses: https://github.com/dtolnay/rust-toolchain@stable
uses: 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/
@ -34,15 +37,19 @@ 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: https://github.com/stefanzweifel/git-auto-commit-action@v5
uses: stefanzweifel/git-auto-commit-action@v5
with:
# Optional. Commit message for the created commit.
# 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]
name = "crock"
version = "0.3.0"
version = "0.3.1"
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)
![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)
![GitHub Release](https://img.shields.io/github/v/release/PlexSheep/crock)
![GitHub language count](https://img.shields.io/github/languages/count/PlexSheep/crock)
A little clock for your terminal, written in rust.
![screenshot](data/media/screenshot.png)
* [Original Repository](https://git.cscherr.de/PlexSheep/crock)
* [GitHub Mirror](https://github.com/PlexSheep/crock)
* [GitHub](https://github.com/PlexSheep/crock)
* [crates.io](https://crates.io/crates/crock)
## Compilation

View File

@ -70,8 +70,6 @@ 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 {
@ -119,7 +117,8 @@ impl Clock {
// the count up should not reset. If the time is over, just keep it at 100%
}
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()
{
self.last_reset = Some(Local::now().round_subsecs(0));
@ -127,19 +126,34 @@ impl Clock {
}
TimeBarLength::Minute => {
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)");
}
}
TimeBarLength::Hour => {
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)");
}
}
TimeBarLength::Day => {
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)");
}
}
@ -208,7 +222,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().unwrap());
let mut uidata: Data = Data::new(self.timebar_len());
self.setup()?;
loop {
let raw_time = chrono::Local::now().round_subsecs(0);
@ -408,7 +422,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.35) as u16;
let hlen_date: u16 = (f32::from(part[1].width) * 0.32) as u16;
let subparts = Layout::default()
.direction(Direction::Horizontal)
.constraints([

View File

@ -9,6 +9,7 @@ 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)]
@ -18,21 +19,21 @@ pub struct Data {
ftime: [String; 2],
timebar_ratio: [Option<f64>; 2],
timebar_type: TimeBarLength,
timebar_type: Option<TimeBarLength>,
started_at: DateTime<Local>,
idx: usize,
}
impl Data {
pub fn new(timebar_type: TimeBarLength) -> Self {
pub fn new(timebar_type: Option<TimeBarLength>) -> Self {
let mut this = Self {
now: [Default::default(); 2],
now: [DateTime::default(); 2],
fdate: [String::new(), String::new()],
ftime: [String::new(), String::new()],
timebar_ratio: [Default::default(); 2],
timebar_ratio: [Option::default(); 2],
started_at: Local::now(),
idx: Default::default(),
idx: usize::default(),
timebar_type,
};
@ -90,7 +91,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 == TimeBarLength::Timer {
if self.timebar_type.is_some() && self.timebar_type.unwrap() == TimeBarLength::Timer {
return Some(0.0);
}
self.timebar_ratio[self.idx]
@ -193,17 +194,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);
.format(TIME_FORMAT_SHORT);
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)
last_reset.format(TIME_FORMAT_SHORT)
),
_ => format!(
"{time_now} / {len} | {} -> {until}",
last_reset.with_second(0).unwrap().format(TIME_FORMAT)
last_reset.with_second(0).unwrap().format(TIME_FORMAT_SHORT)
),
};

View File

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