Commit 5c9cb68 1 parent 2abd785 commit 5c9cb68 Copy full SHA for 5c9cb68
File tree 2 files changed +62
-0
lines changed
docs/src/components/Terminal
2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import figlet from './figlet';
30
30
import { jargon , jargon_init } from './jargon' ;
31
31
import cal from './cal' ;
32
32
import chuck_norris from './chuck-norris' ;
33
+ import star_wars from './star-wars' ;
33
34
34
35
const languages = [
35
36
'markdown' ,
@@ -69,6 +70,7 @@ const commands = {
69
70
jargon,
70
71
cal,
71
72
'chuck-norris' : chuck_norris ,
73
+ 'star-wars' : star_wars ,
72
74
help,
73
75
theme,
74
76
record,
@@ -225,6 +227,9 @@ export default function Interpreter(): JSX.Element {
225
227
< li >
226
228
< button onClick = { exec ( 'chuck-norris' ) } > chuck-norris</ button >
227
229
</ li >
230
+ < li >
231
+ < button onClick = { exec ( 'star-wars' ) } > star-wars</ button >
232
+ </ li >
228
233
< li >
229
234
< button onClick = { exec ( 'fortune | cowsay | lolcat' ) } > cowsay</ button >
230
235
</ li >
Original file line number Diff line number Diff line change
1
+ import type { JQueryTerminal } from 'jquery.terminal' ;
2
+
3
+ export default async function command ( this : JQueryTerminal , delay_arg = '50' ) {
4
+ const $ = ( globalThis as any ) . $ as any ; ;
5
+ if ( this . cols ( ) < 67 ) {
6
+ this . error ( 'not enough width to run the star wars' ) ;
7
+ return ;
8
+ }
9
+ let delay = parseInt ( delay_arg ) ;
10
+ const sw_frames : string [ ] [ ] = globalThis . sw_frames = ( globalThis as any ) . sw_frames ?? [ ] ;
11
+ if ( ! globalThis . star_wars ) {
12
+ await $ . getScript ( 'https://cdn.jsdelivr.net/gh/jcubic/static@master/js/star_wars.js' ) ;
13
+ const star_wars = globalThis . star_wars ;
14
+ const LINES_PER_FRAME = 14 ;
15
+ const lines = star_wars . length ;
16
+ for ( let i = 0 ; i < lines ; i += LINES_PER_FRAME ) {
17
+ sw_frames . push ( star_wars . slice ( i , i + LINES_PER_FRAME ) ) ;
18
+ }
19
+ }
20
+ let stop = false ;
21
+ function play ( term : JQueryTerminal ) {
22
+ let i = 0 ;
23
+ let next_delay : number ;
24
+ ( function display ( ) {
25
+ if ( i == sw_frames . length ) {
26
+ i = 0 ;
27
+ }
28
+ if ( ! stop ) {
29
+ term . clear ( ) ;
30
+ if ( sw_frames [ i ] [ 0 ] . match ( / [ 0 - 9 ] + / ) ) {
31
+ next_delay = parseInt ( sw_frames [ i ] [ 0 ] ) * delay ;
32
+ } else {
33
+ next_delay = delay ;
34
+ }
35
+ term . echo ( sw_frames [ i ++ ] . slice ( 1 ) . join ( '\n' ) + '\n' ) ;
36
+ setTimeout ( display , next_delay ) ;
37
+ }
38
+ } ) ( ) ;
39
+ }
40
+ const view : JQueryTerminal . View = this . export_view ( ) ;
41
+ function exit ( ) {
42
+ stop = true ;
43
+ this . cmd ( ) . show ( ) ;
44
+ this . import_view ( view ) ;
45
+ }
46
+ this . push ( $ . noop , {
47
+ onExit : exit ,
48
+ keymap : {
49
+ 'Q' : exit ,
50
+ 'CTRL+C' : exit ,
51
+ 'ESCAPE' : exit
52
+ } ,
53
+ prompt : ''
54
+ } ) ;
55
+ this . cmd ( ) . hide ( ) ;
56
+ play ( this ) ;
57
+ }
You can’t perform that action at this time.
0 commit comments