UNPKG

5.34 kBJavaScriptView Raw
1/*
2 Terminal Kit
3
4 Copyright (c) 2009 - 2020 Cédric Ronvel
5
6 The MIT License (MIT)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26
27"use strict" ;
28
29
30
31const tree = require( 'tree-kit' ) ;
32const xterm = require( './xterm.js' ) ;
33
34
35
36const bold = '\x1b[1m' ;
37const noBold = '\x1b[22m' ;
38const blink = '\x1b[5m' ;
39const noBlink = '\x1b[25m' ;
40const defaultColor = '\x1b[39m' + noBold ; // back to the default color, most of time it is the same than .white
41const bgDefaultColor = '\x1b[49m' + noBlink ; // back to the default color, most of time it is the same than .bgBlack
42
43
44
45const esc = tree.extend( null , Object.create( xterm.esc ) , {
46 // Not supported...
47 setClipboardLL: { na: true } ,
48 requestClipboard: { na: true } ,
49
50 // Eterm doesn't have bright color code, they are produced using 'bold' (which is not bold, by the way...)
51 defaultColor: { on: defaultColor } ,
52 brightBlack: { on: bold + '\x1b[30m' , off: defaultColor } ,
53 brightRed: { on: bold + '\x1b[31m' , off: defaultColor } ,
54 brightGreen: { on: bold + '\x1b[32m' , off: defaultColor } ,
55 brightYellow: { on: bold + '\x1b[33m' , off: defaultColor } ,
56 brightBlue: { on: bold + '\x1b[34m' , off: defaultColor } ,
57 brightMagenta: { on: bold + '\x1b[35m' , off: defaultColor } ,
58 brightCyan: { on: bold + '\x1b[36m' , off: defaultColor } ,
59 brightWhite: { on: bold + '\x1b[37m' , off: defaultColor } ,
60 brightColor: { on: bold + '\x1b[3%um' , off: defaultColor } , // should be called with a 0..7 integer
61
62 // Eterm console doesn't have bright bg color code, they are produced using 'blink' (which does not blink, by the way...)
63 bgDefaultColor: { on: bgDefaultColor } ,
64 bgBrightBlack: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,
65 bgBrightRed: { on: blink + '\x1b[41m' , off: bgDefaultColor } ,
66 bgBrightGreen: { on: blink + '\x1b[42m' , off: bgDefaultColor } ,
67 bgBrightYellow: { on: blink + '\x1b[43m' , off: bgDefaultColor } ,
68 bgBrightBlue: { on: blink + '\x1b[44m' , off: bgDefaultColor } ,
69 bgBrightMagenta: { on: blink + '\x1b[45m' , off: bgDefaultColor } ,
70 bgBrightCyan: { on: blink + '\x1b[46m' , off: bgDefaultColor } ,
71 bgBrightWhite: { on: blink + '\x1b[47m' , off: bgDefaultColor } ,
72 bgBrightColor: { on: blink + '\x1b[4%um' , off: bgDefaultColor } , // should be called with a 0..7 integer
73
74 // Cursor styles not supported
75 blockCursor: { on: '' , na: true } ,
76 blinkingBlockCursor: { on: '' , na: true } ,
77 underlineCursor: { on: '' , na: true } ,
78 blinkingUnderlineCursor: { on: '' , na: true } ,
79 beamCursor: { on: '' , na: true } ,
80 blinkingBeamCursor: { on: '' , na: true } ,
81
82 // Not capable, fallback to mouseButton
83 mouseDrag: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,
84 mouseMotion: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,
85
86 requestColor: { on: '%D' , na: true } // not capable
87} ) ;
88
89
90
91
92
93/* Key Mapping */
94
95
96
97const keymap = tree.extend( null , Object.create( xterm.keymap ) , {
98 F1: '\x1b[11~' ,
99 F2: '\x1b[12~' ,
100 F3: '\x1b[13~' ,
101 F4: '\x1b[14~' ,
102
103 //SHIFT_F1: '\x1b[25~' , // no difference with F11
104 //SHIFT_F2: '\x1b[26~' , // no difference with F12
105 SHIFT_F3: '\x1b[25~' ,
106 SHIFT_F4: '\x1b[26~' ,
107 SHIFT_F5: '\x1b[28~' ,
108 SHIFT_F6: '\x1b[29~' ,
109 SHIFT_F7: '\x1b[31~' ,
110 SHIFT_F8: '\x1b[32~' ,
111 SHIFT_F9: '\x1b[33~' ,
112 SHIFT_F10: '\x1b[34~' ,
113 SHIFT_F11: '\x1b[23$' ,
114 SHIFT_F12: '\x1b[24$' ,
115
116 CTRL_F1: '\x1b[11^' ,
117 CTRL_F2: '\x1b[12^' ,
118 CTRL_F3: '\x1b[13^' ,
119 CTRL_F4: '\x1b[14^' ,
120 CTRL_F5: '\x1b[15^' ,
121 CTRL_F6: '\x1b[17^' ,
122 CTRL_F7: '\x1b[18^' ,
123 CTRL_F8: '\x1b[19^' ,
124 CTRL_F9: '\x1b[20^' ,
125 CTRL_F10: '\x1b[21^' ,
126 CTRL_F11: '\x1b[23^' ,
127 CTRL_F12: '\x1b[24^' ,
128
129 //CTRL_SHIFT_F1: '\x1b[11^' , // no difference with CTRL_F11
130 //CTRL_SHIFT_F2: '\x1b[12^' , // no difference with CTRL_F12
131 CTRL_SHIFT_F3: '\x1b[25^' ,
132 CTRL_SHIFT_F4: '\x1b[26^' ,
133 CTRL_SHIFT_F5: '\x1b[28^' ,
134 CTRL_SHIFT_F6: '\x1b[29^' ,
135 CTRL_SHIFT_F7: '\x1b[31^' ,
136 CTRL_SHIFT_F8: '\x1b[32^' ,
137 CTRL_SHIFT_F9: '\x1b[33^' ,
138 CTRL_SHIFT_F10: '\x1b[34^' ,
139 CTRL_SHIFT_F11: '\x1b[23@' ,
140 CTRL_SHIFT_F12: '\x1b[24@'
141
142} ) ;
143
144
145
146const handler = Object.create( xterm.handler ) ;
147
148
149
150module.exports = {
151 esc: esc ,
152 keymap: keymap ,
153 handler: handler ,
154 support: {
155 deltaEscapeSequence: true ,
156 "256colors": false ,
157 "24bitsColors": false , // DEPRECATED
158 "trueColor": false
159 } ,
160 colorRegister: require( '../colorScheme/xterm.json' )
161} ;
162