1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | "use strict" ;
|
29 |
|
30 |
|
31 |
|
32 | require( '../lib/termkit.js' ).getDetectedTerminal( function( error , term ) {
|
33 |
|
34 | var terminating = false ;
|
35 |
|
36 | function terminate()
|
37 | {
|
38 | terminating = true ;
|
39 | term.brightBlack( 'About to exit...\n' ) ;
|
40 | term.grabInput( false ) ;
|
41 |
|
42 |
|
43 | setTimeout( function() { process.exit() ; } , 250 ) ;
|
44 | }
|
45 |
|
46 | var i = 0 ;
|
47 |
|
48 | function getColors() {
|
49 |
|
50 | if ( terminating ) { return ; }
|
51 |
|
52 | term.getColor( i , ( error , reg ) => {
|
53 |
|
54 | if ( error ) { term.red( error.toString() + '\n' ) ; }
|
55 | else { term( '#%u -- R:%u G:%u B:%u\n' , reg.register , reg.r , reg.g , reg.b ) ; }
|
56 |
|
57 | if ( terminating ) { return ; }
|
58 |
|
59 | if ( i < 15 ) { i ++ ; getColors() ; }
|
60 | else { terminate() ; }
|
61 | } ) ;
|
62 | }
|
63 |
|
64 | term.on( 'key' , function( name , matches , data ) {
|
65 |
|
66 | console.log(
|
67 | "'key' event:" ,
|
68 | name ,
|
69 | matches ,
|
70 | Buffer.isBuffer( data.code ) ? data.code : data.code.toString( 16 ) ,
|
71 | data.codepoint ? data.codepoint.toString( 16 ) : ''
|
72 | ) ;
|
73 |
|
74 | if ( matches.indexOf( 'CTRL_C' ) >= 0 )
|
75 | {
|
76 | term.green( 'CTRL-C received...\n' ) ;
|
77 | terminate() ;
|
78 | }
|
79 |
|
80 | if ( matches.indexOf( 'CTRL_R' ) >= 0 )
|
81 | {
|
82 | term.green( 'CTRL-R received... asking terminal some information...\n' ) ;
|
83 | term.requestCursorLocation() ;
|
84 | term.requestScreenSize() ;
|
85 | }
|
86 | } ) ;
|
87 |
|
88 |
|
89 | term.on( 'terminal' , function( name , data ) {
|
90 | console.log( "'terminal' event:" , name , data ) ;
|
91 | } ) ;
|
92 |
|
93 | term.on( 'mouse' , function( name , data ) {
|
94 | console.log( "'mouse' event:" , name , data ) ;
|
95 | } ) ;
|
96 |
|
97 | term.on( 'unknown' , function( buffer ) {
|
98 | console.log( "'unknown' event, buffer:" , buffer ) ;
|
99 | } ) ;
|
100 |
|
101 |
|
102 | getColors() ;
|
103 | setTimeout( terminate , 2000 ) ;
|
104 | } ) ;
|
105 |
|