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 |
|
33 |
|
34 |
|
35 |
|
36 | require( '../lib/termkit.js' ).getDetectedTerminal( function( error , term ) {
|
37 |
|
38 |
|
39 | function terminate()
|
40 | {
|
41 | term.brightBlack( 'About to exit...\n' ) ;
|
42 | term.grabInput( false ) ;
|
43 | term.applicationKeypad( false ) ;
|
44 | term.beep() ;
|
45 | term.fullscreen( false ) ;
|
46 |
|
47 |
|
48 | setTimeout( function() { process.exit() ; } , 100 ) ;
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 | term.fullscreen() ;
|
54 | term.bold.cyan( 'Key test, hit anything on the keyboard to see how it is detected...\n' ) ;
|
55 | term.green( 'Hit CTRL-C to quit, CTRL-D to change the mouse reporting mode\n\n' ) ;
|
56 | term.green( 'mouse in motion mode\n' ) ;
|
57 |
|
58 |
|
59 | term.applicationKeypad() ;
|
60 |
|
61 |
|
62 |
|
63 | term.grabInput( { mouse: 'motion' , focus: true } ) ;
|
64 |
|
65 | var mouseMode = 3 ;
|
66 |
|
67 | term.on( 'key' , function( name , matches , data ) {
|
68 |
|
69 | if ( matches.indexOf( 'CTRL_C' ) >= 0 )
|
70 | {
|
71 | term.green( 'CTRL-C received...\n' ) ;
|
72 | terminate() ;
|
73 | }
|
74 |
|
75 | if ( matches.indexOf( 'CTRL_D' ) >= 0 )
|
76 | {
|
77 | term.green( 'CTRL-D received: ' ) ;
|
78 | mouseMode = ( mouseMode + 1 ) % 4 ;
|
79 |
|
80 | switch ( mouseMode )
|
81 | {
|
82 | case 0 :
|
83 | term.green( 'turn mouse off\n' ) ;
|
84 | term.grabInput( { mouse: false , focus: true } ) ;
|
85 | break ;
|
86 | case 1 :
|
87 | term.green( 'mouse in button mode\n' ) ;
|
88 | term.grabInput( { mouse: 'button' , focus: true } ) ;
|
89 | break ;
|
90 | case 2 :
|
91 | term.green( 'mouse in drag mode\n' ) ;
|
92 | term.grabInput( { mouse: 'drag' , focus: true } ) ;
|
93 | break ;
|
94 | case 3 :
|
95 | term.green( 'mouse in motion mode\n' ) ;
|
96 | term.grabInput( { mouse: 'motion' , focus: true } ) ;
|
97 | break ;
|
98 | }
|
99 | }
|
100 | } ) ;
|
101 |
|
102 | term.on( 'terminal' , function( name , data ) {
|
103 | console.log( "'terminal' event:" , name , data ) ;
|
104 | } ) ;
|
105 |
|
106 | term.on( 'mouse' , function( name , data ) {
|
107 | term( "'mouse' event: %s %n\n" , name , data ) ;
|
108 | } ) ;
|
109 |
|
110 | term.on( 'unknown' , function( buffer ) {
|
111 | console.log( "'unknown' event, buffer:" , buffer ) ;
|
112 | } ) ;
|
113 |
|
114 | } ) ;
|
115 |
|