diff --git a/src/components/terminal/TerminalEmulator.tsx b/src/components/terminal/TerminalEmulator.tsx
index 0378a93..4e881f6 100644
--- a/src/components/terminal/TerminalEmulator.tsx
+++ b/src/components/terminal/TerminalEmulator.tsx
@@ -1,3 +1,5 @@
+'use client';
+
import { useStore } from '@nanostores/react';
import { useTranslations } from 'next-intl';
import { useEffect, useRef, useState } from 'react';
@@ -5,11 +7,18 @@ import {
$terminalHistory,
$terminalHistoryVisibleIdx,
$terminalPromptRef,
+ initializeTerminal,
} from '@/stores/terminal-store';
import UnknownCmdOutput from '../cmd-outputs/UnknownCmdOutput';
import TerminalPrompt, { type TerminalPromptRef } from './TerminalPrompt';
-export default function TerminalEmulator() {
+interface TerminalEmulatorProps {
+ initialCommand?: string;
+}
+
+export default function TerminalEmulator({
+ initialCommand = 'welcome',
+}: TerminalEmulatorProps) {
const history = useStore($terminalHistory);
const historyVisibleIdx = useStore($terminalHistoryVisibleIdx);
@@ -33,6 +42,12 @@ export default function TerminalEmulator() {
}
}, [hasWindow]);
+ useEffect(() => {
+ if (hasWindow) {
+ initializeTerminal(initialCommand);
+ }
+ }, [hasWindow, initialCommand]);
+
return (
hasWindow && (
diff --git a/src/constants/routes.ts b/src/constants/routes.ts
index c5b52ff..ae41cf6 100644
--- a/src/constants/routes.ts
+++ b/src/constants/routes.ts
@@ -1,5 +1,6 @@
export const Routes = {
- terminal: '/',
+ welcome: '/',
whoami: '/whoami',
+ services: '/services',
contact: '/contact',
};
diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json
index 822b374..6d219fd 100644
--- a/src/i18n/messages/en.json
+++ b/src/i18n/messages/en.json
@@ -13,8 +13,9 @@
"ctrlc": "CTRL+C"
},
"Pages": {
- "terminal": "home",
+ "welcome": "welcome",
"whoami": "whoami",
+ "services": "services",
"contact": "contact"
},
"Status": {
@@ -66,7 +67,7 @@
},
"services": {
"description": "Display my self-hosted services status",
- "title": "Services that I proudly self-host:",
+ "title": "Services that I proudly self-host",
"connectionStatus": "Connection Status",
"loading": "(Loading...)",
"waitingForHeartbeats": "Waiting for heartbeats...",
diff --git a/src/i18n/messages/fr.json b/src/i18n/messages/fr.json
index c05e888..bb5a756 100644
--- a/src/i18n/messages/fr.json
+++ b/src/i18n/messages/fr.json
@@ -13,8 +13,9 @@
"ctrlc": "CTRL+C"
},
"Pages": {
- "terminal": "accueil",
- "whoami": "qui_suis_je",
+ "welcome": "bienvenue",
+ "whoami": "qui suis-je",
+ "services": "services",
"contact": "contact"
},
"Status": {
@@ -66,7 +67,7 @@
},
"services": {
"description": "Afficher l'état de mes services auto-hébergés",
- "title": "Services que j'héberge avec fierté :",
+ "title": "Services que j'héberge avec fierté",
"connectionStatus": "État de la connexion",
"loading": "(Chargement...)",
"waitingForHeartbeats": "En attente de heartbeats...",
diff --git a/src/stores/terminal-store.ts b/src/stores/terminal-store.ts
index ed28328..8a7249c 100644
--- a/src/stores/terminal-store.ts
+++ b/src/stores/terminal-store.ts
@@ -1,9 +1,9 @@
-import { atom, effect, onMount } from 'nanostores';
+import { atom, effect } from 'nanostores';
import type { KeyboardEvent, RefObject } from 'react';
import type { TerminalPromptRef } from '@/components/terminal/TerminalPrompt';
import { Commands } from '@/constants/commands';
import { Key } from '@/types/keyboard';
-import { Command, type CommandEntry } from '@/types/terminal';
+import type { CommandEntry } from '@/types/terminal';
import { getPastInputStr, parseTerminalEntry } from '@/utils/terminal-utils';
export const $terminalInput = atom('');
@@ -17,15 +17,6 @@ export const $terminalPromptRef =
atom | null>(null);
export const $scrollY = atom(0);
-const $hasGreeted = atom(false);
-
-onMount($terminalInput, () => {
- if (!$hasGreeted.get()) {
- $hasGreeted.set(true);
- simulateInput(Command.Welcome);
- }
-});
-
effect($terminalKeyEvent, (event) => {
const isReadOnly = $terminalInputReadOnly.get();
if (!event || isReadOnly) return;
@@ -100,6 +91,13 @@ export function simulateInput(input: string) {
addChar(input);
}
+export function initializeTerminal(command: string) {
+ $terminalHistory.set([]);
+ $terminalHistoryIdx.set(-1);
+ $terminalHistoryVisibleIdx.set(0);
+ simulateInput(command);
+}
+
export function setPreviousHistoryEntry() {
const history = $terminalHistory.get();
const historyIdx = $terminalHistoryIdx.get();