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:
parent
a9e573122d
commit
3d0d55c8d8
39
.github/workflows/ci.yml
vendored
Normal file
39
.github/workflows/ci.yml
vendored
Normal 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
17
.zed/settings.json
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
README.md
30
README.md
@ -1,6 +1,6 @@
|
|||||||
# tim:r
|
# tim:r
|
||||||
|
|
||||||
## Development
|
## Build from source
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
@ -13,17 +13,20 @@ If `direnv` is installed, run `direnv allow` once to install dependencies. Other
|
|||||||
|
|
||||||
#### Non Nix user
|
#### 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
|
```sh
|
||||||
cargo run
|
cargo run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Build release
|
#### Build
|
||||||
|
|
||||||
- Linux
|
- Linux
|
||||||
```sh
|
```sh
|
||||||
@ -34,3 +37,22 @@ nix build
|
|||||||
```sh
|
```sh
|
||||||
nix build .#windows
|
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`
|
||||||
|
```
|
||||||
|
|||||||
24
flake.nix
24
flake.nix
@ -28,6 +28,7 @@
|
|||||||
cargoArtifacts = craneLib.buildDepsOnly {
|
cargoArtifacts = craneLib.buildDepsOnly {
|
||||||
src = craneLib.cleanCargoSource ./.;
|
src = craneLib.cleanCargoSource ./.;
|
||||||
};
|
};
|
||||||
|
doCheck = false; # skip tests during nix build
|
||||||
};
|
};
|
||||||
|
|
||||||
# Native build
|
# Native build
|
||||||
@ -64,20 +65,17 @@
|
|||||||
windows = crossBuild;
|
windows = crossBuild;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Separate artifacts for CI caching
|
|
||||||
checks = {
|
|
||||||
inherit timr;
|
|
||||||
cargoArtifacts = commonArgs.cargoArtifacts;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Development shell with all necessary tools
|
# Development shell with all necessary tools
|
||||||
devShells.default = pkgs.mkShell {
|
devShell = with nixpkgs.legacyPackages.${system}; mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with fenix.packages.${system}.stable; [
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
clippy
|
clippy
|
||||||
rustfmt
|
rustfmt
|
||||||
toolchain
|
toolchain
|
||||||
];
|
just
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inherit (commonArgs) src;
|
inherit (commonArgs) src;
|
||||||
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
||||||
|
|||||||
32
justfile
Normal file
32
justfile
Normal 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
|
||||||
17
src/app.rs
17
src/app.rs
@ -7,27 +7,28 @@ use ratatui::{
|
|||||||
widgets::{Block, Paragraph, Widget},
|
widgets::{Block, Paragraph, Widget},
|
||||||
DefaultTerminal, Frame,
|
DefaultTerminal, Frame,
|
||||||
};
|
};
|
||||||
use strum::{Display, EnumIter, FromRepr};
|
|
||||||
|
|
||||||
use crate::footer::Footer;
|
use crate::footer::Footer;
|
||||||
use crate::pomodoro::Pomodoro;
|
use crate::pomodoro::Pomodoro;
|
||||||
use crate::timer::Timer;
|
use crate::timer::Timer;
|
||||||
use crate::{countdown::Countdown, utils::center};
|
use crate::{countdown::Countdown, utils::center};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||||
enum Mode {
|
enum Mode {
|
||||||
|
#[default]
|
||||||
Running,
|
Running,
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Display, EnumIter, FromRepr, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Content {
|
pub enum Content {
|
||||||
|
#[default]
|
||||||
Countdown,
|
Countdown,
|
||||||
Timer,
|
Timer,
|
||||||
Pomodoro,
|
Pomodoro,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
content: Content,
|
content: Content,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
@ -35,14 +36,6 @@ pub struct App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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<()> {
|
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
|
||||||
while self.is_running() {
|
while self.is_running() {
|
||||||
terminal
|
terminal
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use color_eyre::{eyre::Context, Result};
|
|||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
let terminal = ratatui::init();
|
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();
|
ratatui::restore();
|
||||||
app_result
|
app_result
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user