diff options
| -rwxr-xr-x | run.sh | 2 | ||||
| -rw-r--r-- | src/countries.ts | 18 | ||||
| -rw-r--r-- | src/util/logger.ts | 12 |
3 files changed, 26 insertions, 6 deletions
@@ -1,4 +1,4 @@ #!/bin/sh # Just a short-hand to run instead of typing it out in terminal during development -deno run --allow-all --unstable "$@" ./index.ts
\ No newline at end of file +deno run --allow-all --unstable ./index.ts "$@"
\ No newline at end of file diff --git a/src/countries.ts b/src/countries.ts index 2485c49..e2230dc 100644 --- a/src/countries.ts +++ b/src/countries.ts @@ -43,10 +43,9 @@ export class Countries { this.cache.saveTxt("last-synced", JSON.stringify(Date.now())); if (config?.flagAscii) { - this.logger.alert( - "Generating ASCII art for each country flag. This may take a minute..." - ); - const flagStrings = await this.generateFlagImgs(countries); + const logTitle = + "Generating ASCII art for each country flag. This may take a minute..."; + const flagStrings = await this.generateFlagImgs(countries, logTitle); this.flags = flagStrings; this.cache.saveJson("flags", flagStrings); } @@ -173,8 +172,12 @@ export class Countries { return result.join(" | "); } - private async generateFlagImgs(countries: Country[]): Promise<FlagAscii[]> { + private async generateFlagImgs( + countries: Country[], + logTitle?: string + ): Promise<FlagAscii[]> { const data = []; + let index = 0; for (const country of countries) { // Replace png with jpg as the library used has trouble with png const flagUrl = country.flags["png"].replace(".png", ".jpg"); @@ -183,6 +186,11 @@ export class Countries { countryName: country.name.common, flagString, }); + index++; + this.logger.progress(index, countries.length, { + title: logTitle, + description: "Generating a flag for " + country.name.common, + }); } return data; } diff --git a/src/util/logger.ts b/src/util/logger.ts index 4df9fb7..49dcd86 100644 --- a/src/util/logger.ts +++ b/src/util/logger.ts @@ -18,6 +18,18 @@ export class Logger { console.error(nano.red(data)); } + public progress( + current: number, + total: number, + config?: { title: string; description: string } + ) { + console.clear(); + if (config?.title) { + this.alert(config.title); + } + console.log(`${current}/${total} ${config?.description || ""}`); + } + public logCountry(country: FetchedCountry) { console.log( nano.cyan("Country:"), |
