File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Expand file tree Collapse file tree 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([
1515[ '>' , [ 'Exit alternate keypad mode' ] ] ,
1616[ '1' , [ 'Graphics processor on' ] ] ,
1717[ '2' , [ 'Graphics processor off' ] ] ,
18- [ '<' , [ 'Enter ANSI mode' ] ]
18+ [ '<' , [ 'Enter ANSI mode' ] ] ,
19+ [ 's' , [ 'Cursor save' ] ] ,
20+ [ 'u' , [ 'Cursor restore' ] ]
1921] ) ;
2022
21- // From http ://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
23+ // From https ://espterm.github.io/docs/VT100%20escape%20codes.html
2224export const ansiCompatible = new Map ( [
2325[ '[176A' , [ 'Cursor up Pn lines' ] ] ,
2426[ '[176B' , [ 'Cursor down Pn lines' ] ] ,
Original file line number Diff line number Diff line change 11export default function ansiRegex ( { onlyFirst = false } = { } ) {
22const pattern = [
33'[\\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 =><~]))'
55] . join ( '|' ) ;
66
77return new RegExp ( pattern , onlyFirst ? undefined : 'g' ) ;
Original file line number Diff line number Diff line change 5151" pattern"
5252],
5353"devDependencies" : {
54+ "ansi-escapes" : " ^5.0.0" ,
5455"ava" : " ^3.15.0" ,
5556"tsd" : " ^0.14.0" ,
5657"xo" : " ^0.38.2"
Original file line number Diff line number Diff line change 11import test from 'ava' ;
2+ import ansiEscapes from 'ansi-escapes' ;
23import * as ansiCodes from './fixtures/ansi-codes.js' ;
34import ansiRegex from './index.js' ;
45
@@ -92,3 +93,28 @@ for (const codeSet of Object.keys(ansiCodes)) {
9293} ) ;
9394}
9495}
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