-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nigel Scott
committed
Jan 20, 2020
1 parent
93c224f
commit 6b8506d
Showing
6 changed files
with
215 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var vscode = require( 'vscode' ); | ||
|
||
function getAttribute( tag, attribute, defaultValue ) | ||
{ | ||
function getCustomHighlightSettings( customHighlight, tag ) | ||
{ | ||
var result; | ||
Object.keys( customHighlight ).map( function( t ) | ||
{ | ||
var flags = ''; | ||
if( vscode.workspace.getConfiguration( 'todo-tree.regex' ).get( 'regexCaseSensitive' ) === false ) | ||
{ | ||
flags += 'i'; | ||
} | ||
t = t.replace( /\\/g, '\\\\' ); | ||
t = t.replace( /[|{}()[\]^$+*?.-]/g, '\\$&' ); | ||
|
||
var regex = new RegExp( t, flags ); | ||
|
||
if( tag.match( regex ) ) | ||
{ | ||
result = customHighlight[ tag ]; | ||
} | ||
} ); | ||
return result; | ||
} | ||
|
||
var config = vscode.workspace.getConfiguration( 'todo-tree.highlights' ); | ||
var tagSettings = getCustomHighlightSettings( config.customHighlight, tag ); | ||
if( tagSettings && tagSettings[ attribute ] !== undefined ) | ||
{ | ||
return tagSettings[ attribute ]; | ||
} | ||
else | ||
{ | ||
var defaultHighlight = config.get( 'defaultHighlight' ); | ||
if( defaultHighlight[ attribute ] !== undefined ) | ||
{ | ||
return defaultHighlight[ attribute ]; | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
|
||
function getIcon( tag ) | ||
{ | ||
return getAttribute( tag, 'icon', undefined ); | ||
} | ||
|
||
function getIconColour( tag ) | ||
{ | ||
var foreground = getAttribute( tag, 'foreground', undefined ); | ||
var background = getAttribute( tag, 'background', undefined ); | ||
|
||
return getAttribute( tag, 'iconColour', foreground ? foreground : ( background ? background : "green" ) ); | ||
} | ||
|
||
module.exports.getAttribute = getAttribute; | ||
module.exports.getIcon = getIcon; | ||
module.exports.getIconColour = getIconColour; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
var vscode = require( 'vscode' ); | ||
|
||
var utils = require( './utils.js' ); | ||
|
||
var defaultColours = [ "red", "green", "blue", "yellow", "magenta", "cyan", "grey", "white", "black" ]; | ||
|
||
var defaultLightColours = { | ||
"red": "#CC0000", | ||
"green": "#008f00", | ||
"blue": "#0433ff", | ||
"yellow": "#c8c800", | ||
"magenta": "#bb60bb", | ||
"cyan": "#76d6ff", | ||
"grey": "#888888", | ||
"white": "#ffffff", | ||
"black": "#000000" | ||
}; | ||
|
||
var defaultDarkColours = { | ||
"red": "#CC0000", | ||
"green": "#6AC259", | ||
"blue": "#0433ff", | ||
"yellow": "#fffb00", | ||
"magenta": "#ff85ff", | ||
"cyan": "#76d6ff", | ||
"grey": "#aaaaaa", | ||
"white": "#ffffff", | ||
"black": "#000000" | ||
}; | ||
|
||
var complementaryColours = {}; | ||
|
||
function getColourList() | ||
{ | ||
return defaultColours; | ||
} | ||
|
||
function complementaryColour( colour ) | ||
{ | ||
var hex = colour.split( / / )[ 0 ].replace( /[^\da-fA-F]/g, '' ); | ||
var digits = hex.length / 3; | ||
var red = parseInt( hex.substr( 0, digits ), 16 ); | ||
var green = parseInt( hex.substr( 1 * digits, digits ), 16 ); | ||
var blue = parseInt( hex.substr( 2 * digits, digits ), 16 ); | ||
var c = [ red / 255, green / 255, blue / 255 ]; | ||
for( var i = 0; i < c.length; ++i ) | ||
{ | ||
if( c[ i ] <= 0.03928 ) | ||
{ | ||
c[ i ] = c[ i ] / 12.92; | ||
} else | ||
{ | ||
c[ i ] = Math.pow( ( c[ i ] + 0.055 ) / 1.055, 2.4 ); | ||
} | ||
} | ||
var l = 0.2126 * c[ 0 ] + 0.7152 * c[ 1 ] + 0.0722 * c[ 2 ]; | ||
return l > 0.179 ? "#000000" : "#ffffff"; | ||
} | ||
|
||
function getOtherColours() | ||
{ | ||
function addColour( colour ) | ||
{ | ||
if( colour !== undefined ) | ||
{ | ||
colours.push( colour ); | ||
} | ||
} | ||
|
||
var colours = []; | ||
|
||
var config = vscode.workspace.getConfiguration( 'todo-tree.highlights' ); | ||
var customHighlight = config.get( 'customHighlight' ); | ||
|
||
addColour( config.get( 'defaultHighlight' ).foreground ); | ||
addColour( config.get( 'defaultHighlight' ).background ); | ||
Object.keys( customHighlight ).map( function( tag ) | ||
{ | ||
addColour( customHighlight[ tag ].foreground ); | ||
addColour( customHighlight[ tag ].background ); | ||
} ); | ||
|
||
return colours; | ||
} | ||
|
||
function refreshComplementaryColours() | ||
{ | ||
complementaryColours = {}; | ||
|
||
Object.keys( defaultLightColours ).forEach( function( colour ) | ||
{ | ||
complementaryColours[ defaultLightColours[ colour ] ] = complementaryColour( defaultLightColours[ colour ] ); | ||
} ); | ||
Object.keys( defaultDarkColours ).forEach( function( colour ) | ||
{ | ||
complementaryColours[ defaultDarkColours[ colour ] ] = complementaryColour( defaultDarkColours[ colour ] ); | ||
} ); | ||
|
||
var otherColours = getOtherColours(); | ||
|
||
otherColours.forEach( function( colour ) | ||
{ | ||
if( utils.isHexColour( colour ) ) | ||
{ | ||
complementaryColours[ colour ] = complementaryColour( colour ); | ||
} | ||
} ); | ||
} | ||
|
||
module.exports.getColourList = getColourList; | ||
module.exports.refreshComplementaryColours = refreshComplementaryColours; | ||
module.exports.complementaryColours = complementaryColours; | ||
module.exports.defaultLightColours = defaultLightColours; | ||
module.exports.defaultDarkColours = defaultDarkColours; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.