|
1 | 1 | <script lang="ts">
|
2 |
| - import { Xterm, XtermAddon } from '$lib/index.js'; |
3 |
| - import type { ITerminalOptions, ITerminalInitOnlyOptions, Terminal } from '$lib/index.js'; |
4 |
| -
|
5 |
| - let options: ITerminalOptions & ITerminalInitOnlyOptions = {}; |
6 |
| -
|
7 |
| - async function onLoad(event: CustomEvent<{ terminal: Terminal }>) { |
8 |
| - console.log('Child component has loaded'); |
9 |
| - const terminal = event.detail.terminal; |
10 |
| -
|
11 |
| - // FitAddon Usage |
12 |
| - const { FitAddon } = await XtermAddon.FitAddon(); |
13 |
| - const fitAddon = new FitAddon(); |
14 |
| - terminal.loadAddon(fitAddon); |
15 |
| - fitAddon.fit(); |
16 |
| -
|
17 |
| - terminal.onKey(({ key }) => { |
18 |
| - terminal.write(key); |
19 |
| - }); |
20 |
| -
|
21 |
| - terminal.write('Hello World'); |
22 |
| - } |
23 |
| -
|
24 |
| - function onBell() { |
25 |
| - console.log('onBell()'); |
26 |
| - } |
27 |
| -
|
28 |
| - function onBinary(event: CustomEvent<string>) { |
29 |
| - const data = event.detail; |
30 |
| - console.log('onBinary()', data); |
31 |
| - } |
32 |
| -
|
33 |
| - function onCursorMove() { |
34 |
| - console.log('onCursorMove()'); |
35 |
| - } |
36 |
| -
|
37 |
| - function onData(event: CustomEvent<string>) { |
38 |
| - const data = event.detail; |
39 |
| - console.log('onData()', data); |
40 |
| - } |
41 |
| -
|
42 |
| - function onKey(event: CustomEvent<{ key: string; domEvent: KeyboardEvent }>) { |
43 |
| - const data = event.detail; |
44 |
| - console.log('onKey()', data); |
45 |
| - } |
46 |
| -
|
47 |
| - function onLineFeed() { |
48 |
| - console.log('onLineFeed()'); |
49 |
| - } |
50 |
| -
|
51 |
| - function onRender(event: CustomEvent<{ start: number; end: number }>) { |
52 |
| - const data = event.detail; |
53 |
| - console.log('onRender()', data); |
54 |
| - } |
55 |
| -
|
56 |
| - function onWriteParsed() { |
57 |
| - console.log('onWriteParsed()'); |
58 |
| - } |
59 |
| -
|
60 |
| - function onResize(event: CustomEvent<{ cols: number; rows: number }>) { |
61 |
| - const data = event.detail; |
62 |
| - console.log('onResize()', data); |
63 |
| - } |
64 |
| -
|
65 |
| - function onScroll(event: CustomEvent<number>) { |
66 |
| - const data = event.detail; |
67 |
| - console.log('onScroll()', data); |
68 |
| - } |
69 |
| -
|
70 |
| - function onSelectionChange() { |
71 |
| - console.log('onSelectionChange()'); |
72 |
| - } |
73 |
| -
|
74 |
| - function onTitleChange(event: CustomEvent<string>) { |
75 |
| - const data = event.detail; |
76 |
| - console.log('onTitleChange()', data); |
77 |
| - } |
| 2 | + import Terminal from './Terminal.svelte'; |
78 | 3 | </script>
|
79 | 4 |
|
80 |
| -<h1>Welcome to your library project</h1> |
81 |
| -<p>Create your package using @sveltejs/package and preview/showcase your work with SvelteKit</p> |
82 |
| -<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p> |
83 |
| - |
84 |
| -<Xterm |
85 |
| - {options} |
86 |
| - on:load={onLoad} |
87 |
| - on:bell={onBell} |
88 |
| - on:binary={onBinary} |
89 |
| - on:cursormove={onCursorMove} |
90 |
| - on:data={onData} |
91 |
| - on:key={onKey} |
92 |
| - on:linefeed={onLineFeed} |
93 |
| - on:render={onRender} |
94 |
| - on:writeparsed={onWriteParsed} |
95 |
| - on:resize={onResize} |
96 |
| - on:scroll={onScroll} |
97 |
| - on:selectionchange={onSelectionChange} |
98 |
| - on:titlechange={onTitleChange} |
99 |
| -/> |
| 5 | +<svelte:head> |
| 6 | + <title>Xterm.js with SvelteKit</title> |
| 7 | +</svelte:head> |
| 8 | + |
| 9 | +<div class="container mx-auto px-2 py-12"> |
| 10 | + <div class="text-center py-12"> |
| 11 | + <h1 |
| 12 | + class="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl dark:text-white" |
| 13 | + > |
| 14 | + Welcome to |
| 15 | + <span class="text-transparent bg-clip-text bg-gradient-to-r to-emerald-600 from-sky-400"> |
| 16 | + xterm-svelte |
| 17 | + </span> |
| 18 | + </h1> |
| 19 | + <p class="mb-6 text-lg font-normal text-gray-500 lg:text-xl dark:text-gray-400"> |
| 20 | + A SvelteKit wrapper for |
| 21 | + <a |
| 22 | + href="https://xtermjs.org/" |
| 23 | + class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Xterm.js</a |
| 24 | + > |
| 25 | + , enabling terminal embedding in SvelteKit apps, managing Xterm addons, and providing seamless |
| 26 | + updates with the latest SvelteKit and Xterm.js versions. |
| 27 | + </p> |
| 28 | + |
| 29 | + <div class="w-full max-w-[24rem] mx-auto"> |
| 30 | + <div class="relative"> |
| 31 | + <label for="npm-install-copy-button" class="sr-only">Label</label> |
| 32 | + <input |
| 33 | + id="npm-install-copy-button" |
| 34 | + type="text" |
| 35 | + class="col-span-6 bg-gray-50 border border-gray-300 text-gray-500 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500" |
| 36 | + value="npm install @battlefieldduck/xterm-svelte" |
| 37 | + disabled |
| 38 | + readonly |
| 39 | + /> |
| 40 | + <button |
| 41 | + data-copy-to-clipboard-target="npm-install-copy-button" |
| 42 | + data-tooltip-target="tooltip-copy-npm-install-copy-button" |
| 43 | + class="absolute end-2 top-1/2 -translate-y-1/2 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg p-2 inline-flex items-center justify-center" |
| 44 | + > |
| 45 | + <span id="default-icon"> |
| 46 | + <svg |
| 47 | + class="w-3.5 h-3.5" |
| 48 | + aria-hidden="true" |
| 49 | + xmlns="http://www.w3.org/2000/svg" |
| 50 | + fill="currentColor" |
| 51 | + viewBox="0 0 18 20" |
| 52 | + > |
| 53 | + <path |
| 54 | + d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z" |
| 55 | + /> |
| 56 | + </svg> |
| 57 | + </span> |
| 58 | + <span id="success-icon" class="hidden inline-flex items-center"> |
| 59 | + <svg |
| 60 | + class="w-3.5 h-3.5 text-blue-700 dark:text-blue-500" |
| 61 | + aria-hidden="true" |
| 62 | + xmlns="http://www.w3.org/2000/svg" |
| 63 | + fill="none" |
| 64 | + viewBox="0 0 16 12" |
| 65 | + > |
| 66 | + <path |
| 67 | + stroke="currentColor" |
| 68 | + stroke-linecap="round" |
| 69 | + stroke-linejoin="round" |
| 70 | + stroke-width="2" |
| 71 | + d="M1 5.917 5.724 10.5 15 1.5" |
| 72 | + /> |
| 73 | + </svg> |
| 74 | + </span> |
| 75 | + </button> |
| 76 | + <div |
| 77 | + id="tooltip-copy-npm-install-copy-button" |
| 78 | + role="tooltip" |
| 79 | + class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700" |
| 80 | + > |
| 81 | + <span id="default-tooltip-message">Copy to clipboard</span> |
| 82 | + <span id="success-tooltip-message" class="hidden">Copied!</span> |
| 83 | + <div class="tooltip-arrow" data-popper-arrow></div> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div |
| 90 | + class="flex items-center p-4 mb-4 text-sm text-blue-800 rounded-lg bg-blue-50 dark:bg-gray-800 dark:text-blue-400" |
| 91 | + role="alert" |
| 92 | + > |
| 93 | + <svg |
| 94 | + class="flex-shrink-0 inline w-4 h-4 me-3" |
| 95 | + aria-hidden="true" |
| 96 | + xmlns="http://www.w3.org/2000/svg" |
| 97 | + fill="currentColor" |
| 98 | + viewBox="0 0 20 20" |
| 99 | + > |
| 100 | + <path |
| 101 | + d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z" |
| 102 | + /> |
| 103 | + </svg> |
| 104 | + <span class="sr-only">Info</span> |
| 105 | + <div> |
| 106 | + Below is a simulated demo of the Windows Command Prompt, powered by xterm.js and integrated |
| 107 | + with xterm-svelte. Feel free to interact with the terminal - try pressing ‘Enter’ to see it in |
| 108 | + action! |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + |
| 112 | + <Terminal /> |
| 113 | +</div> |
0 commit comments