Comments (9)
It's quite common for multiple progress bars (ie docker) and less so for spinners.
Minikube is an example that uses multiple spinners on setup to show a series of async tasks running.
Multiple spinners can be useful for anytime you need to do tasks in parallel, but can't really track individual progress steps.
from deno_std.
This is a reasonable expectation for a spinner implementation. SGTM.
from deno_std.
(Sharing another point raised in an offline discussion.)
When there are multiple things going on in CLI tools, I often see the single loading indicator with the message part changing quickly (e.g. npm install
shows its progress in this way). I guess that would be more common way to show the progress of multiple things in a terminal app.
from deno_std.
Is this common pattern in cli tool development? I personally don't often see the multiple spinners in cli tools in general.
from deno_std.
I also don't see it often, but maybe that's because there is no popular library for this yet? I could only find these two:
- https://github.com/jbcarpanelli/spinnies (last commit 5 years ago)
- https://github.com/codekirei/node-multispinner (last commit 9 years ago)
from deno_std.
Btw, the snippet I shared above is broken in so many ways, so whoever implements this shouldn't take much inspiration from it. It turned out to be a bit more challenging to do this right, especially when trying to support "nested" spinners (s1 starts - s2 starts - s2 stops - s1 stops) or when trying to combine spinners with normal console.log
output.
from deno_std.
Popular npm packages (ora, cli-spinners) that implement spinners don't support multiple spinners. I'm skeptical the users need this feature.
If we add this feature, I expect the added complexity won't be small. I wonder if it's worth the effort for such rarely used feature.
Minikube is an example that uses multiple spinners on setup to show a series of async tasks running.
Can anybody give more examples of multiple loading indicators in CLI tools? If minikube is only common example, then it feels too rare feature to provide support in the standard library.
from deno_std.
Hmm, fair point. This may not be worth the added complexity incurred. I think this is fine as long as we provide justification and possible workarounds in the documentation.
from deno_std.
Yeah...currently in my project, I went forward with a "single-line" approach as well, to track multiple, especially nested, processes, looking like this:
import { Spinner } from "@std/cli";
/**
* @implements {Spinner}
* @extends {Spinner}
* @example
* const loader = new Loader({
* color: "blue",
* message: "Loading..."
* });
*
* loader.start(); // "Loading..."
*
* await new Promise((resolve) => setTimeout(resolve, 1000));
*
* loader.setBlock("block1", "a"); // "1 | a"
*
* await new Promise((resolve) => setTimeout(resolve, 1000));
*
* loader.setBlock("block1", "b"); // "2 | b"
* loader.setBlock("block2", "c"); // "3 | b | c"
*
* await new Promise((resolve) => setTimeout(resolve, 1000));
*
* loader.removeBlock("block1"); // "4 | c"
*
* await new Promise((resolve) => setTimeout(resolve, 1000));
*
* loader.stop();
*/
const Loader = class extends Spinner {
/**
* @type {Map<unknown, string>}
*/
#blocks = new Map();
/**
* @type {Map<unknown, number>}
*/
#maximumLengths = new Map();
/**
* @type {number}
*/
#messageCount = 0;
/**
* @type {unknown[]}
*/
#order = [];
/**
* Updates the message.
*
* @example
* this.#updateMessage();
*/
#updateMessage = () => {
this.message = [
this.#messageCount,
...this.#order
.filter((blockId) => this.#blocks.has(blockId))
.map((blockId, index) => {
const blockValue = this.#blocks.get(blockId);
return (
index === 0
? blockValue
: blockValue.padStart(this.#maximumLengths.get(blockId))
);
})
]
.join(" | ");
};
/**
*
* @param {unknown} id - The id of the block.
* @example
* const loader = new Loader({
* color: "blue",
* message: "Loading..."
* });
*
* loader.start();
*
* loader.setBlock("block1", "value1");
*
* loader.removeBlock("block1");
*
* loader.stop();
*/
removeBlock = (id) => {
this.#blocks.delete(id);
this.#messageCount += 1;
if (this.#messageCount % 1 === 0) {
this.#updateMessage();
}
};
/**
* Set the value of a block.
*
* @param {unknown} id - The id of the block.
* @param {string|number|boolean} value - The value of the block.
* @example
* const loader = new Loader({
* color: "blue",
* message: "Loading..."
* });
*
* loader.start();
*
* loader.setBlock("block1", "value1");
*
* loader.stop();
*/
setBlock = (id, value) => {
const valueString = String(value);
this.#maximumLengths.set(id, Math.max(
this.#maximumLengths.get(id) ?? 0,
valueString.length
));
this.#blocks.set(id, valueString);
if (!this.#order.includes(id)) {
this.#order.push(id);
}
this.#messageCount += 1;
this.#updateMessage();
};
};
export default Loader;
Bildschirmaufnahme.2024-06-18.um.17.25.55.mov
Bildschirmaufnahme.2024-06-18.um.17.24.09.mov
It works for now, but if the list of things I want to track gets longer, one line might just not be enough.
from deno_std.
Related Issues (20)
- Support Cookies Having Independent Partitioned State (CHIPS)/Partioned cookies in http/cookie.ts HOT 1
- deleteCookie doesn't allow deleting cookies with the SameSite, Secure or unparsed attributes set
- proposal: drop `std/io` from the first stabilization targets HOT 4
- bug: packages appear twice in dependency graph
- to-do: remove access modifiers across the codebase HOT 1
- feature request(streams): lines(readable): AsyncIterable<string> HOT 6
- suggestion: internal `assertStrictThrows()` and `assertStrictRejects()` HOT 4
- fs: `copy` with `{ preserveTimestamps: true }` does not update the timestamps of symlinks HOT 2
- to-do: investigate possibly unreachable LOC in `@std/streams/delimiter-stream`
- fs: enable `ensureSymlink() works with URLs` test case on windows.
- proposal: remove non-default schema support from yaml HOT 3
- bug(cli): `Spinner.stop() terminates the sequence` test failure
- text: Add `algorithm` option to string comparison functions HOT 4
- proposal: do not expose implementation details of yaml schemas HOT 5
- yaml: Rename negative property names in options HOT 2
- suggestion: remove `iterator` argument from `parseAll()` in `@std/yaml`
- suggestion: rename `verifyCookie()` to `verifySignedCookie()` in `@std/http/signed-cookie` HOT 1
- proposal(http): rename `calculate` to `eTag` HOT 1
- proposal(http): rename `Entity` to `ETagSource` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno_std.