rustfmt, clippy, gh actions, justfile, Default app (#4)

* `Default` app
* add zed settings
* add justfile
* flake: update devShell, ignore tests, add `just`
* update README
* gh actions: lint, format, tests. build
This commit is contained in:
Jens K. 2024-11-29 15:49:55 +01:00 committed by GitHub
parent a9e573122d
commit 3d0d55c8d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 131 additions and 30 deletions

39
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: lint, format, test, build
on:
push:
branches: [ master ]
pull_request:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Check formatting
run: nix develop --command cargo fmt --all -- --check
- name: Run clippy
run: nix develop --command cargo clippy -- -D warnings
- name: Run tests
run: nix develop --command cargo test
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Run tests
run: nix develop --command cargo test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build project
run: nix build .#timr

17
.zed/settings.json Normal file
View File

@ -0,0 +1,17 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"format_on_save": "on",
"formatter": "language_server",
"lsp": {
"rust-analyzer": {
"initialization_options": {
"check": {
"command": "clippy" // rust-analyzer.check.command (default: "check")
}
}
}
}
}

View File

@ -1,6 +1,6 @@
# tim:r
## Development
## Build from source
### Requirements
@ -13,17 +13,20 @@ If `direnv` is installed, run `direnv allow` once to install dependencies. Other
#### Non Nix user
- [`Rust`](https://www.rust-lang.org/)
- [`Rust`](https://www.rust-lang.org/learn/get-started)
- [`Clippy`](https://github.com/rust-lang/rust-clippy)
- [`rustfmt`](https://github.com/rust-lang/rustfmt)
- [`just`](https://just.systems)
#### Build/run
#### Run
```sh
cargo run
```
## Build release
#### Build
- Linux
```sh
@ -34,3 +37,22 @@ nix build
```sh
nix build .#windows
```
#### Commands to `run`, `build` etc.
```sh
just --list
Available recipes:
build # build app
b # alias for `build`
default
format # format files
f # alias for `format`
lint # lint
l # alias for `lint`
run # run app
r # alias for `run`
test # run tests
t # alias for `test`
```

View File

@ -28,6 +28,7 @@
cargoArtifacts = craneLib.buildDepsOnly {
src = craneLib.cleanCargoSource ./.;
};
doCheck = false; # skip tests during nix build
};
# Native build
@ -64,20 +65,17 @@
windows = crossBuild;
};
# Separate artifacts for CI caching
checks = {
inherit timr;
cargoArtifacts = commonArgs.cargoArtifacts;
};
# Development shell with all necessary tools
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
rust-analyzer
clippy
rustfmt
toolchain
];
devShell = with nixpkgs.legacyPackages.${system}; mkShell {
buildInputs = with fenix.packages.${system}.stable; [
rust-analyzer
clippy
rustfmt
toolchain
just
];
inherit (commonArgs) src;
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";

32
justfile Normal file
View File

@ -0,0 +1,32 @@
# The `--fmt` command is currently unstable.
set unstable := true
default: run
alias b := build
alias f := format
alias l := lint
alias t := test
alias r := run
# build app
build:
cargo build
# run tests
test:
cargo test
# format files
format:
just --fmt
cargo fmt --check
# lint
lint:
cargo clippy --no-deps
# run app
run:
cargo run

View File

@ -7,27 +7,28 @@ use ratatui::{
widgets::{Block, Paragraph, Widget},
DefaultTerminal, Frame,
};
use strum::{Display, EnumIter, FromRepr};
use crate::footer::Footer;
use crate::pomodoro::Pomodoro;
use crate::timer::Timer;
use crate::{countdown::Countdown, utils::center};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
enum Mode {
#[default]
Running,
Quit,
}
#[derive(Debug, Clone, Copy, Display, EnumIter, FromRepr, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Content {
#[default]
Countdown,
Timer,
Pomodoro,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct App {
content: Content,
mode: Mode,
@ -35,14 +36,6 @@ pub struct App {
}
impl App {
pub const fn new() -> Self {
Self {
content: Content::Countdown,
mode: Mode::Running,
show_menu: false,
}
}
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
while self.is_running() {
terminal

View File

@ -11,7 +11,7 @@ use color_eyre::{eyre::Context, Result};
fn main() -> Result<()> {
color_eyre::install()?;
let terminal = ratatui::init();
let app_result = App::new().run(terminal).context("app loop failed");
let app_result = App::default().run(terminal).context("app loop failed");
ratatui::restore();
app_result
}