generated from PlexSheep/rs-base
Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
Christoph J. Scherr | a7ba7f9e34 | |
Christoph J. Scherr | 74f1df69c2 | |
Christoph J. Scherr | bd801282f2 | |
Christoph J. Scherr | cf4e8b6011 | |
Christoph J. Scherr | b0c605452a | |
Christoph J. Scherr | 18135c15d7 | |
Christoph J. Scherr | 4a9eac6091 | |
Christoph J. Scherr | 757fe6b7b2 | |
Christoph J. Scherr | 140123c124 | |
Christoph J. Scherr | 04c570243c | |
Christoph J. Scherr | 89a636589d |
|
@ -0,0 +1,7 @@
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
# Check for updates every Monday
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
|
@ -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"
|
|
@ -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 }}
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "crock"
|
name = "crock"
|
||||||
version = "0.3.0"
|
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>"]
|
||||||
|
|
|
@ -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
|
||||||
|
|
30
src/clock.rs
30
src/clock.rs
|
@ -70,8 +70,6 @@ pub struct Clock {
|
||||||
pub(crate) last_reset: Option<DateTime<Local>>,
|
pub(crate) last_reset: Option<DateTime<Local>>,
|
||||||
#[clap(skip)]
|
#[clap(skip)]
|
||||||
pub(crate) did_notify: bool,
|
pub(crate) did_notify: bool,
|
||||||
#[clap(skip)]
|
|
||||||
pub(crate) started_at: DateTime<Local>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clock {
|
impl Clock {
|
||||||
|
@ -119,7 +117,8 @@ impl Clock {
|
||||||
// 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));
|
||||||
|
@ -127,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)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,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::new(self.timebar_len().unwrap());
|
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);
|
||||||
|
@ -408,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([
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::clock::timebar::TimeBarLength;
|
||||||
use super::Clock;
|
use super::Clock;
|
||||||
|
|
||||||
pub const TIME_FORMAT: &str = "%H:%M:%S";
|
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)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
@ -18,21 +19,21 @@ pub struct Data {
|
||||||
ftime: [String; 2],
|
ftime: [String; 2],
|
||||||
timebar_ratio: [Option<f64>; 2],
|
timebar_ratio: [Option<f64>; 2],
|
||||||
|
|
||||||
timebar_type: TimeBarLength,
|
timebar_type: Option<TimeBarLength>,
|
||||||
started_at: DateTime<Local>,
|
started_at: DateTime<Local>,
|
||||||
|
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
pub fn new(timebar_type: TimeBarLength) -> Self {
|
pub fn new(timebar_type: Option<TimeBarLength>) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
now: [Default::default(); 2],
|
now: [DateTime::default(); 2],
|
||||||
fdate: [String::new(), String::new()],
|
fdate: [String::new(), String::new()],
|
||||||
ftime: [String::new(), String::new()],
|
ftime: [String::new(), String::new()],
|
||||||
timebar_ratio: [Default::default(); 2],
|
timebar_ratio: [Option::default(); 2],
|
||||||
started_at: Local::now(),
|
started_at: Local::now(),
|
||||||
idx: Default::default(),
|
idx: usize::default(),
|
||||||
|
|
||||||
timebar_type,
|
timebar_type,
|
||||||
};
|
};
|
||||||
|
@ -90,7 +91,7 @@ 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 == TimeBarLength::Timer {
|
if self.timebar_type.is_some() && self.timebar_type.unwrap() == TimeBarLength::Timer {
|
||||||
return Some(0.0);
|
return Some(0.0);
|
||||||
}
|
}
|
||||||
self.timebar_ratio[self.idx]
|
self.timebar_ratio[self.idx]
|
||||||
|
@ -193,17 +194,17 @@ 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(TIME_FORMAT);
|
.format(TIME_FORMAT_SHORT);
|
||||||
|
|
||||||
let text: String = match clock.timebar_len().unwrap() {
|
let text: String = match clock.timebar_len().unwrap() {
|
||||||
TimeBarLength::Timer => format!("{} + {time_now}", data.started_at.format(TIME_FORMAT)),
|
TimeBarLength::Timer => format!("{} + {time_now}", data.started_at.format(TIME_FORMAT)),
|
||||||
TimeBarLength::Countup(_) | TimeBarLength::Custom(_) => format!(
|
TimeBarLength::Countup(_) | TimeBarLength::Custom(_) => format!(
|
||||||
"{time_now} / {len} | {} -> {until}",
|
"{time_now} / {len} | {} -> {until}",
|
||||||
last_reset.format(TIME_FORMAT)
|
last_reset.format(TIME_FORMAT_SHORT)
|
||||||
),
|
),
|
||||||
_ => format!(
|
_ => format!(
|
||||||
"{time_now} / {len} | {} -> {until}",
|
"{time_now} / {len} | {} -> {until}",
|
||||||
last_reset.with_second(0).unwrap().format(TIME_FORMAT)
|
last_reset.with_second(0).unwrap().format(TIME_FORMAT_SHORT)
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn mock_tests() {
|
||||||
info!("0s=0.0");
|
info!("0s=0.0");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut data = Data::new(clock::timebar::TimeBarLength::Day);
|
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));
|
||||||
|
|
Reference in New Issue