add progress estimation based on several samples

This commit is contained in:
Matthieu Jolimaitre 2025-08-01 11:10:10 +02:00
parent 669b9ac56a
commit f58632c025
3 changed files with 24 additions and 8 deletions

View file

@ -16,12 +16,12 @@ version="$(./regar -V)"
sed -E -i ../src/PKGBUILD -e "s/^sha256sums=.*\$/sha256sums=(\"$checksum\")/g"
sed -E -i ../src/PKGBUILD -e "s/^pkgver=.*\$/pkgver=$version/g"
git clone ssh://aur@aur.archlinux.org/regar-bin.git
cd regar-bin
cp ../../src/PKGBUILD ./PKGBUILD
makepkg -sf
makepkg --printsrcinfo > .SRCINFO
exit
added="$(git add -v PKGBUILD .SRCINFO)"
if [ ".$added" != "." ]
then

View file

@ -1,13 +1,13 @@
# Maintainer: JOLIMAITRE Matthieu <matthieu@imagevo.fr>
pkgname="regar-bin"
pkgver=1.1.0
pkgver=1.1.2
pkgrel=1
pkgdesc="Cli for watching file changes and running commands periodically."
url="https://git.barnulf.net/mb/regar"
arch=("x86_64")
license=('MIT')
source=("https://git.barnulf.net/api/packages/mb/generic/regar/latest/regar-x86_64-unknown-linux-gnu.zip")
sha256sums=("c9b125d06f5085561e80335435baa57697442c3ba0d219cea854eff84f4af1e2")
sha256sums=("a8556e48382320432b0083d4aaa1af2e45097aa02a01340690b28f78197468bd")
options=("!strip")
provides=("regar")

View file

@ -5,7 +5,7 @@ import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts"
import { Channel, Constructible, InstanceOf } from "https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/mod.ts"
import { wait } from "https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/utils.ts"
const version = "1.1.1"
const version = "1.1.2"
async function main() {
const { do_clear, command, extensions, files, strategy, go_up, show_progress } = await parse_args()
@ -118,7 +118,7 @@ class Runner {
return (status: Deno.CommandStatus) => {
const end_ms = Date.now()
const time_ms = end_ms - start_ms
if (status.success) this.time_estimation_ms = time_ms
if (status.success) this.estimator.add(time_ms)
const secs = time_ms / 1000
if (this.go_up) this.restore_cursor()
if (stop !== undefined) stop.stop = true
@ -135,14 +135,14 @@ class Runner {
console.log("\x1b[u")
}
time_estimation_ms = 0
estimator = new Estimator(Math.max)
private start_progress() {
const stop = { stop: false }
;(async () => {
for await (const step of progress(this.time_estimation_ms)) {
for await (const step of progress(this.estimator.estimate())) {
if (stop.stop) break
const secs = (Math.floor(step.ms / 100) / 10).toString().padStart(3)
const total = Math.floor(this.time_estimation_ms / 1_000).toString().padStart(3)
const total = Math.floor(this.estimator.estimate() / 1_000).toString().padStart(3)
const perc = (Math.floor(step.relative * 1_000) / 10).toString().padStart(5)
console.log("")
log("progress", `${secs} s / ${total} s (${perc} %)`)
@ -234,6 +234,22 @@ function catch_<T, R, Cs extends Catching<any, R>[]>(op: () => T, ...catchings:
}
}
class Estimator {
private readonly measures = Array<number>()
public constructor(
private readonly estimation: (...measures: Array<number>) => number,
) {}
public add(measure: number) {
this.measures.push(measure)
}
public estimate() {
return this.estimation(...this.measures)
}
}
function log(verb: string, value: unknown) {
const yellow = "\x1b[0;33m"
const bold = "\x1b[1m"