UNPKG

4.33 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 esc = tree.extend( null , Object.create( xterm.esc ) , {
37 // Not supported...
38 setClipboardLL: { na: true } ,
39 requestClipboard: { na: true } ,
40
41 // Amazingly, those uber-standard and uber-common sequences are *NOT* supported by Konsole...
42 // SHAME on you KDE! Even the Linux Console support it!
43 // This workaround use up()/down() & column(1)
44 nextLine: { on: '\x1b[%UB\x1b[1G' } ,
45 previousLine: { on: '\x1b[%UA\x1b[1G' } ,
46
47 // Cursor styles
48 blockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
49 blinkingBlockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
50 underlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
51 blinkingUnderlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
52 beamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
53 blinkingBeamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
54
55 requestColor: { on: '%D' , na: true } // not capable
56} ) ;
57
58
59
60
61
62/* Key Mapping */
63
64
65
66const keymap = Object.create( xterm.keymap ) ;
67
68
69
70
71
72/* Handlers */
73
74
75
76const handler = Object.create( xterm.handler ) ;
77
78
79
80// Stoopid KDE again, it can flood MOUSE_X_PRESSED on mouse drag, rather than MOUSE_MOTION -_-'
81// This is a copy-paste of handler.mouseSGRProtocol of xterm.js, with the appropriated work-around
82handler.mouseSGRProtocol = function mouseSGRProtocol( basename , buffer ) {
83 var code , pressed , matches , result ;
84
85 matches = buffer.toString().match( /^([0-9]*);([0-9]*);([0-9]*)(.)/ ) ;
86
87 code = parseInt( matches[ 1 ] , 10 ) ;
88 pressed = matches[ 4 ] !== 'm' ;
89
90 result = {
91 data: {
92 shift: !! ( code & 4 ) ,
93 alt: !! ( code & 8 ) ,
94 ctrl: !! ( code & 16 )
95 }
96 } ;
97
98 result.data.x = parseInt( matches[ 2 ] , 10 ) ;
99 result.data.y = parseInt( matches[ 3 ] , 10 ) ;
100 result.eaten = matches[ 0 ].length ;
101
102 if ( code & 32 ) {
103 // Motions event
104 result.name = basename + '_MOTION' ;
105 }
106 else if ( code & 64 ) {
107 result.name = basename + ( code & 1 ? '_WHEEL_DOWN' : '_WHEEL_UP' ) ;
108 }
109 else {
110 //console.log( this.state.button ) ;
111
112 // Button event
113 switch ( code & 3 ) {
114 case 0 :
115 result.name = basename + '_LEFT_BUTTON' ;
116 if ( this.state.button.left === pressed ) { result.disable = true ; }
117 this.state.button.left = pressed ;
118 break ;
119
120 case 1 :
121 result.name = basename + '_MIDDLE_BUTTON' ;
122 if ( this.state.button.middle === pressed ) { result.disable = true ; }
123 this.state.button.middle = pressed ;
124 break ;
125
126 case 2 :
127 result.name = basename + '_RIGHT_BUTTON' ;
128 if ( this.state.button.right === pressed ) { result.disable = true ; }
129 this.state.button.right = pressed ;
130 break ;
131
132 case 3 :
133 result.name = basename + '_OTHER_BUTTON' ;
134 if ( this.state.button.other === pressed ) { result.disable = true ; }
135 this.state.button.other = pressed ;
136 break ;
137 }
138
139 result.name += pressed ? '_PRESSED' : '_RELEASED' ;
140 }
141
142 result.data.code = code ;
143
144 return result ;
145} ;
146
147
148
149module.exports = {
150 esc: esc ,
151 keymap: keymap ,
152 handler: handler ,
153 support: {
154 deltaEscapeSequence: true ,
155 "256colors": false ,
156 "24bitsColors": false , // DEPRECATED
157 "trueColor": false
158 } ,
159 colorRegister: require( '../colorScheme/konsole.json' )
160} ;
161