MCPcopy Create free account
hub / github.com/anomalyco/opencode / _diffStyle

Method _diffStyle

packages/app/src/addons/serialize.ts:298–372  ·  view source on GitHub ↗
(cell: IBufferCell, oldCell: IBufferCell)

Source from the content-addressed store, hash-verified

296 }
297
298 private _diffStyle(cell: IBufferCell, oldCell: IBufferCell): number[] {
299 const sgrSeq: number[] = []
300 const fgChanged = !equalFg(cell, oldCell)
301 const bgChanged = !equalBg(cell, oldCell)
302 const flagsChanged = !equalFlags(cell, oldCell)
303
304 if (fgChanged || bgChanged || flagsChanged) {
305 if (this._isAttributeDefault(cell)) {
306 if (!this._isAttributeDefault(oldCell)) {
307 sgrSeq.push(0)
308 }
309 } else {
310 if (flagsChanged) {
311 if (!!cell.isInverse() !== !!oldCell.isInverse()) {
312 sgrSeq.push(cell.isInverse() ? 7 : 27)
313 }
314 if (!!cell.isBold() !== !!oldCell.isBold()) {
315 sgrSeq.push(cell.isBold() ? 1 : 22)
316 }
317 if (!!cell.isUnderline() !== !!oldCell.isUnderline()) {
318 sgrSeq.push(cell.isUnderline() ? 4 : 24)
319 }
320 if (!!cell.isBlink() !== !!oldCell.isBlink()) {
321 sgrSeq.push(cell.isBlink() ? 5 : 25)
322 }
323 if (!!cell.isInvisible() !== !!oldCell.isInvisible()) {
324 sgrSeq.push(cell.isInvisible() ? 8 : 28)
325 }
326 if (!!cell.isItalic() !== !!oldCell.isItalic()) {
327 sgrSeq.push(cell.isItalic() ? 3 : 23)
328 }
329 if (!!cell.isDim() !== !!oldCell.isDim()) {
330 sgrSeq.push(cell.isDim() ? 2 : 22)
331 }
332 if (!!cell.isStrikethrough() !== !!oldCell.isStrikethrough()) {
333 sgrSeq.push(cell.isStrikethrough() ? 9 : 29)
334 }
335 }
336 if (fgChanged) {
337 const color = cell.getFgColor()
338 const mode = cell.getFgColorMode()
339 if (mode === 2 || mode === 3 || mode === -1) {
340 sgrSeq.push(38, 2, (color >>> 16) & 0xff, (color >>> 8) & 0xff, color & 0xff)
341 } else if (mode === 1) {
342 // Palette
343 if (color >= 16) {
344 sgrSeq.push(38, 5, color)
345 } else {
346 sgrSeq.push(color & 8 ? 90 + (color & 7) : 30 + (color & 7))
347 }
348 } else {
349 sgrSeq.push(39)
350 }
351 }
352 if (bgChanged) {
353 const color = cell.getBgColor()
354 const mode = cell.getBgColorMode()
355 if (mode === 2 || mode === 3 || mode === -1) {

Callers 2

_nextCellMethod · 0.95
_serializeStringMethod · 0.95

Calls 15

_isAttributeDefaultMethod · 0.95
equalFgFunction · 0.85
equalBgFunction · 0.85
equalFlagsFunction · 0.85
pushMethod · 0.80
isInverseMethod · 0.80
isBoldMethod · 0.80
isUnderlineMethod · 0.80
isBlinkMethod · 0.80
isInvisibleMethod · 0.80
isItalicMethod · 0.80
isDimMethod · 0.80

Tested by

no test coverage detected