File tree 4 files changed +32
-3
lines changed
4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,12 @@ export const vt52Codes = new Map([
15
15
[ '>' , [ 'Exit alternate keypad mode' ] ] ,
16
16
[ '1' , [ 'Graphics processor on' ] ] ,
17
17
[ '2' , [ 'Graphics processor off' ] ] ,
18
- [ '<' , [ 'Enter ANSI mode' ] ]
18
+ [ '<' , [ 'Enter ANSI mode' ] ] ,
19
+ [ 's' , [ 'Cursor save' ] ] ,
20
+ [ 'u' , [ 'Cursor restore' ] ]
19
21
] ) ;
20
22
21
- // From http ://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
23
+ // From https ://espterm.github.io/docs/VT100%20escape%20codes.html
22
24
export const ansiCompatible = new Map ( [
23
25
[ '[176A' , [ 'Cursor up Pn lines' ] ] ,
24
26
[ '[176B' , [ 'Cursor down Pn lines' ] ] ,
Original file line number Diff line number Diff line change 1
1
export default function ansiRegex ( { onlyFirst = false } = { } ) {
2
2
const pattern = [
3
3
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)' ,
4
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry =><~]))'
4
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy =><~]))'
5
5
] . join ( '|' ) ;
6
6
7
7
return new RegExp ( pattern , onlyFirst ? undefined : 'g' ) ;
Original file line number Diff line number Diff line change 51
51
" pattern"
52
52
],
53
53
"devDependencies" : {
54
+ "ansi-escapes" : " ^5.0.0" ,
54
55
"ava" : " ^3.15.0" ,
55
56
"tsd" : " ^0.14.0" ,
56
57
"xo" : " ^0.38.2"
Original file line number Diff line number Diff line change 1
1
import test from 'ava' ;
2
+ import ansiEscapes from 'ansi-escapes' ;
2
3
import * as ansiCodes from './fixtures/ansi-codes.js' ;
3
4
import ansiRegex from './index.js' ;
4
5
@@ -92,3 +93,28 @@ for (const codeSet of Object.keys(ansiCodes)) {
92
93
} ) ;
93
94
}
94
95
}
96
+
97
+ const escapeCodeFunctionArgs = [ 1 , 2 ] ;
98
+ const escapeCodeIgnoresList = new Set ( [ 'beep' , 'image' , 'iTerm' ] ) ;
99
+ const escapeCodeResultMap = new Map ( [ [ 'link' , escapeCodeFunctionArgs [ 0 ] ] ] ) ;
100
+
101
+ for ( const key of Object . keys ( ansiEscapes ) ) {
102
+ if ( escapeCodeIgnoresList . has ( key ) ) {
103
+ continue ;
104
+ }
105
+
106
+ const escapeCode = ansiEscapes [ key ] ;
107
+
108
+ const escapeCodeValue = typeof escapeCode === 'function' ?
109
+ escapeCode ( ...escapeCodeFunctionArgs ) :
110
+ escapeCode ;
111
+
112
+ test ( `ansi-escapes ${ key } ` , t => {
113
+ for ( const character of consumptionCharacters ) {
114
+ const string = escapeCodeValue + character ;
115
+ const result = ( escapeCodeResultMap . get ( key ) || '' ) + character ;
116
+
117
+ t . is ( string . replace ( ansiRegex ( ) , '' ) , result ) ;
118
+ }
119
+ } ) ;
120
+ }
You can’t perform that action at this time.
0 commit comments