From 4c2f096a18cd50507ce4a1338aaf62d9185d34b7 Mon Sep 17 00:00:00 2001 From: Daniel Svitan Date: Mon, 30 Jun 2025 16:02:44 +0200 Subject: [PATCH] :hammer: Refactors terminal rendering algorithm --- src/components/Terminal.vue | 84 ++++++++++++------------------------- 1 file changed, 27 insertions(+), 57 deletions(-) diff --git a/src/components/Terminal.vue b/src/components/Terminal.vue index da6026a..5490100 100644 --- a/src/components/Terminal.vue +++ b/src/components/Terminal.vue @@ -28,76 +28,46 @@ import {onMounted, ref} from "vue"; const text = ref("") -interface Part { - pre?: string; - content: string; - post?: string; -} - -const prompt: Part[] = [ - { - pre: ``, - content: `╭─`, - post: `` - }, - { - pre: ``, - content: `guest@svitan.dev`, - post: `` - }, - { - content: ` ` - }, - { - pre: ``, - content: `~`, - post: `
` - }, - { - pre: ``, - content: `╰─$ `, - post: `` - } -] - -const target: Part[] = [ - ...prompt, - { - content: "./portfolio", - post: `
` - }, - { - content: ` +const prompt = `╭─guest@svitan.dev ~ +╰─$` +const target = `${prompt} ./portfolio ____ _ _ ____ _ _ \\\\// | _ \\ __ _ _ __ (_) ___| | / ___|_ _(_) |_ __ _ _\\/_ | | | |/ _\` | '_ \\| |/ _ \\ | \\___ \\ \\ / / | __/ _\` | '_ \\ | |_| | (_| | | | | | __/ | ___) \\ V /| | || (_| | | | | |____/ \\__,_|_| |_|_|\\___|_| |____/ \\_/ |_|\\__\\__,_|_| |_| +

Hi, I'm Daniel Svitaň, {a} {years} year-old aspiring engineer

+

Residence: Bratislava, Slovakia

Contacts: + selfsigned-ash@proton.me + +421 948 309 804 + @selfsigned-ash:svitan.dev (Matrix) +

Socials: + GitHub + Gitea + Signal + Mastodon +

` - } -] onMounted(() => { let i = 0; - let j = 0; const id = setInterval(() => { - if (i === target[j].content.length) { - text.value += target[j].post ?? ""; - i = 0; - j++; - text.value += target[j].pre ?? ""; - } - if (i === 0 && j === 0) { - text.value += target[j].pre ?? ""; + if (i === target.length) { + clearInterval(id); + return; } - text.value += target[j].content[i] - .replaceAll("\n", "
") - .replaceAll(" ", " "); - if (j === target.length - 1 && i === target[j].content.length - 1) { - text.value += target[j].post ?? ""; - clearTimeout(id); + let next = ""; + if (target[i] === "<") { + do { + next += target[i++] + } while(target[i] !== ">"); } + next += target[i] + .replace("\n", "
") + .replace(" ", " "); + + text.value += next; i++; }, 5) })