blog/frontend/src/lib/home/framework/ui/TerminalLastLine.svelte
SquidSpirit 8b1d643531
All checks were successful
Frontend CI / build (push) Successful in 1m21s
PR Title Check / pr-title-check (pull_request) Successful in 17s
chore: pnpm format
2025-10-12 18:26:56 +08:00

71 lines
1.9 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script lang="ts">
import TerminalCursor from '$lib/home/framework/ui/TerminalCursor.svelte';
import { onDestroy, onMount } from 'svelte';
let { text, onComplete: onCompleted }: { text: string; onComplete: () => void } = $props();
let timeText: string = $state('');
let showingText: string = $state('');
let textUpdateInterval: ReturnType<typeof setInterval> | null = null;
let timeUpdateInterval: ReturnType<typeof setInterval> | null = null;
onMount(() => {
setTimeout(() => {
textUpdateInterval = setInterval(() => {
if (showingText.length < text.length) {
showingText += text[showingText.length];
} else {
clearInterval(textUpdateInterval!);
setTimeout(onCompleted, 300);
}
}, 50);
}, 300);
timeText = dateToLocaleString(new Date());
timeUpdateInterval = setInterval(() => {
timeText = dateToLocaleString(new Date());
}, 1000);
});
onDestroy(() => {
if (textUpdateInterval != null) {
clearInterval(textUpdateInterval);
textUpdateInterval = null;
}
if (timeUpdateInterval != null) {
clearInterval(timeUpdateInterval);
timeUpdateInterval = null;
}
});
function dateToLocaleString(date: Date): string {
return date.toLocaleString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
}
</script>
<div class="flex w-full flex-col pt-1.5 leading-5 md:pt-2.5 md:leading-7">
<div class="flex w-full flex-row flex-nowrap items-center gap-x-1.5 text-nowrap md:gap-x-2">
<span>
<span>╭─  squid </span>
<span class="text-blue-500">
~<span class="max-md:hidden">/Documents/blog</span>
</span>
</span>
<div class="h-0.5 w-full bg-gray-50"></div>
<span>{timeText}</span>
</div>
<div class="flex w-full flex-row gap-x-1.5 md:gap-x-2">
<span>
╰─<span class="text-green-400"></span>
</span>
<span>{showingText}</span>
<TerminalCursor />
</div>
</div>