@@ -27,10 +27,74 @@ class Terminal {
2727 this . Ipc . send ( "terminal_channel-" + this . port , "Resize" , cols , rows ) ;
2828 } ;
2929
30+ // Support for custom color filters on the terminal - see #483
31+ let doCustomFilter = false ;
32+
33+ // Typechecking condition to ensure that provided filters are valid and prevent code injection
34+ if ( typeof window . theme . terminal . colorFilter === "object" && window . theme . terminal . colorFilter . length > 0 ) {
35+ doCustomFilter = window . theme . terminal . colorFilter . every ( ( step , i , a ) => {
36+ let func = step . slice ( 0 , step . indexOf ( "(" ) ) ;
37+
38+ switch ( func ) {
39+ case "negate" :
40+ case "grayscale" :
41+ a [ i ] = {
42+ func,
43+ arg : [ ]
44+ } ;
45+ return true ;
46+ case "lighten" :
47+ case "darken" :
48+ case "saturate" :
49+ case "desaturate" :
50+ case "whiten" :
51+ case "blacken" :
52+ case "fade" :
53+ case "opaquer" :
54+ case "rotate" :
55+ case "mix" :
56+ break ;
57+ default :
58+ return false ;
59+ }
60+
61+ let arg = step . slice ( step . indexOf ( "(" ) + 1 , step . indexOf ( ")" ) ) ;
62+
63+ if ( typeof Number ( arg ) === "number" ) {
64+ a [ i ] = {
65+ func,
66+ arg : [ Number ( arg ) ]
67+ } ;
68+ return true ;
69+ }
70+
71+ return false ;
72+ } ) ;
73+ }
74+
3075 let color = require ( "color" ) ;
31- let colorify = ( base , target ) => {
32- return color ( base ) . grayscale ( ) . mix ( color ( target ) , 0.3 ) . hex ( ) ;
33- } ;
76+ let colorify ;
77+ if ( doCustomFilter ) {
78+ colorify = ( base , target ) => {
79+ let newColor = color ( base ) ;
80+ target = color ( target ) ;
81+
82+ for ( let i = 0 ; i < window . theme . terminal . colorFilter . length ; i ++ ) {
83+ if ( window . theme . terminal . colorFilter [ i ] . func === "mix" ) {
84+ newColor = newColor [ window . theme . terminal . colorFilter [ i ] . func ] ( target , ...window . theme . terminal . colorFilter [ i ] . arg ) ;
85+ } else {
86+ newColor = newColor [ window . theme . terminal . colorFilter [ i ] . func ] ( ...window . theme . terminal . colorFilter [ i ] . arg ) ;
87+ }
88+ }
89+
90+ return newColor . hex ( ) ;
91+ } ;
92+ } else {
93+ colorify = ( base , target ) => {
94+ return color ( base ) . grayscale ( ) . mix ( color ( target ) , 0.3 ) . hex ( ) ;
95+ } ;
96+ }
97+
3498 let themeColor = `rgb(${ window . theme . r } , ${ window . theme . g } , ${ window . theme . b } )` ;
3599
36100 this . term = new this . xTerm ( {
0 commit comments