forked from m4tt72/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 497f561
Showing
21 changed files
with
1,782 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["svelte.svelte-vscode"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Svelte + TS + Vite | ||
|
||
This template should help get you started developing with Svelte and TypeScript in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). | ||
|
||
## Need an official Svelte framework? | ||
|
||
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. | ||
|
||
## Technical considerations | ||
|
||
**Why use this over SvelteKit?** | ||
|
||
- It brings its own routing solution which might not be preferable for some users. | ||
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. | ||
|
||
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. | ||
|
||
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate. | ||
|
||
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** | ||
|
||
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. | ||
|
||
**Why include `.vscode/extensions.json`?** | ||
|
||
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project. | ||
|
||
**Why enable `allowJs` in the TS template?** | ||
|
||
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant. | ||
|
||
**Why is HMR not preserving my local component state?** | ||
|
||
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr). | ||
|
||
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. | ||
|
||
```ts | ||
// store.ts | ||
// An extremely simple external store | ||
import { writable } from 'svelte/store' | ||
export default writable(0) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html class="dark" lang="en" style="color-scheme: dark;"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + Svelte + TS</title> | ||
</head> | ||
|
||
<body class="min-h-screen font-mono antialiased"> | ||
<div id="app" class="h-screen p-4"></div> | ||
|
||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "svelterm", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"check": "svelte-check --tsconfig ./tsconfig.json" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/vite-plugin-svelte": "^3.0.1", | ||
"@tsconfig/svelte": "^5.0.2", | ||
"autoprefixer": "^10.4.16", | ||
"postcss": "^8.4.32", | ||
"svelte": "^4.2.8", | ||
"svelte-check": "^3.6.2", | ||
"tailwindcss": "^3.4.0", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.0.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<script lang="ts"> | ||
import { afterUpdate, onDestroy, onMount } from 'svelte'; | ||
import type { Command } from './interfaces/command'; | ||
let input: HTMLInputElement; | ||
let command = ''; | ||
let history: Array<Command> = []; | ||
let isFocused = false; | ||
let hostname = window.location.hostname; | ||
let historyIndex = -1; | ||
const commands: Record<string, (args: string[]) => Promise<string> | string> = | ||
{ | ||
help: () => 'Available commands: ' + Object.keys(commands).join(', '), | ||
hostname: () => hostname, | ||
pwd: () => '/home/guest', | ||
whoami: () => 'guest', | ||
clear: () => { | ||
history = []; | ||
return ''; | ||
}, | ||
echo: (args: string[]) => args.join(' '), | ||
curl: async (args: string[]) => { | ||
if (args.length === 0) { | ||
return 'curl: no URL provided'; | ||
} | ||
const url = args[0]; | ||
try { | ||
const response = await fetch(url); | ||
const data = await response.text(); | ||
return data; | ||
} catch (error) { | ||
return `curl: could not fetch URL ${url}`; | ||
} | ||
}, | ||
}; | ||
const handleFocus = () => { | ||
isFocused = true; | ||
}; | ||
const handleBlur = () => { | ||
isFocused = false; | ||
}; | ||
onMount(() => { | ||
input.focus(); | ||
window.addEventListener('click', () => input.focus()); | ||
}); | ||
afterUpdate(() => { | ||
input.scrollIntoView({ behavior: 'smooth', block: 'end' }); | ||
}); | ||
onDestroy(() => { | ||
window.removeEventListener('click', () => input.focus()); | ||
}); | ||
const handleKeyDown = async (event: KeyboardEvent) => { | ||
if (event.key === 'Enter') { | ||
const [commandName, ...args] = command.split(' '); | ||
const commandFunction = commands[commandName]; | ||
if (commandFunction) { | ||
const output = await commandFunction(args); | ||
if (commandName !== 'clear') { | ||
history = [...history, { command, outputs: [output] }]; | ||
} | ||
} else { | ||
const output = `${commandName}: command not found`; | ||
history = [...history, { command, outputs: [output] }]; | ||
} | ||
command = ''; | ||
} else if (event.key === 'ArrowUp') { | ||
if (historyIndex < history.length - 1) { | ||
historyIndex++; | ||
command = history[history.length - 1 - historyIndex].command; | ||
} | ||
event.preventDefault(); | ||
} else if (event.key === 'ArrowDown') { | ||
if (historyIndex > -1) { | ||
historyIndex--; | ||
command = | ||
historyIndex >= 0 | ||
? history[history.length - 1 - historyIndex].command | ||
: ''; | ||
} | ||
event.preventDefault(); | ||
} else if (event.key === 'Tab') { | ||
event.preventDefault(); | ||
const autoCompleteCommand = Object.keys(commands).find((cmd) => | ||
cmd.startsWith(command), | ||
); | ||
if (autoCompleteCommand) { | ||
command = autoCompleteCommand; | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<main class="h-full border-2 rounded-md border-green-600 p-4 overflow-auto"> | ||
{#each history as { command, outputs }} | ||
<div> | ||
<div class="flex flex-row"> | ||
<h1 class="font-bold text-green-600"> | ||
<span class="text-orange-600">guest</span>@{hostname}:<span | ||
class="text-white">~$</span | ||
> | ||
</h1> | ||
|
||
<p class="text-white px-3">{command}</p> | ||
</div> | ||
|
||
{#each outputs as output} | ||
<p class="text-white">{output}</p> | ||
{/each} | ||
</div> | ||
{/each} | ||
|
||
<div class="flex flex-row"> | ||
<h1 class="font-bold text-green-600"> | ||
<span class="text-orange-600">guest</span>@{hostname}:<span | ||
class="text-white">~$</span | ||
> | ||
</h1> | ||
|
||
<div class="input-container"> | ||
<input | ||
class="w-full px-3 bg-transparent outline-none caret-green-600" | ||
type="text" | ||
bind:value={command} | ||
on:keydown={handleKeyDown} | ||
bind:this={input} | ||
on:focus={handleFocus} | ||
on:blur={handleBlur} | ||
/> | ||
|
||
{#if isFocused} | ||
<div class="block-caret" style="left: {command.length}ch"></div> | ||
{/if} | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<style> | ||
.input-container { | ||
position: relative; | ||
width: 100%; | ||
} | ||
.input-container input { | ||
caret-color: transparent; | ||
} | ||
.input-container .block-caret { | ||
position: absolute; | ||
top: 4px; /* Add this line */ | ||
width: 10px; | ||
height: 1em; | ||
background-color: currentColor; | ||
animation: blink 1s infinite; | ||
margin-left: 14px; | ||
} | ||
@keyframes blink { | ||
50% { | ||
opacity: 0; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Command { | ||
command: string; | ||
outputs: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface FileSystemNode { | ||
type: 'file' | 'directory'; | ||
contents: string | Record<string, FileSystemNode>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import './app.css'; | ||
import App from './App.svelte'; | ||
|
||
const app = new App({ | ||
target: document.getElementById('app'), | ||
}); | ||
|
||
export default app; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference types="svelte" /> | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' | ||
|
||
export default { | ||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess | ||
// for more information about preprocessors | ||
preprocess: vitePreprocess(), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: ['./index.html', './src/**/*.{svelte,js,ts,jsx,tsx}'], | ||
theme: { | ||
extend: { | ||
caretColor: ['focus-visible'], | ||
}, | ||
}, | ||
plugins: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": "@tsconfig/svelte/tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"resolveJsonModule": true, | ||
/** | ||
* Typecheck JS in `.svelte` and `.js` files by default. | ||
* Disable checkJs if you'd like to use dynamic types in JS. | ||
* Note that setting allowJs false does not prevent the use | ||
* of JS in `.svelte` files. | ||
*/ | ||
"allowJs": true, | ||
"checkJs": true, | ||
"isolatedModules": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler" | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
Oops, something went wrong.