Skip to content

Commit ccf3449

Browse files
committed
Styling, add length limit to command input
1 parent 4a9d86a commit ccf3449

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

web/frontend/src/components/Console.svelte

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
3535
$: inactive = $sessionState === "closed" || $sessionState === "readonly";
3636
37+
const MAX_COMMAND_LENGTH = 128;
38+
const COUNTER_THRESHOLD = Math.floor(MAX_COMMAND_LENGTH * 0.8);
39+
let commandValue = "";
40+
$: remaining = MAX_COMMAND_LENGTH - commandValue.length;
41+
$: showCounter = commandValue.length >= COUNTER_THRESHOLD;
42+
$: counterColor =
43+
remaining <= 10 ? "text-red-400" :
44+
remaining <= 20 ? "text-yellow-400" :
45+
"text-gray-500";
46+
3747
let cleanClose = false;
3848
let virtualConsole: VirtualConsole;
3949
let reconnection: ReconnectionController;
@@ -156,25 +166,25 @@
156166
}
157167
158168
function handleKeydown(e: KeyboardEvent) {
159-
if (e.key === "Enter" && commandInput.value.trim() !== "") {
160-
const commandText = commandInput.value.trim();
169+
if (e.key === "Enter" && commandValue.trim() !== "") {
170+
const commandText = commandValue.trim();
161171
sendCommand(commandText);
162172
commandHistory.unshift(commandText);
163173
if (commandHistory.length > 50) commandHistory.pop();
164174
localStorage.setItem(HISTORY_KEY, JSON.stringify(commandHistory));
165175
historyIndex = -1;
166-
commandInput.value = "";
176+
commandValue = "";
167177
e.preventDefault();
168178
} else if (e.key === "ArrowUp") {
169179
if (historyIndex < commandHistory.length - 1) {
170180
historyIndex++;
171-
commandInput.value = commandHistory[historyIndex];
181+
commandValue = commandHistory[historyIndex];
172182
}
173183
e.preventDefault();
174184
} else if (e.key === "ArrowDown") {
175185
if (historyIndex >= 0) {
176186
historyIndex--;
177-
commandInput.value = historyIndex >= 0 ? commandHistory[historyIndex] : "";
187+
commandValue = historyIndex >= 0 ? commandHistory[historyIndex] : "";
178188
}
179189
e.preventDefault();
180190
}
@@ -189,7 +199,10 @@
189199
<div class="flex items-center border-t border-gray-700 pt-3">
190200
<span class="{inactive ? 'text-gray-600' : 'text-green-400'} mr-2 shrink-0">&gt;</span>
191201
<!-- svelte-ignore a11y-autofocus -->
192-
<input type="text" bind:this={commandInput} on:keydown={handleKeydown} class="w-full bg-transparent border-none focus:ring-0 focus:outline-none {inactive ? 'text-gray-600 placeholder-gray-600 cursor-not-allowed' : 'text-gray-200 placeholder-gray-500'}" placeholder="{inactive ? 'Session ended' : 'Enter command...'}" autocomplete="off" autofocus disabled>
202+
<input type="text" bind:this={commandInput} bind:value={commandValue} maxlength={MAX_COMMAND_LENGTH} on:keydown={handleKeydown} class="w-full bg-transparent border-none focus:ring-0 focus:outline-none {inactive ? 'text-gray-600 placeholder-gray-600 cursor-not-allowed' : 'text-gray-200 placeholder-gray-500'}" placeholder="{inactive ? 'Session ended' : 'Enter command...'}" autocomplete="off" autofocus disabled>
203+
{#if showCounter}
204+
<span class="ml-2 text-xs font-mono tabular-nums shrink-0 {counterColor}">{remaining}</span>
205+
{/if}
193206
</div>
194207
</div>
195208
</div>

0 commit comments

Comments
 (0)