add progress estimation based on several samples
This commit is contained in:
parent
669b9ac56a
commit
f58632c025
3 changed files with 24 additions and 8 deletions
|
@ -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/^sha256sums=.*\$/sha256sums=(\"$checksum\")/g"
|
||||||
sed -E -i ../src/PKGBUILD -e "s/^pkgver=.*\$/pkgver=$version/g"
|
sed -E -i ../src/PKGBUILD -e "s/^pkgver=.*\$/pkgver=$version/g"
|
||||||
|
|
||||||
|
|
||||||
git clone ssh://aur@aur.archlinux.org/regar-bin.git
|
git clone ssh://aur@aur.archlinux.org/regar-bin.git
|
||||||
cd regar-bin
|
cd regar-bin
|
||||||
cp ../../src/PKGBUILD ./PKGBUILD
|
cp ../../src/PKGBUILD ./PKGBUILD
|
||||||
makepkg -sf
|
makepkg -sf
|
||||||
makepkg --printsrcinfo > .SRCINFO
|
makepkg --printsrcinfo > .SRCINFO
|
||||||
|
exit
|
||||||
added="$(git add -v PKGBUILD .SRCINFO)"
|
added="$(git add -v PKGBUILD .SRCINFO)"
|
||||||
if [ ".$added" != "." ]
|
if [ ".$added" != "." ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# Maintainer: JOLIMAITRE Matthieu <matthieu@imagevo.fr>
|
# Maintainer: JOLIMAITRE Matthieu <matthieu@imagevo.fr>
|
||||||
pkgname="regar-bin"
|
pkgname="regar-bin"
|
||||||
pkgver=1.1.0
|
pkgver=1.1.2
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Cli for watching file changes and running commands periodically."
|
pkgdesc="Cli for watching file changes and running commands periodically."
|
||||||
url="https://git.barnulf.net/mb/regar"
|
url="https://git.barnulf.net/mb/regar"
|
||||||
arch=("x86_64")
|
arch=("x86_64")
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
source=("https://git.barnulf.net/api/packages/mb/generic/regar/latest/regar-x86_64-unknown-linux-gnu.zip")
|
source=("https://git.barnulf.net/api/packages/mb/generic/regar/latest/regar-x86_64-unknown-linux-gnu.zip")
|
||||||
sha256sums=("c9b125d06f5085561e80335435baa57697442c3ba0d219cea854eff84f4af1e2")
|
sha256sums=("a8556e48382320432b0083d4aaa1af2e45097aa02a01340690b28f78197468bd")
|
||||||
options=("!strip")
|
options=("!strip")
|
||||||
provides=("regar")
|
provides=("regar")
|
||||||
|
|
||||||
|
|
26
src/regar.ts
26
src/regar.ts
|
@ -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 { 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"
|
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() {
|
async function main() {
|
||||||
const { do_clear, command, extensions, files, strategy, go_up, show_progress } = await parse_args()
|
const { do_clear, command, extensions, files, strategy, go_up, show_progress } = await parse_args()
|
||||||
|
@ -118,7 +118,7 @@ class Runner {
|
||||||
return (status: Deno.CommandStatus) => {
|
return (status: Deno.CommandStatus) => {
|
||||||
const end_ms = Date.now()
|
const end_ms = Date.now()
|
||||||
const time_ms = end_ms - start_ms
|
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
|
const secs = time_ms / 1000
|
||||||
if (this.go_up) this.restore_cursor()
|
if (this.go_up) this.restore_cursor()
|
||||||
if (stop !== undefined) stop.stop = true
|
if (stop !== undefined) stop.stop = true
|
||||||
|
@ -135,14 +135,14 @@ class Runner {
|
||||||
console.log("\x1b[u")
|
console.log("\x1b[u")
|
||||||
}
|
}
|
||||||
|
|
||||||
time_estimation_ms = 0
|
estimator = new Estimator(Math.max)
|
||||||
private start_progress() {
|
private start_progress() {
|
||||||
const stop = { stop: false }
|
const stop = { stop: false }
|
||||||
;(async () => {
|
;(async () => {
|
||||||
for await (const step of progress(this.time_estimation_ms)) {
|
for await (const step of progress(this.estimator.estimate())) {
|
||||||
if (stop.stop) break
|
if (stop.stop) break
|
||||||
const secs = (Math.floor(step.ms / 100) / 10).toString().padStart(3)
|
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)
|
const perc = (Math.floor(step.relative * 1_000) / 10).toString().padStart(5)
|
||||||
console.log("")
|
console.log("")
|
||||||
log("progress", `${secs} s / ${total} s (${perc} %)`)
|
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) {
|
function log(verb: string, value: unknown) {
|
||||||
const yellow = "\x1b[0;33m"
|
const yellow = "\x1b[0;33m"
|
||||||
const bold = "\x1b[1m"
|
const bold = "\x1b[1m"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue