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 | const termkit = require( '../..' ) ;
|
33 | const term = termkit.terminal ;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | term.on( 'key' , function( key ) {
|
39 | switch( key )
|
40 | {
|
41 | case 'CTRL_C' :
|
42 | term.grabInput( false ) ;
|
43 | term.hideCursor( false ) ;
|
44 | term.styleReset() ;
|
45 | term( '\n' ) ;
|
46 | process.exit() ;
|
47 | break ;
|
48 | }
|
49 | } ) ;
|
50 |
|
51 |
|
52 |
|
53 | async function test() {
|
54 | var button = await term.createInlineElement( termkit.Button , {
|
55 | outputDst: term ,
|
56 | content: '> bob' ,
|
57 | value: 'bob' ,
|
58 | x: 10 , y: 10 ,
|
59 | } ) ;
|
60 | }
|
61 |
|
62 | async function test2() {
|
63 |
|
64 |
|
65 | var columnMenu = await term.createInlineElement( termkit.ColumnMenu , {
|
66 |
|
67 |
|
68 | items: [
|
69 | {
|
70 | content: 'File' ,
|
71 | value: 'file'
|
72 | } ,
|
73 | {
|
74 | content: 'Edit' ,
|
75 | value: 'edit'
|
76 | } ,
|
77 | {
|
78 | content: 'View' ,
|
79 | value: 'view'
|
80 | } ,
|
81 | {
|
82 | content: 'History' ,
|
83 | value: 'history'
|
84 | } ,
|
85 | {
|
86 | content: 'Bookmarks' ,
|
87 | value: 'bookmarks'
|
88 | } ,
|
89 | {
|
90 | content: 'Tools' ,
|
91 | value: 'tools'
|
92 | } ,
|
93 | {
|
94 | content: 'Help' ,
|
95 | value: 'help'
|
96 | } ,
|
97 | ]
|
98 | } ) ;
|
99 |
|
100 | columnMenu.on( 'submit' , onSubmit ) ;
|
101 |
|
102 | function onSubmit( buttonValue ) {
|
103 |
|
104 | term.saveCursor() ;
|
105 | term.moveTo.styleReset.eraseLine( 1 , 22 , 'Submitted: %s\n' , buttonValue ) ;
|
106 | term.restoreCursor() ;
|
107 | }
|
108 |
|
109 | columnMenu.document.giveFocusTo( columnMenu ) ;
|
110 | }
|
111 |
|
112 | function test3() {
|
113 | var table = term.createInlineElement( termkit.TextTable , {
|
114 | cellContents: [
|
115 |
|
116 | [ 'header #1' , 'header #2' , 'header #3' ] ,
|
117 | [ 'row #1' , 'a much bigger cell '.repeat( 10 ) , 'cell' ] ,
|
118 | [ 'row #2' , 'cell' , 'a medium cell' ] ,
|
119 | [ 'row #3' , 'cell' , 'cell' ] ,
|
120 | [ 'row #4' , 'cell\nwith\nnew\nlines' , 'cell' ]
|
121 |
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 | ] ,
|
128 |
|
129 |
|
130 |
|
131 | fit: true
|
132 | } ) ;
|
133 |
|
134 |
|
135 |
|
136 | }
|
137 |
|
138 |
|
139 |
|
140 | test3() ;
|
141 |
|