UNPKG

2.93 kBJavaScriptView Raw
1#!/usr/bin/env node
2/*
3 Terminal Kit
4
5 Copyright (c) 2009 - 2020 Cédric Ronvel
6
7 The MIT License (MIT)
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26*/
27
28"use strict" ;
29
30
31
32var termkit = require( '../..' ) ;
33var term = termkit.terminal ;
34
35
36
37term.clear() ;
38
39var document = term.createDocument() ;
40
41
42
43var columnMenuMulti = new termkit.ColumnMenuMulti( {
44 parent: document ,
45 x: 0 ,
46 y: 5 ,
47 width: 20 ,
48 pageMaxHeight: 5 ,
49 blurLeftPadding: ' ' ,
50 focusLeftPadding: '^R> ' ,
51 disabledLeftPadding: ' ' ,
52 paddingHasMarkup: true ,
53 multiLineItems: true ,
54
55 value: {
56 view: true ,
57 file: true
58 } ,
59 items: [
60 {
61 content: 'File' ,
62 key: 'file'
63 } ,
64 {
65 //content: 'Edit' ,
66 content: '^REdit' , markup: true ,
67 key: 'edit'
68 } ,
69 {
70 content: 'View' ,
71 key: 'view'
72 } ,
73 {
74 content: 'History' ,
75 key: 'history'
76 } ,
77 {
78 content: 'Bookmarks' ,
79 key: 'bookmarks'
80 } ,
81 {
82 content: 'Tools' ,
83 key: 'tools'
84 } ,
85 {
86 content: 'Help' ,
87 key: 'help'
88 } ,
89 {
90 content: 'Disabled button' ,
91 disabled: true ,
92 key: 'disabled'
93 } ,
94 {
95 //content: 'Very long, very long, very long, very long, very long, very long, very long, very long, very long, very long' ,
96 content: 'Very long, very long, very ^rlong, very long, very long, very long, very ^blong, very long, very long, very long' , markup: true ,
97 key: 'very long'
98 } ,
99 {
100 content: 'Not long' ,
101 key: 'not long'
102 } ,
103 ]
104} ) ;
105
106
107
108columnMenuMulti.on( 'submit' , onSubmit ) ;
109
110var counter = 0 ;
111
112function onSubmit( buttonValue ) {
113 term.saveCursor() ;
114 term.moveTo.styleReset.eraseLine( 1 , 22 , 'Submitted #%i: %J\n' , counter ++ , buttonValue ) ;
115 term.restoreCursor() ;
116}
117
118
119
120document.giveFocusTo( columnMenuMulti ) ;
121
122term.on( 'key' , function( key ) {
123 switch( key )
124 {
125 case 'CTRL_C' :
126 term.grabInput( false ) ;
127 term.hideCursor( false ) ;
128 term.styleReset() ;
129 term.clear() ;
130 process.exit() ;
131 break ;
132 }
133} ) ;
134