Skip to content

Commit 093daa8

Browse files
committed
feat(ASCII Art Drawer): add coding languages support
Add support for outputing in many coding languages (Python , bash....) FIx other part of CorentinTh#934
1 parent 2850dbd commit 093daa8

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ declare module '@vue/runtime-core' {
159159
RouterLink: typeof import('vue-router')['RouterLink']
160160
RouterView: typeof import('vue-router')['RouterView']
161161
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
162+
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
162163
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
163164
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
164165
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']

src/tools/ascii-text-drawer/ascii-text-drawer.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script setup lang="ts">
22
import figlet from 'figlet';
33
import TextareaCopyable from '@/components/TextareaCopyable.vue';
4+
import { languages, translateToLanguage } from '@/utils/ascii-lang-utils';
45
56
const input = ref('Ascii ART');
7+
const language = useStorage('ascii-text-drawer:language', 'raw');
68
const font = useStorage('ascii-text-drawer:font', 'Standard');
79
const width = useStorage('ascii-text-drawer:width', 80);
810
const output = ref('');
@@ -11,16 +13,24 @@ const processing = ref(false);
1113
1214
figlet.defaults({ fontPath: '//unpkg.com/[email protected]/fonts/' });
1315
16+
const languagesOptions = languages.map(lang => ({ value: lang.id, label: lang.name }));
17+
18+
figlet.defaults({ fontPath: '//unpkg.com/[email protected]/fonts/' });
19+
1420
watchEffect(async () => {
21+
const inputValue = input.value;
22+
const languageValue = language.value;
23+
const fontValue = font.value;
24+
const widthValue = width.value;
1525
processing.value = true;
1626
try {
1727
const options: figlet.Options = {
18-
font: font.value as figlet.Fonts,
19-
width: width.value,
28+
font: fontValue as figlet.Fonts,
29+
width: widthValue,
2030
whitespaceBreak: true,
2131
};
22-
output.value = await (new Promise<string>((resolve, reject) =>
23-
figlet.text(input.value, options,
32+
const rawOutput = await (new Promise<string>((resolve, reject) =>
33+
figlet.text(inputValue, options,
2434
(err, text) => {
2535
if (err) {
2636
reject(err);
@@ -29,6 +39,8 @@ watchEffect(async () => {
2939
3040
resolve(text ?? '');
3141
})));
42+
43+
output.value = translateToLanguage(rawOutput, languageValue);
3244
errored.value = false;
3345
}
3446
catch (e: any) {
@@ -50,6 +62,7 @@ const fonts = ['1Row', '3-D', '3D Diagonal', '3D-ASCII', '3x5', '4Max', '5 Line
5062
multiline
5163
rows="4"
5264
/>
65+
<c-select v-model:value="language" :options="languagesOptions" searchable mt-3 />
5366

5467
<n-divider />
5568

src/utils/ascii-lang-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function escapeXml(unsafe: string) {
77
case '\'': return '&apos;';
88
case '"': return '&quot;';
99
}
10+
return '';
1011
});
1112
}
1213

0 commit comments

Comments
 (0)