👨💻 Последние статьи из моего блога:
Обновлено 2024-05-06 09:01
🌀 The simplest and tiniest terminal spinner for Node.js
Home Page: https://npm.im/nanospinner
License: ISC License
👨💻 Последние статьи из моего блога:
Обновлено 2024-05-06 09:01
ora
is your main enemy, not mico-spinner
.
Hi 👋🏻
I'm trying to setup 2 spinners at the same time, but it looks like i can't. My code:
import { createSpinner } from 'nanospinner';
const a = createSpinner('Spinner A').start();
const b = createSpinner('Spinner B').start();
setTimeout(() => {
a.success();
b.success();
process.exit(0);
}, 3000);
Result:
When exiting in the loading state (e.g. ctrl
+ c
), the cursor is still hidden.
Do you think it's better to listen to SIGINT
to restore the cursor when exit?
(Willing to contribute a PR for this. Also if there is anything inappropriate please point it out directly :)
I am currently working on a node script to update a dataset generated from a bunch fetch requests. I decided to add nanospinners to the fetchData function I have set up to fetch one or multiple json endpoints and it appears to have caused a memory leak:
(node:17186) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at process.addListener (events.js:406:10)
at Object.start (/home/mitsunee/Projects/fgo-tools/node_modules/nanospinner/index.js:54:15)
at fetchData (file:///home/mitsunee/Projects/fgo-tools/scripts/update-upgrades-data.mjs:230:11)
at fetchQuestData (file:///home/mitsunee/Projects/fgo-tools/scripts/update-upgrades-data.mjs:245:42)
at main (file:///home/mitsunee/Projects/fgo-tools/scripts/update-upgrades-data.mjs:401:44)
Here is an excerpt from the script in question (I haven't pushed my changes yet, so I'm copypasting it here for reference)
async function fetchData(url, defaultValue, message = "Fetching Data") {
const spinner = createSpinner(message);
const _fetch = async (url, defaultValue) => {
try {
const res = await fetch(url);
if (!res.ok) {
if (defaultValue === undefined) {
spinner.error(`error while fetching '${url}'`);
process.exit(2);
}
return defaultValue;
}
return await res.json();
} catch (e) {
if (defaultValue === undefined) {
spinner.error(`received invalid data from '${url}'`);
process.exit(2);
}
return defaultValue;
}
};
let res;
spinner.start();
if (url instanceof Array) {
res = await Promise.all(
url.map(async item => await _fetch(item, defaultValue))
);
} else {
res = await _fetch(url, defaultValue);
}
spinner.success();
return res;
}
The fetch()
api is provided by node-fetch
. The warning occurs after this function has ran 10 times, causing it to return invalid data (possibly undefined?). fetchQuestData
is merely a wrapper around fetchData()
that caches results in a Map. It appears the warning is thrown here:
https://github.com/usmanyunusov/nanospinner/blob/master/index.js#L47-L57
What do you think about moving this to a method:
function bindExit() {
process.on('SIGINT', () => {
spinner.stop();
process.exit();
});
}
You could also handle more exit types like:
function bindExit() {
[
'SIGHUP',
'SIGINT',
'SIGQUIT',
'SIGTERM',
'uncaughtException'
]
.forEach(eventType => process.on(eventType, () => {
spinner.stop();
process.exit();
}));
}
Current Behaviour:
console methods (like log, warn, table) print in a line that already contains a frame of the spinner.
Expected Behaviour:
No spinner is visible in the line a console method prints to
Suggestion:
Either a pause or togglePause method (pausing hides the spinner, leaving an empty line for any logger to print to) or a log method specifically for this use case.
There should be the option to pass a text on start()
like ora does.
Otherwise I have to do this:
spinner.start();
spinner.update({
text: 'start the spinner'
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.