mirror of
https://github.com/nikolassv/bartib
synced 2024-11-10 14:14:12 +00:00
commit
eccbc21972
12 changed files with 225 additions and 368 deletions
75
.github/workflows/test.yml
vendored
75
.github/workflows/test.yml
vendored
|
@ -10,14 +10,79 @@ env:
|
|||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Format
|
||||
run: cargo fmt --all --check
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
needs: format
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo
|
||||
target
|
||||
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: ${{ runner.os }}-build-
|
||||
- name: Install Clippy
|
||||
run: rustup component add clippy
|
||||
- name: Run Clippy
|
||||
run: cargo clippy -- -D warnings
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: lint
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain: [stable, beta, nightly]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo
|
||||
target
|
||||
key: ${{ runner.os }}-${{ matrix.toolchain }}-build-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.toolchain }}-build-
|
||||
${{ runner.os }}-build-
|
||||
- name: Set up Rust toolchain
|
||||
run: rustup toolchain install ${{ matrix.toolchain }}
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
- name: Build
|
||||
run: cargo +${{ matrix.toolchain }} build --verbose
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain: [stable, beta, nightly]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Cache Rust dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cargo
|
||||
target
|
||||
key: ${{ runner.os }}-${{ matrix.toolchain }}-build-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.toolchain }}-build-
|
||||
${{ runner.os }}-build-
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
- name: Set up Rust toolchain
|
||||
run: rustup toolchain install ${{ matrix.toolchain }}
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
run: cargo +${{ matrix.toolchain }} test --verbose
|
||||
|
|
348
Cargo.lock
generated
348
Cargo.lock
generated
|
@ -3,24 +3,10 @@
|
|||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.6"
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
|
@ -42,9 +28,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.70"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
|
@ -84,15 +70,18 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.1"
|
||||
version = "3.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8"
|
||||
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
@ -102,17 +91,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.24"
|
||||
version = "0.4.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
|
||||
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -130,86 +118,12 @@ dependencies = [
|
|||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
|
||||
dependencies = [
|
||||
"termcolor",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxxbridge-flags",
|
||||
"cxxbridge-macro",
|
||||
"link-cplusplus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx-build"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-flags"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb"
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-macro"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
|
@ -221,9 +135,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.56"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
|
||||
checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
|
@ -235,52 +149,33 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cxx",
|
||||
"cxx-build",
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.61"
|
||||
version = "0.3.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||
checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.142"
|
||||
version = "0.2.148"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
|
@ -292,30 +187,20 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
|
@ -325,45 +210,22 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
version = "1.0.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
|
||||
|
||||
[[package]]
|
||||
name = "scratch"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"
|
||||
|
||||
[[package]]
|
||||
name = "smawk"
|
||||
version = "0.3.1"
|
||||
|
@ -378,20 +240,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
version = "2.0.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
checksum = "88ec6cdb6a4c16306eccf52ccd8d492e4ab64705a15a5016acb205251001bf72"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -408,15 +259,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
|
@ -439,50 +281,35 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi 0.10.0+wasi-snapshot-preview1",
|
||||
"winapi",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-linebreak"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"regex",
|
||||
]
|
||||
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
|
@ -496,29 +323,11 @@ version = "0.8.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
|
@ -526,24 +335,24 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
|
@ -551,22 +360,22 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
|
@ -584,15 +393,6 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
@ -610,9 +410,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
|
@ -625,42 +425,42 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
|
|
@ -115,10 +115,10 @@ fn print_activity_with_line(activity: &Activity, line_number: usize) {
|
|||
"{} (Started: {}, Ended: {}, Line: {})\n",
|
||||
activity.description,
|
||||
activity.start.format(conf::FORMAT_DATETIME),
|
||||
activity
|
||||
.end
|
||||
.map(|end| end.format(conf::FORMAT_DATETIME).to_string())
|
||||
.unwrap_or_else(|| String::from("--")),
|
||||
activity.end.map_or_else(
|
||||
|| String::from("--"),
|
||||
|end| end.format(conf::FORMAT_DATETIME).to_string()
|
||||
),
|
||||
line_number
|
||||
)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ pub fn check(file_name: &str) -> Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
println!("Found {} line(s) with parsing errors", number_of_errors);
|
||||
println!("Found {number_of_errors} line(s) with parsing errors");
|
||||
|
||||
file_content
|
||||
.iter()
|
||||
|
@ -169,7 +169,7 @@ pub fn list_projects(file_name: &str, current: bool) -> Result<()> {
|
|||
all_projects.dedup();
|
||||
|
||||
for project in all_projects {
|
||||
println!("\"{}\"", project);
|
||||
println!("\"{project}\"");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -49,7 +49,7 @@ fn save_new_activity(
|
|||
|
||||
file_content.push(bartib_file::Line::for_activity(activity));
|
||||
bartib_file::write_to_file(file_name, file_content)
|
||||
.context(format!("Could not write to file: {}", file_name))
|
||||
.context(format!("Could not write to file: {file_name}"))
|
||||
}
|
||||
|
||||
pub fn change(
|
||||
|
@ -60,7 +60,7 @@ pub fn change(
|
|||
) -> Result<()> {
|
||||
let mut file_content = bartib_file::get_file_content(file_name)?;
|
||||
|
||||
for line in file_content.iter_mut() {
|
||||
for line in &mut file_content {
|
||||
if let Ok(activity) = &mut line.activity {
|
||||
if !activity.is_stopped() {
|
||||
let mut changed = false;
|
||||
|
@ -93,7 +93,7 @@ pub fn change(
|
|||
}
|
||||
}
|
||||
bartib_file::write_to_file(file_name, &file_content)
|
||||
.context(format!("Could not write to file: {}", file_name))
|
||||
.context(format!("Could not write to file: {file_name}"))
|
||||
}
|
||||
|
||||
// stops all currently running activities
|
||||
|
@ -101,7 +101,7 @@ pub fn stop(file_name: &str, time: Option<NaiveDateTime>) -> Result<()> {
|
|||
let mut file_content = bartib_file::get_file_content(file_name)?;
|
||||
stop_all_running_activities(&mut file_content, time);
|
||||
bartib_file::write_to_file(file_name, &file_content)
|
||||
.context(format!("Could not write to file: {}", file_name))
|
||||
.context(format!("Could not write to file: {file_name}"))
|
||||
}
|
||||
|
||||
// cancels all currently running activities
|
||||
|
@ -128,7 +128,7 @@ pub fn cancel(file_name: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
bartib_file::write_to_file(file_name, &new_file_content)
|
||||
.context(format!("Could not write to file: {}", file_name))
|
||||
.context(format!("Could not write to file: {file_name}"))
|
||||
}
|
||||
|
||||
// continue last activity
|
||||
|
|
|
@ -23,8 +23,9 @@ pub enum ActivityError {
|
|||
}
|
||||
|
||||
impl Activity {
|
||||
pub fn start(project: String, description: String, time: Option<NaiveDateTime>) -> Activity {
|
||||
Activity {
|
||||
#[must_use]
|
||||
pub fn start(project: String, description: String, time: Option<NaiveDateTime>) -> Self {
|
||||
Self {
|
||||
start: time.unwrap_or_else(|| Local::now().naive_local()),
|
||||
end: None,
|
||||
project,
|
||||
|
@ -36,10 +37,12 @@ impl Activity {
|
|||
self.end = time.or_else(|| Some(Local::now().naive_local()));
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_stopped(&self) -> bool {
|
||||
self.end.is_some()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_duration(&self) -> Duration {
|
||||
if let Some(end) = self.end {
|
||||
end.signed_duration_since(self.start)
|
||||
|
@ -101,7 +104,7 @@ impl FromStr for Activity {
|
|||
let project = parts[1].trim();
|
||||
let description = if parts.len() > 2 { parts[2].trim() } else { "" };
|
||||
|
||||
let activity = Activity {
|
||||
let activity = Self {
|
||||
start: starttime,
|
||||
end: endtime,
|
||||
project: project.to_string(),
|
||||
|
@ -133,9 +136,7 @@ impl Iterator for StringSplitter<'_> {
|
|||
fn next(&mut self) -> Option<String> {
|
||||
let mut next_char = self.chars.next();
|
||||
|
||||
if next_char.is_none() {
|
||||
return None;
|
||||
}
|
||||
next_char?;
|
||||
|
||||
let mut escaped = false;
|
||||
let mut collector = String::new();
|
||||
|
@ -202,13 +203,13 @@ mod tests {
|
|||
);
|
||||
t.start = NaiveDateTime::parse_from_str("2021-02-16 16:14", conf::FORMAT_DATETIME).unwrap();
|
||||
assert_eq!(
|
||||
format!("{}", t),
|
||||
format!("{t}"),
|
||||
"2021-02-16 16:14 | test project\\| 1 | test\\\\description\n"
|
||||
);
|
||||
t.end =
|
||||
Some(NaiveDateTime::parse_from_str("2021-02-16 18:23", conf::FORMAT_DATETIME).unwrap());
|
||||
assert_eq!(
|
||||
format!("{}", t),
|
||||
format!("{t}"),
|
||||
"2021-02-16 16:14 - 2021-02-16 18:23 | test project\\| 1 | test\\\\description\n"
|
||||
);
|
||||
}
|
||||
|
@ -240,7 +241,7 @@ mod tests {
|
|||
assert_eq!(t.start.time().hour(), 16);
|
||||
assert_eq!(t.start.time().minute(), 14);
|
||||
|
||||
assert_eq!(t.description, "".to_string());
|
||||
assert_eq!(t.description, String::new());
|
||||
assert_eq!(t.project, "test project".to_string());
|
||||
assert_eq!(t.end, None);
|
||||
}
|
||||
|
@ -283,7 +284,7 @@ mod tests {
|
|||
None,
|
||||
);
|
||||
t.stop(None);
|
||||
let t2 = Activity::from_str(format!("{}", t).as_str()).unwrap();
|
||||
let t2 = Activity::from_str(format!("{t}").as_str()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
t.start.with_second(0).unwrap().with_nanosecond(0).unwrap(),
|
||||
|
|
|
@ -28,8 +28,9 @@ pub struct Line {
|
|||
|
||||
impl Line {
|
||||
// creates a new line struct from plaintext
|
||||
pub fn new(plaintext: &str, line_number: usize) -> Line {
|
||||
Line {
|
||||
#[must_use]
|
||||
pub fn new(plaintext: &str, line_number: usize) -> Self {
|
||||
Self {
|
||||
plaintext: Some(plaintext.trim().to_string()),
|
||||
line_number: Some(line_number),
|
||||
activity: activity::Activity::from_str(plaintext),
|
||||
|
@ -38,8 +39,9 @@ impl Line {
|
|||
}
|
||||
|
||||
// creates a new line from an existing activity
|
||||
pub fn for_activity(activity: activity::Activity) -> Line {
|
||||
Line {
|
||||
#[must_use]
|
||||
pub fn for_activity(activity: activity::Activity) -> Self {
|
||||
Self {
|
||||
plaintext: None,
|
||||
line_number: None,
|
||||
activity: Ok(activity),
|
||||
|
@ -56,12 +58,12 @@ impl Line {
|
|||
// reads the content of a file to a vector of lines
|
||||
pub fn get_file_content(file_name: &str) -> Result<Vec<Line>> {
|
||||
let file_handler =
|
||||
File::open(file_name).context(format!("Could not read from file: {}", file_name))?;
|
||||
File::open(file_name).context(format!("Could not read from file: {file_name}"))?;
|
||||
let reader = BufReader::new(file_handler);
|
||||
|
||||
let lines = reader
|
||||
.lines()
|
||||
.filter_map(|line_result| line_result.ok())
|
||||
.map_while(Result::ok)
|
||||
.enumerate()
|
||||
.map(|(line_number, line)| Line::new(&line, line_number.saturating_add(1)))
|
||||
.collect();
|
||||
|
@ -77,7 +79,7 @@ pub fn write_to_file(file_name: &str, file_content: &[Line]) -> Result<(), io::E
|
|||
match &line.status {
|
||||
LineStatus::Unchanged => {
|
||||
if let Some(plaintext) = &line.plaintext {
|
||||
writeln!(&file_handler, "{}", plaintext)?
|
||||
writeln!(&file_handler, "{plaintext}")?
|
||||
} else {
|
||||
write!(&file_handler, "{}", line.activity.as_ref().unwrap())?
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ pub struct ActivityFilter<'a> {
|
|||
pub project: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_descriptions_and_projects(
|
||||
file_content: &[bartib_file::Line],
|
||||
) -> Vec<(&String, &String)> {
|
||||
|
@ -49,6 +50,7 @@ fn get_descriptions_and_projects_from_activities<'a>(
|
|||
descriptions_and_projects
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_running_activities(file_content: &[bartib_file::Line]) -> Vec<&activity::Activity> {
|
||||
get_activities(file_content)
|
||||
.filter(|activity| !activity.is_stopped())
|
||||
|
@ -91,14 +93,10 @@ pub fn filter_activities<'a>(
|
|||
.filter(move |activity| {
|
||||
activity.start.date() >= from_date && activity.start.date() <= to_date
|
||||
})
|
||||
.filter(move |activity| {
|
||||
filter
|
||||
.project
|
||||
.map(|p| activity.project == *p)
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.filter(move |activity| filter.project.map_or(true, |p| activity.project == *p))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_last_activity_by_end(file_content: &[bartib_file::Line]) -> Option<&activity::Activity> {
|
||||
get_activities(file_content)
|
||||
.filter(|activity| activity.is_stopped())
|
||||
|
@ -109,6 +107,7 @@ pub fn get_last_activity_by_end(file_content: &[bartib_file::Line]) -> Option<&a
|
|||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_last_activity_by_start(
|
||||
file_content: &[bartib_file::Line],
|
||||
) -> Option<&activity::Activity> {
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use anyhow::{bail, Context, Result};
|
||||
use chrono::{Datelike, Duration, Local, NaiveDate, NaiveTime};
|
||||
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand, crate_version};
|
||||
use clap::{crate_version, App, AppSettings, Arg, ArgMatches, SubCommand};
|
||||
|
||||
use bartib::data::getter::ActivityFilter;
|
||||
#[cfg(windows)]
|
||||
|
@ -347,9 +347,9 @@ fn create_filter_for_arguments<'a>(sub_m: &'a ArgMatches) -> ActivityFilter<'a>
|
|||
|
||||
if sub_m.is_present("current_week") {
|
||||
filter.from_date =
|
||||
Some(today - Duration::days(today.weekday().num_days_from_monday() as i64));
|
||||
Some(today - Duration::days(i64::from(today.weekday().num_days_from_monday())));
|
||||
filter.to_date = Some(
|
||||
today - Duration::days(today.weekday().num_days_from_monday() as i64)
|
||||
today - Duration::days(i64::from(today.weekday().num_days_from_monday()))
|
||||
+ Duration::days(6),
|
||||
);
|
||||
}
|
||||
|
@ -357,12 +357,12 @@ fn create_filter_for_arguments<'a>(sub_m: &'a ArgMatches) -> ActivityFilter<'a>
|
|||
if sub_m.is_present("last_week") {
|
||||
filter.from_date = Some(
|
||||
today
|
||||
- Duration::days(today.weekday().num_days_from_monday() as i64)
|
||||
- Duration::days(i64::from(today.weekday().num_days_from_monday()))
|
||||
- Duration::weeks(1),
|
||||
);
|
||||
filter.to_date = Some(
|
||||
today
|
||||
- Duration::days(today.weekday().num_days_from_monday() as i64)
|
||||
- Duration::days(i64::from(today.weekday().num_days_from_monday()))
|
||||
- Duration::weeks(1)
|
||||
+ Duration::days(6),
|
||||
)
|
||||
|
@ -382,8 +382,7 @@ fn get_number_argument_or_ignore(
|
|||
Some(number)
|
||||
} else {
|
||||
println!(
|
||||
"Can not parse \"{}\" as number. Argument for {} is ignored",
|
||||
number_string, argument_name
|
||||
"Can not parse \"{number_string}\" as number. Argument for {argument_name} is ignored"
|
||||
);
|
||||
None
|
||||
}
|
||||
|
@ -403,8 +402,7 @@ fn get_date_argument_or_ignore(
|
|||
Ok(date) => Some(date),
|
||||
Err(parsing_error) => {
|
||||
println!(
|
||||
"Can not parse \"{}\" as date. Argument for {} is ignored ({})",
|
||||
date_string, argument_name, parsing_error
|
||||
"Can not parse \"{date_string}\" as date. Argument for {argument_name} is ignored ({parsing_error})"
|
||||
);
|
||||
None
|
||||
}
|
||||
|
@ -425,8 +423,7 @@ fn get_time_argument_or_ignore(
|
|||
Ok(date) => Some(date),
|
||||
Err(parsing_error) => {
|
||||
println!(
|
||||
"Can not parse \"{}\" as time. Argument for {} is ignored ({})",
|
||||
time_string, argument_name, parsing_error
|
||||
"Can not parse \"{time_string}\" as time. Argument for {argument_name} is ignored ({parsing_error})"
|
||||
);
|
||||
None
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub fn format_duration(duration: &Duration) -> String {
|
|||
if duration.num_minutes() > 0 {
|
||||
duration_string.push_str(&format!("{:0>2}m", duration.num_minutes() % 60));
|
||||
} else {
|
||||
duration_string.push_str(&format!("<1m"));
|
||||
duration_string.push_str("<1m");
|
||||
}
|
||||
|
||||
duration_string
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn list_activities(activities: &[&activity::Activity], with_start_dates: boo
|
|||
.map(|t| get_activity_table_row(t, with_start_dates))
|
||||
.for_each(|row| activity_table.add_row(row));
|
||||
|
||||
println!("\n{}", activity_table);
|
||||
println!("\n{activity_table}");
|
||||
}
|
||||
|
||||
// list activities grouped by the dates of their start time
|
||||
|
@ -36,11 +36,11 @@ pub fn list_activities_grouped_by_date(activities: &[&activity::Activity]) {
|
|||
group_activities_by_date(activities)
|
||||
.iter()
|
||||
.map(|(date, activity_list)| {
|
||||
create_activities_group(&format!("{}", date), activity_list.as_slice())
|
||||
create_activities_group(&format!("{date}"), activity_list.as_slice())
|
||||
})
|
||||
.for_each(|g| activity_table.add_group(g));
|
||||
|
||||
println!("\n{}", activity_table);
|
||||
println!("\n{activity_table}");
|
||||
}
|
||||
|
||||
fn create_activity_table() -> table::Table {
|
||||
|
@ -112,7 +112,7 @@ pub fn list_running_activities(activities: &[&activity::Activity]) {
|
|||
})
|
||||
.for_each(|row| activity_table.add_row(row));
|
||||
|
||||
println!("\n{}", activity_table);
|
||||
println!("\n{activity_table}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,12 +143,12 @@ pub fn list_descriptions_and_projects(descriptions_and_projects: &[(&String, &St
|
|||
|
||||
descriptions_and_projects_table.add_row(table::Row::new(vec![
|
||||
format!("[{}]", i),
|
||||
description.to_string(),
|
||||
project.to_string(),
|
||||
(*description).to_string(),
|
||||
(*project).to_string(),
|
||||
]));
|
||||
}
|
||||
|
||||
println!("\n{}", descriptions_and_projects_table);
|
||||
println!("\n{descriptions_and_projects_table}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ fn group_activities_by_date<'a>(
|
|||
) -> BTreeMap<NaiveDate, Vec<&'a activity::Activity>> {
|
||||
let mut activities_by_date = BTreeMap::new();
|
||||
|
||||
for &activity in activities.iter() {
|
||||
for &activity in activities {
|
||||
activities_by_date
|
||||
.entry(activity.start.date())
|
||||
.or_insert_with(Vec::new)
|
||||
|
|
|
@ -32,15 +32,13 @@ impl<'a> fmt::Display for Report<'a> {
|
|||
let mut longest_line = get_longest_line(&self.project_map).unwrap_or(0);
|
||||
let longest_duration_string = get_longest_duration_string(self).unwrap_or(0);
|
||||
|
||||
let terminal_width = term_size::dimensions_stdout()
|
||||
.map(|d| d.0)
|
||||
.unwrap_or(conf::DEFAULT_WIDTH);
|
||||
let terminal_width = term_size::dimensions_stdout().map_or(conf::DEFAULT_WIDTH, |d| d.0);
|
||||
|
||||
if terminal_width < longest_line + longest_duration_string + 1 {
|
||||
longest_line = terminal_width - longest_duration_string - 1;
|
||||
}
|
||||
|
||||
for (project, (activities, duration)) in self.project_map.iter() {
|
||||
for (project, (activities, duration)) in &self.project_map {
|
||||
print_project_heading(f, project, duration, longest_line, longest_duration_string)?;
|
||||
|
||||
print_descriptions_with_durations(
|
||||
|
@ -60,21 +58,21 @@ impl<'a> fmt::Display for Report<'a> {
|
|||
|
||||
pub fn show_activities<'a>(activities: &'a [&'a activity::Activity]) {
|
||||
let report = Report::new(activities);
|
||||
println!("\n{}", report);
|
||||
println!("\n{report}");
|
||||
}
|
||||
|
||||
fn create_project_map<'a>(activities: &'a [&'a activity::Activity]) -> ProjectMap {
|
||||
let mut project_map: ProjectMap = BTreeMap::new();
|
||||
|
||||
activities.iter().for_each(|a| {
|
||||
for a in activities {
|
||||
project_map
|
||||
.entry(&a.project)
|
||||
.or_insert_with(|| (Vec::<&'a activity::Activity>::new(), Duration::seconds(0)))
|
||||
.0
|
||||
.push(a);
|
||||
});
|
||||
}
|
||||
|
||||
for (_project, (activities, duration)) in project_map.iter_mut() {
|
||||
for (activities, duration) in project_map.values_mut() {
|
||||
*duration = sum_duration(activities);
|
||||
}
|
||||
|
||||
|
@ -103,7 +101,7 @@ fn print_project_heading(
|
|||
|
||||
for (i, line) in project_lines.iter().enumerate() {
|
||||
if i + 1 < project_lines.len() {
|
||||
writeln!(f, "{}", line)?;
|
||||
writeln!(f, "{line}")?;
|
||||
} else {
|
||||
write!(
|
||||
f,
|
||||
|
@ -131,13 +129,13 @@ fn print_descriptions_with_durations<'a>(
|
|||
.initial_indent(&indent_string)
|
||||
.subsequent_indent(&indent_string);
|
||||
|
||||
for (description, activities) in description_map.iter() {
|
||||
for (description, activities) in &description_map {
|
||||
let description_duration = sum_duration(activities);
|
||||
let description_lines = textwrap::wrap(description, &wrapping_options);
|
||||
|
||||
for (i, line) in description_lines.iter().enumerate() {
|
||||
if i + 1 < description_lines.len() {
|
||||
writeln!(f, "{}", line)?;
|
||||
writeln!(f, "{line}")?;
|
||||
} else {
|
||||
writeln!(
|
||||
f,
|
||||
|
@ -177,12 +175,12 @@ fn group_activities_by_description<'a>(
|
|||
) -> BTreeMap<&str, Vec<&'a activity::Activity>> {
|
||||
let mut activity_map: BTreeMap<&str, Vec<&'a activity::Activity>> = BTreeMap::new();
|
||||
|
||||
activities.iter().for_each(|a| {
|
||||
for a in activities {
|
||||
activity_map
|
||||
.entry(&a.description)
|
||||
.or_insert_with(Vec::<&'a activity::Activity>::new)
|
||||
.push(a);
|
||||
});
|
||||
}
|
||||
|
||||
activity_map
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ pub struct Table {
|
|||
}
|
||||
|
||||
impl Row {
|
||||
pub fn new(content: Vec<String>) -> Row {
|
||||
Row {
|
||||
pub fn new(content: Vec<String>) -> Self {
|
||||
Self {
|
||||
content,
|
||||
style: None,
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ impl Row {
|
|||
}
|
||||
|
||||
impl Group {
|
||||
pub fn new(title: Option<String>, rows: Vec<Row>) -> Group {
|
||||
Group { title, rows }
|
||||
pub fn new(title: Option<String>, rows: Vec<Row>) -> Self {
|
||||
Self { title, rows }
|
||||
}
|
||||
}
|
||||
|
||||
impl Table {
|
||||
pub fn new(columns: Vec<Column>) -> Table {
|
||||
Table {
|
||||
pub fn new(columns: Vec<Column>) -> Self {
|
||||
Self {
|
||||
columns,
|
||||
groups: Vec::new(),
|
||||
rows: Vec::new(),
|
||||
|
@ -190,9 +190,7 @@ impl Table {
|
|||
|
||||
impl fmt::Display for Table {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let terminal_width = term_size::dimensions_stdout()
|
||||
.map(|d| d.0)
|
||||
.unwrap_or(conf::DEFAULT_WIDTH);
|
||||
let terminal_width = term_size::dimensions_stdout().map_or(conf::DEFAULT_WIDTH, |d| d.0);
|
||||
|
||||
let column_width = self.get_column_width(terminal_width - self.columns.len());
|
||||
|
||||
|
@ -214,7 +212,7 @@ impl fmt::Display for Table {
|
|||
}
|
||||
|
||||
fn write_group(f: &mut fmt::Formatter<'_>, group: &Group, column_width: &[usize]) -> fmt::Result {
|
||||
let empty_string = "".to_string();
|
||||
let empty_string = String::new();
|
||||
let title = group.title.as_ref().unwrap_or(&empty_string);
|
||||
|
||||
writeln!(f)?;
|
||||
|
@ -250,7 +248,11 @@ fn write_cells<T: AsRef<str> + std::fmt::Display>(
|
|||
})
|
||||
.collect();
|
||||
|
||||
let most_lines: usize = wrapped_cells.iter().map(|c| c.len()).max().unwrap_or(1);
|
||||
let most_lines: usize = wrapped_cells
|
||||
.iter()
|
||||
.map(std::vec::Vec::len)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
|
||||
for line in 0..most_lines {
|
||||
for (width, wrapped_cell) in column_width.iter().zip(wrapped_cells.iter()) {
|
||||
|
@ -275,19 +277,12 @@ fn write_with_width_and_style(
|
|||
width: &usize,
|
||||
opt_style: Option<Style>,
|
||||
) -> fmt::Result {
|
||||
let style_prefix = opt_style.map_or("".to_string(), |style| style.prefix().to_string());
|
||||
let style_suffix = opt_style.map_or("".to_string(), |style| style.suffix().to_string());
|
||||
let style_prefix = opt_style.map_or(String::new(), |style| style.prefix().to_string());
|
||||
let style_suffix = opt_style.map_or(String::new(), |style| style.suffix().to_string());
|
||||
|
||||
// cells are filled with non-breaking white space. Contrary to normal spaces non-breaking white
|
||||
// space will be styled (e.g. underlined)
|
||||
write!(
|
||||
f,
|
||||
"{prefix}{content:\u{a0}<width$}{suffix} ", // pad with non breaking space
|
||||
prefix = style_prefix,
|
||||
content = content,
|
||||
width = width,
|
||||
suffix = style_suffix
|
||||
)
|
||||
write!(f, "{style_prefix}{content:\u{a0}<width$}{style_suffix} ")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -467,7 +462,7 @@ mod tests {
|
|||
t.add_row(row2);
|
||||
|
||||
assert_eq!(
|
||||
format!("{}", t),
|
||||
format!("{t}"),
|
||||
"\u{1b}[4ma\u{a0}\u{a0}\u{1b}[0m \u{1b}[4mb\u{a0}\u{a0}\u{a0}\u{1b}[0m \u{1b}[4mc\u{a0}\u{a0}\u{a0}\u{1b}[0m \nabc defg \na\u{a0}\u{a0} b\u{a0}\u{a0}\u{a0} cdef \n"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue