Skip to content
Merged

V2 #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/LoadingScreen/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
}

const BOOT_LINES = [
{ ts: '0.0001', msg: 'Initializing RahulOS...' },
{ ts: '0.0001', msg: 'Initializing Rahul AP...' },
{ ts: '0.0042', msg: 'Loading kernel...' },
{ ts: '0.0125', msg: 'Loading React...' },
{ ts: '0.0210', msg: 'Loading portfolio...' },
Expand Down Expand Up @@ -74,7 +74,7 @@ const LoadingScreen: React.FC<Props> = ({ onComplete }) => {
>
<div className="ls-content">
<div className="ls-brand">
RAHUL_OS_V2.0
RAHUL_AP_V2.0
<span className="ls-cursor">▋</span>
</div>

Expand Down
44 changes: 38 additions & 6 deletions src/components/Terminal/Terminal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
color: var(--fg);
font-family: var(--font-mono);
cursor: text;
overflow: hidden;
overflow-y: auto;
overflow-x: hidden;
}

.terminal-scroll {
height: 100%;
overflow-y: auto;
min-height: 100%;
padding: clamp(16px, 4vw, 40px);
max-width: 900px;
margin: 0 auto;
Expand All @@ -23,10 +23,15 @@

.terminal-welcome {
margin-bottom: 16px;
color: var(--primary);

p:first-child {
font-weight: 700;
> * + * {
margin-top: 8px;
}

.welcome-login {
p + p {
margin-top: 0;
}
}
}

Expand Down Expand Up @@ -92,6 +97,20 @@
margin-top: 4px;
}

.out-help-section {
margin-bottom: 14px;
}

.out-section-title {
color: var(--accent);
text-transform: uppercase;
letter-spacing: 2px;
font-size: 0.72rem;
padding-bottom: 4px;
margin-bottom: 6px;
border-bottom: 1px dashed var(--border-color);
}

.out-help .out-row {
display: flex;
gap: 16px;
Expand Down Expand Up @@ -121,6 +140,19 @@
padding-left: 8px;
}

.out-neofetch {
display: flex;
gap: 24px;
flex-wrap: wrap;

.out-ascii {
color: var(--terminal-green);
font-family: inherit;
line-height: 1.3;
white-space: pre;
}
}

.terminal-suggestions {
display: flex;
flex-wrap: wrap;
Expand Down
55 changes: 43 additions & 12 deletions src/components/Terminal/Terminal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTheme, Theme } from '../../context/ThemeContext';
import { runCommand, COMMAND_NAMES, CommandOutput } from './commands';
import { runCommand, COMMAND_NAMES, OPEN_TARGETS, CommandOutput } from './commands';
import './Terminal.scss';

interface LineEntry {
Expand All @@ -10,10 +10,35 @@ interface LineEntry {
}

const THEME_ORDER: Theme[] = ['dark', 'neon', 'pastel', 'light'];
const WELCOME = 'Type "help" to begin.';
const PROMPT = 'guest@rahulap:~$';

let idCounter = 0;

type CompletionContext = { kind: 'command' | 'open-arg'; prefix: string; options: string[] };

const getCompletionContext = (value: string): CompletionContext | null => {
const trailingSpace = /\s$/.test(value);
const parts = value.split(/\s+/).filter(Boolean);
if (parts.length === 0) return null;

const first = parts[0].toLowerCase();
if (first === 'open' && (parts.length > 1 || trailingSpace)) {
return { kind: 'open-arg', prefix: parts.length > 1 ? parts[1].toLowerCase() : '', options: OPEN_TARGETS };
}
if (parts.length > 1) return null;
return { kind: 'command', prefix: first, options: COMMAND_NAMES };
};

const formatLastLogin = () => {
const parts = new Intl.DateTimeFormat('en-US', {
month: 'short', day: '2-digit', year: 'numeric',
hour: '2-digit', minute: '2-digit', hour12: false,
timeZone: 'Asia/Kolkata',
}).formatToParts(new Date());
const get = (type: string) => parts.find(p => p.type === type)?.value;
return `${get('month')} ${get('day')} ${get('year')} ${get('hour')}:${get('minute')} IST`;
};

const Terminal: React.FC = () => {
const { theme, setTheme } = useTheme();
const [lines, setLines] = useState<LineEntry[]>([]);
Expand All @@ -22,6 +47,7 @@ const Terminal: React.FC = () => {
const [historyIndex, setHistoryIndex] = useState<number | null>(null);
const [matrixActive, setMatrixActive] = useState(false);

const [lastLogin] = useState(formatLastLogin);
const inputRef = useRef<HTMLInputElement>(null);
const bottomRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -97,17 +123,18 @@ const Terminal: React.FC = () => {

if (e.key === 'Tab') {
e.preventDefault();
const [prefix] = input.split(/\s+/);
if (!prefix) return;
const matches = COMMAND_NAMES.filter(c => c.startsWith(prefix.toLowerCase()));
const ctx = getCompletionContext(input);
if (!ctx) return;
const matches = ctx.options.filter(o => o.startsWith(ctx.prefix));
if (matches.length === 1) {
setInput(matches[0] + ' ');
setInput(ctx.kind === 'open-arg' ? `open ${matches[0]} ` : `${matches[0]} `);
}
}
};

const suggestions = input.trim()
? COMMAND_NAMES.filter(c => c.startsWith(input.trim().toLowerCase()) && c !== input.trim().toLowerCase())
const completionCtx = getCompletionContext(input);
const suggestions = completionCtx
? completionCtx.options.filter(o => o.startsWith(completionCtx.prefix) && o !== completionCtx.prefix)
: [];

return (
Expand All @@ -116,22 +143,26 @@ const Terminal: React.FC = () => {

<div className="terminal-scroll">
<div className="terminal-welcome">
<p>RahulOS v2.0 — interactive portfolio</p>
<p className="out-muted">{WELCOME}</p>
<p className="out-title">Rahul AP v2.1</p>
<div className="welcome-login">
<p className="out-muted">Last login:</p>
<p className="out-muted">{lastLogin}</p>
</div>
<p className="out-muted">Type &quot;help&quot; to begin.</p>
</div>

{lines.map(line => (
<div className="terminal-block" key={line.id}>
<div className="terminal-line">
<span className="terminal-prompt">visitor@rahul:~$</span>
<span className="terminal-prompt">{PROMPT}</span>
<span className="terminal-command">{line.command}</span>
</div>
{line.output && <div className="terminal-output">{line.output}</div>}
</div>
))}

<div className="terminal-line terminal-line--active">
<span className="terminal-prompt">visitor@rahul:~$</span>
<span className="terminal-prompt">{PROMPT}</span>
<input
ref={inputRef}
className="terminal-input"
Expand Down
Loading
Loading