1- import { types } from "util" ;
2- import * as vscode from "vscode" ;
3- import { LogInfo } from "./model" ;
1+ import * as vscode from "vscode"
2+ import { LogInfo } from "./model"
3+ import { Parser , ColorToHex } from './parser'
44
55const timestampRE = / \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 7 } Z / ;
66
77const timestampDecorationType = vscode . window . createTextEditorDecorationType ( {
88 color : "#99999959"
99} ) ;
1010
11- const background = {
12- "40" : "#0c0c0c" ,
13- "41" : "#e74856" ,
14- "42" : "#16c60c" ,
15- "43" : "#f9f1a5" ,
16- "44" : "#0037da" ,
17- "45" : "#881798" ,
18- "46" : "#3a96dd" ,
19- "47" : "#cccccc" ,
20- "100" : "#767676"
21- } as { [ key : string ] : string } ;
22-
23- const foreground = {
24- "30" : "#0c0c0c" ,
25- "31" : "#e74856" ,
26- "32" : "#16c60c" ,
27- "33" : "#f9f1a5" ,
28- "34" : "#0037da" ,
29- "35" : "#881798" ,
30- "36" : "#3a96dd" ,
31- "37" : "#cccccc" ,
32- "90" : "#767676"
33- } as { [ key : string ] : string } ;
34-
3511export function updateDecorations ( activeEditor : vscode . TextEditor , logInfo : LogInfo ) {
3612 if ( ! activeEditor ) {
3713 return ;
@@ -56,7 +32,6 @@ export function updateDecorations(activeEditor: vscode.TextEditor, logInfo: LogI
5632 [ key : string ] : { type : vscode . TextEditorDecorationType ; ranges : vscode . Range [ ] } ;
5733 } = { } ;
5834
59-
6035 for ( let lineNo = 0 ; lineNo < logInfo . updatedLogLines . length ; lineNo ++ ) {
6136 // .filter() preserves the order of the array
6237 const lineStyles = logInfo . styleFormats . filter ( style => style . line == lineNo )
@@ -67,21 +42,49 @@ export function updateDecorations(activeEditor: vscode.TextEditor, logInfo: LogI
6742 const range = new vscode . Range ( lineNo , pos , lineNo , endPos ) ;
6843 pos = endPos
6944
70- // TODO build key by concatenating styles... or using style hash?
71- const key = `mykey`
72- if ( ! ctypes [ key ] ) {
73- ctypes [ key ] = {
74- type : vscode . window . createTextEditorDecorationType ( {
75- color : style . style ?. fg ,
76- backgroundColor : style . style ?. bg ,
77- fontWeight : style . style ?. bold ? "bold" : "normal" ,
78- fontStyle : style . style ?. italic ? "italic" : "normal" ,
79- textDecoration : style . style ?. underline ? "underline" : ""
80- } ) ,
81- ranges : [ range ]
82- } ;
83- } else {
84- ctypes [ key ] . ranges . push ( range ) ;
45+ if ( style . style ) {
46+ const key = Parser . styleKey ( style . style )
47+ let fgHex = ""
48+ let bgHex = ""
49+
50+ // Convert to hex colors if RGB-formatted, or use lookup for predefined colors
51+ if ( style . style . isFgRGB ) {
52+ const rgbValues = style . style . fg . split ( ',' )
53+ if ( rgbValues . length == 3 ) {
54+ fgHex = "#"
55+ for ( let i = 0 ; i < 3 ; i ++ ) {
56+ fgHex . concat ( parseInt ( rgbValues [ i ] ) . toString ( 16 ) )
57+ }
58+ }
59+ } else {
60+ fgHex = ColorToHex [ style . style . fg ]
61+ }
62+ if ( style . style . isBgRGB ) {
63+ const rgbValues = style . style . bg . split ( ',' )
64+ if ( rgbValues . length == 3 ) {
65+ bgHex = "#"
66+ for ( let i = 0 ; i < 3 ; i ++ ) {
67+ bgHex . concat ( parseInt ( rgbValues [ i ] ) . toString ( 16 ) )
68+ }
69+ }
70+ } else {
71+ bgHex = ColorToHex [ style . style . bg ]
72+ }
73+
74+ if ( ! ctypes [ key ] ) {
75+ ctypes [ key ] = {
76+ type : vscode . window . createTextEditorDecorationType ( {
77+ color : fgHex ,
78+ backgroundColor : bgHex ,
79+ fontWeight : style . style . bold ? "bold" : "normal" ,
80+ fontStyle : style . style . italic ? "italic" : "normal" ,
81+ textDecoration : style . style . underline ? "underline" : ""
82+ } ) ,
83+ ranges : [ range ]
84+ } ;
85+ } else {
86+ ctypes [ key ] . ranges . push ( range ) ;
87+ }
8588 }
8689 }
8790 }
0 commit comments