66import { createProgram , PROJECTION_MATRIX , throwIfFalsy } from './WebglUtils' ;
77import { WebglCharAtlas } from './atlas/WebglCharAtlas' ;
88import { IWebGL2RenderingContext , IWebGLVertexArrayObject , IRenderModel , IRasterizedGlyph } from './Types' ;
9- import { INDICIES_PER_CELL } from './WebglRenderer' ;
10- import { COMBINED_CHAR_BIT_MASK } from './RenderModel' ;
9+ import { COMBINED_CHAR_BIT_MASK , RENDER_MODEL_INDICIES_PER_CELL , RENDER_MODEL_FG_OFFSET } from './RenderModel' ;
1110import { fill } from 'common/TypedArrayUtils' ;
1211import { slice } from './TypedArray' ;
13- import { NULL_CELL_CODE , WHITESPACE_CELL_CODE } from 'common/buffer/Constants' ;
14- import { getLuminance } from './ColorUtils' ;
12+ import { NULL_CELL_CODE , WHITESPACE_CELL_CODE , Attributes } from 'common/buffer/Constants' ;
1513import { Terminal , IBufferLine } from 'xterm' ;
1614import { IColorSet } from 'browser/Types' ;
1715import { IRenderDimensions } from 'browser/renderer/Types' ;
@@ -169,11 +167,11 @@ export class GlyphRenderer {
169167return this . _atlas ?this . _atlas . beginFrame ( ) :true ;
170168}
171169
172- public updateCell ( x :number , y :number , code :number , attr : number , bg :number , fg :number , chars :string ) :void {
173- this . _updateCell ( this . _vertices . attributes , x , y , code , attr , bg , fg , chars ) ;
170+ public updateCell ( x :number , y :number , code :number , bg :number , fg :number , chars :string ) :void {
171+ this . _updateCell ( this . _vertices . attributes , x , y , code , bg , fg , chars ) ;
174172}
175173
176- private _updateCell ( array :Float32Array , x :number , y :number , code :number | undefined , attr : number , bg :number , fg :number , chars ?:string ) :void {
174+ private _updateCell ( array :Float32Array , x :number , y :number , code :number | undefined , bg :number , fg :number , chars ?:string ) :void {
177175const terminal = this . _terminal ;
178176
179177const i = ( y * terminal . cols + x ) * INDICES_PER_CELL ;
@@ -189,9 +187,9 @@ export class GlyphRenderer {
189187throw new Error ( 'atlas must be set before updating cell' ) ;
190188}
191189if ( chars && chars . length > 1 ) {
192- rasterizedGlyph = this . _atlas . getRasterizedGlyphCombinedChar ( chars , attr , bg , fg ) ;
190+ rasterizedGlyph = this . _atlas . getRasterizedGlyphCombinedChar ( chars , bg , fg ) ;
193191} else {
194- rasterizedGlyph = this . _atlas . getRasterizedGlyph ( code , attr , bg , fg ) ;
192+ rasterizedGlyph = this . _atlas . getRasterizedGlyph ( code , bg , fg ) ;
195193}
196194
197195// Fill empty if no glyph was found
@@ -220,58 +218,51 @@ export class GlyphRenderer {
220218
221219this . _vertices . selectionAttributes = slice ( this . _vertices . attributes , 0 ) ;
222220
223- // TODO: Make fg and bg configurable, currently since the buffer doesn't
224- // support truecolor the char atlas cannot store it.
225- const lumi = getLuminance ( this . _colors . background ) ;
226- const fg = lumi > 0.5 ?7 :0 ;
227- const bg = lumi > 0.5 ?0 :7 ;
221+ const bg = ( this . _colors . selectionOpaque . rgba >>> 8 ) | Attributes . CM_RGB ;
228222
229223if ( columnSelectMode ) {
230224const startCol = model . selection . startCol ;
231225const width = model . selection . endCol - startCol ;
232226const height = model . selection . viewportCappedEndRow - model . selection . viewportCappedStartRow + 1 ;
233227for ( let y = model . selection . viewportCappedStartRow ; y < model . selection . viewportCappedStartRow + height ; y ++ ) {
234- this . _updateSelectionRange ( startCol , startCol + width , y , model , bg , fg ) ;
228+ this . _updateSelectionRange ( startCol , startCol + width , y , model , bg ) ;
235229}
236230} else {
237231// Draw first row
238232const startCol = model . selection . viewportStartRow === model . selection . viewportCappedStartRow ?model . selection . startCol :0 ;
239233const startRowEndCol = model . selection . viewportCappedStartRow === model . selection . viewportCappedEndRow ?model . selection . endCol :terminal . cols ;
240- this . _updateSelectionRange ( startCol , startRowEndCol , model . selection . viewportCappedStartRow , model , bg , fg ) ;
234+ this . _updateSelectionRange ( startCol , startRowEndCol , model . selection . viewportCappedStartRow , model , bg ) ;
241235
242236// Draw middle rows
243237const middleRowsCount = Math . max ( model . selection . viewportCappedEndRow - model . selection . viewportCappedStartRow - 1 , 0 ) ;
244238for ( let y = model . selection . viewportCappedStartRow + 1 ; y <= model . selection . viewportCappedStartRow + middleRowsCount ; y ++ ) {
245- this . _updateSelectionRange ( 0 , startRowEndCol , y , model , bg , fg ) ;
239+ this . _updateSelectionRange ( 0 , startRowEndCol , y , model , bg ) ;
246240}
247241
248242// Draw final row
249243if ( model . selection . viewportCappedStartRow !== model . selection . viewportCappedEndRow ) {
250244// Only draw viewportEndRow if it's not the same as viewportStartRow
251245const endCol = model . selection . viewportEndRow === model . selection . viewportCappedEndRow ?model . selection . endCol :terminal . cols ;
252- this . _updateSelectionRange ( 0 , endCol , model . selection . viewportCappedEndRow , model , bg , fg ) ;
246+ this . _updateSelectionRange ( 0 , endCol , model . selection . viewportCappedEndRow , model , bg ) ;
253247}
254248}
255249}
256250
257- private _updateSelectionRange ( startCol :number , endCol :number , y :number , model :IRenderModel , bg :number , fg : number ) :void {
251+ private _updateSelectionRange ( startCol :number , endCol :number , y :number , model :IRenderModel , bg :number ) :void {
258252const terminal = this . _terminal ;
259253const row = y + terminal . buffer . viewportY ;
260254let line :IBufferLine | undefined ;
261255for ( let x = startCol ; x < endCol ; x ++ ) {
262- const offset = ( y * this . _terminal . cols + x ) * INDICIES_PER_CELL ;
263- // Because the cache uses attr as a lookup key it needs to contain the selection colors as well
264- let attr = model . cells [ offset + 1 ] ;
265- attr = attr & ~ 0x3ffff | bg << 9 | fg ;
256+ const offset = ( y * this . _terminal . cols + x ) * RENDER_MODEL_INDICIES_PER_CELL ;
266257const code = model . cells [ offset ] ;
267258if ( code & COMBINED_CHAR_BIT_MASK ) {
268259if ( ! line ) {
269260line = terminal . buffer . getLine ( row ) ;
270261}
271262const chars = line ! . getCell ( x ) ! . char ;
272- this . _updateCell ( this . _vertices . selectionAttributes , x , y , model . cells [ offset ] , attr , bg , fg , chars ) ;
263+ this . _updateCell ( this . _vertices . selectionAttributes , x , y , model . cells [ offset ] , bg , model . cells [ offset + RENDER_MODEL_FG_OFFSET ] , chars ) ;
273264} else {
274- this . _updateCell ( this . _vertices . selectionAttributes , x , y , model . cells [ offset ] , attr , bg , fg ) ;
265+ this . _updateCell ( this . _vertices . selectionAttributes , x , y , model . cells [ offset ] , bg , model . cells [ offset + RENDER_MODEL_FG_OFFSET ] ) ;
275266}
276267}
277268}