UNPKG

2.98 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' ) ;
33const string = require( 'string-kit' ) ;
34
35
36
37// Remove colors
38const defaultColor = '\x1b[39m' ; // back to the default color, most of time it is the same than .white
39const bgDefaultColor = '\x1b[49m' ; // back to the default color, most of time it is the same than .bgBlack
40
41
42const esc = tree.extend( null , Object.create( xterm.esc ) , {
43
44 color256: { on: '\x1b[38;5;%um' , off: defaultColor } ,
45 bgColor256: { on: '\x1b[48;5;%um' , off: bgDefaultColor } ,
46
47 setCursorColorRgb: { on: '\x1b]12;#%x%x%x\x07' } , // it want rgb as parameter, like rgb:127/0/32
48 setDefaultColorRgb: { on: '\x1b]10;#%x%x%x\x07' } , // ->|TODOC|<- not widely supported
49 setDefaultBgColorRgb: { on: '\x1b]11;#%x%x%x\x07' } , // ->|TODOC|<- not widely supported
50 color24bits: { on: '\x1b[38;2;%u;%u;%um' , off: defaultColor , fb: true } ,
51 bgColor24bits: { on: '\x1b[48;2;%u;%u;%um' , off: bgDefaultColor , fb: true } ,
52
53 // Cannot find a way to set the cursor to a register, so try to guess
54 setCursorColor: {
55 on: '%[setCursorColor:%a%a]F' ,
56 handler: function setCursorColor( bg , fg ) {
57
58 if ( typeof fg !== 'number' || typeof bg !== 'number' ) { return '' ; }
59
60 fg = Math.floor( fg ) ;
61 bg = Math.floor( bg ) ;
62
63 if ( fg < 0 || fg > 255 || bg < 0 || bg > 255 ) { return '' ; }
64
65 var rgb = this.root.rgbForRegister( bg ) ;
66
67 return string.format( this.root.esc.setCursorColorRgb.on , rgb.r , rgb.g , rgb.b ) ;
68 }
69 }
70} ) ;
71
72
73
74
75
76const keymap = Object.create( xterm.keymap ) ;
77const handler = Object.create( xterm.handler ) ;
78
79
80
81
82
83module.exports = {
84 esc: esc ,
85 keymap: keymap ,
86 handler: handler ,
87 support: {
88 deltaEscapeSequence: true ,
89 "256colors": true ,
90 "24bitsColors": false , // DEPRECATED
91 "trueColor": false
92 } ,
93 colorRegister: xterm.colorRegister
94} ;