made some slight improvements to the terminal emulator
This commit is contained in:
1 parent
a57a27e4a3
commit
79ab1285c5
5 files changed
+170
-78
No files matched your search
@@ -1,6 +1,6 @@
|
||||
.terminal-container {
|
||||
padding: 0 22px;
|
||||
height: 526px;
|
||||
height: 498px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scroll-behavior: smooth;
|
||||
@@ -23,23 +23,19 @@ h2 {
|
||||
.input-shell {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.input-mirror {
|
||||
display: inline-block;
|
||||
white-space: none;
|
||||
font: inherit;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.input-placeholder {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.terminal-field {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
@@ -51,21 +47,39 @@ h2 {
|
||||
letter-spacing: inherit;
|
||||
}
|
||||
|
||||
.cursorblink {
|
||||
margin-left: -12px;
|
||||
animation: cursorBlink 1.25s infinite;
|
||||
.input-mirror,
|
||||
.terminal-field {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.cursor-block {
|
||||
display: inline-block;
|
||||
width: 1ch;
|
||||
height: 1.2em;
|
||||
background: white;
|
||||
color: #1b1920;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
.cursor-block.blink {
|
||||
animation: cursorBlink 1.05s steps(1) infinite;
|
||||
}
|
||||
|
||||
@keyframes cursorBlink {
|
||||
0%, 50% {
|
||||
background: white;
|
||||
color: #1b1920;
|
||||
}
|
||||
50.01%, 100% {
|
||||
background: transparent;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.terminal-error {
|
||||
color: #ff7a7a;
|
||||
}
|
||||
|
||||
@keyframes cursorBlink {
|
||||
0% { opacity: 1; }
|
||||
50% { opacity: 0; }
|
||||
100% { opacity: 1; }
|
||||
}
|
||||
|
||||
.category {
|
||||
max-width: 200px;
|
||||
}
|
||||
@@ -106,7 +120,8 @@ a.green {
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 30%;
|
||||
width: 30%;
|
||||
height: auto;
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
@@ -125,6 +140,7 @@ img {
|
||||
}
|
||||
|
||||
.tech-stack li {
|
||||
font-size: 1rem;
|
||||
color: #649aff;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
@@ -43,23 +43,30 @@
|
||||
<span class="prompt">$ </span>
|
||||
|
||||
<span class="input-shell">
|
||||
<span class="input-mirror">
|
||||
{{ command }}
|
||||
@if (!command) {
|
||||
<span class="input-placeholder"> </span>
|
||||
}
|
||||
<span class="cursorblink">█</span>
|
||||
</span>
|
||||
<input
|
||||
#terminalInput
|
||||
type="text"
|
||||
[(ngModel)]="command"
|
||||
(keydown.enter)="runCommand()"
|
||||
class="terminal-field"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
/>
|
||||
<span class="input-mirror" aria-hidden="true">
|
||||
<span>{{ beforeCursor }}</span>
|
||||
|
||||
<span class="cursor-block" [class.blink]="isFocused && shouldBlink">
|
||||
{{ cursorChar || '\u00A0' }}
|
||||
</span>
|
||||
|
||||
<span>{{ afterCursor }}</span>
|
||||
</span>
|
||||
|
||||
<input
|
||||
#terminalInput
|
||||
type="text"
|
||||
[(ngModel)]="command"
|
||||
(input)="handleCursorActivity()"
|
||||
(click)="handleCursorActivity()"
|
||||
(keyup)="handleCursorActivity()"
|
||||
(keydown)="onKeydown($event)"
|
||||
(keydown.enter)="onEnter($event)"
|
||||
(focus)="onFocus()"
|
||||
(blur)="onBlur()"
|
||||
class="terminal-field"
|
||||
/>
|
||||
</span>
|
||||
</h2>
|
||||
</code>
|
||||
}
|
||||
@@ -69,7 +76,13 @@
|
||||
</ng-template>
|
||||
|
||||
<ng-template #catTemplate>
|
||||
<img alt="cat" class="fade-in" src="https://files.itz.sh/itzmineydev/lilguy.jpg">
|
||||
<img
|
||||
alt="cat"
|
||||
class="fade-in"
|
||||
src="https://files.itz.sh/itzmineydev/lilguy.jpg"
|
||||
(load)="scrollToBottom()"
|
||||
/>
|
||||
<p>lil goober</p>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #toolsTemplate>
|
||||
|
||||
@@ -42,6 +42,11 @@ export class TerminalEmulatorComponent implements OnInit, OnChanges {
|
||||
booting = true;
|
||||
private hasBooted = false;
|
||||
|
||||
caretIndex = 0;
|
||||
isFocused = false;
|
||||
shouldBlink = true;
|
||||
private blinkResumeTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
private rootEntries: TerminalEntry[] = [
|
||||
{ name: 'about.txt', type: 'file' },
|
||||
{ name: 'tools', type: 'dir' },
|
||||
@@ -108,6 +113,11 @@ export class TerminalEmulatorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
onEnter(event: Event): void {
|
||||
event.preventDefault();
|
||||
this.runCommand();
|
||||
}
|
||||
|
||||
runCommand() {
|
||||
const cmd = this.command.trim();
|
||||
if (!cmd || this.booting) return;
|
||||
@@ -185,6 +195,7 @@ export class TerminalEmulatorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
this.command = '';
|
||||
this.caretIndex = 0;
|
||||
this.scrollToBottom();
|
||||
}
|
||||
|
||||
@@ -261,13 +272,78 @@ export class TerminalEmulatorComponent implements OnInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
get beforeCursor(): string {
|
||||
return this.command.slice(0, this.caretIndex);
|
||||
}
|
||||
|
||||
get cursorChar(): string {
|
||||
const ch = this.command[this.caretIndex];
|
||||
|
||||
if (ch === ' ') return '\u00A0';
|
||||
return ch ?? '\u00A0';
|
||||
}
|
||||
|
||||
get afterCursor(): string {
|
||||
return this.command.slice(this.caretIndex + (this.caretIndex < this.command.length ? 1 : 0));
|
||||
}
|
||||
|
||||
handleCursorActivity(): void {
|
||||
this.syncCursor();
|
||||
this.restartBlink();
|
||||
}
|
||||
|
||||
focusInput() {
|
||||
if (!this.booting && this.terminalInput) {
|
||||
this.terminalInput.nativeElement.focus();
|
||||
this.syncCursor();
|
||||
}
|
||||
}
|
||||
|
||||
private scrollToBottom() {
|
||||
onFocus(): void {
|
||||
this.isFocused = true;
|
||||
this.restartBlink();
|
||||
this.syncCursor();
|
||||
}
|
||||
|
||||
onBlur(): void {
|
||||
this.isFocused = false;
|
||||
this.shouldBlink = false;
|
||||
|
||||
if (this.blinkResumeTimer) {
|
||||
clearTimeout(this.blinkResumeTimer);
|
||||
this.blinkResumeTimer = null;
|
||||
}
|
||||
|
||||
this.syncCursor();
|
||||
}
|
||||
|
||||
onKeydown(_: KeyboardEvent): void {
|
||||
queueMicrotask(() => {
|
||||
this.syncCursor();
|
||||
this.restartBlink();
|
||||
});
|
||||
}
|
||||
|
||||
syncCursor(): void {
|
||||
const input = this.terminalInput?.nativeElement;
|
||||
if (!input) return;
|
||||
|
||||
this.caretIndex = input.selectionStart ?? this.command.length;
|
||||
}
|
||||
|
||||
private restartBlink(): void {
|
||||
this.shouldBlink = false;
|
||||
|
||||
if (this.blinkResumeTimer) {
|
||||
clearTimeout(this.blinkResumeTimer);
|
||||
}
|
||||
|
||||
this.blinkResumeTimer = setTimeout(() => {
|
||||
this.shouldBlink = true;
|
||||
}, 10);
|
||||
}
|
||||
|
||||
protected scrollToBottom() {
|
||||
setTimeout(() => {
|
||||
if (!this.terminalOutput) return;
|
||||
const el = this.terminalContainer.nativeElement;
|
||||
|
||||
Reference in new issue
Block a user