( screen: Screen, x: number, y: number, line: string, styleId: number, )
| 1049 | * Returns the exclusive end column after the written content. |
| 1050 | */ |
| 1051 | export function writePlainAsciiLineAt( |
| 1052 | screen: Screen, |
| 1053 | x: number, |
| 1054 | y: number, |
| 1055 | line: string, |
| 1056 | styleId: number, |
| 1057 | ): number { |
| 1058 | if (y < 0 || y >= screen.height || line.length === 0 || x >= screen.width) { |
| 1059 | return x |
| 1060 | } |
| 1061 | |
| 1062 | let sourceIndex = 0 |
| 1063 | let startX = x |
| 1064 | if (startX < 0) { |
| 1065 | sourceIndex = -startX |
| 1066 | startX = 0 |
| 1067 | } |
| 1068 | |
| 1069 | const available = screen.width - startX |
| 1070 | const length = Math.min(line.length - sourceIndex, available) |
| 1071 | if (length <= 0) { |
| 1072 | return x |
| 1073 | } |
| 1074 | |
| 1075 | const cells = screen.cells |
| 1076 | const packedWord = packWord1(styleId, 0, CellWidth.Narrow) |
| 1077 | let minAffectedX = startX |
| 1078 | let maxAffectedX = startX + length - 1 |
| 1079 | const rowBase = y * screen.width |
| 1080 | |
| 1081 | for (let i = 0; i < length; i += 1) { |
| 1082 | const screenX = startX + i |
| 1083 | const ci = (rowBase + screenX) << 1 |
| 1084 | const prevWidth = cells[ci + 1]! & WIDTH_MASK |
| 1085 | |
| 1086 | if (prevWidth === CellWidth.Wide) { |
| 1087 | const spacerX = screenX + 1 |
| 1088 | if (spacerX < screen.width) { |
| 1089 | const spacerCI = ci + 2 |
| 1090 | if ((cells[spacerCI + 1]! & WIDTH_MASK) === CellWidth.SpacerTail) { |
| 1091 | cells[spacerCI] = EMPTY_CHAR_INDEX |
| 1092 | cells[spacerCI + 1] = packWord1( |
| 1093 | screen.emptyStyleId, |
| 1094 | 0, |
| 1095 | CellWidth.Narrow, |
| 1096 | ) |
| 1097 | maxAffectedX = Math.max(maxAffectedX, spacerX) |
| 1098 | } |
| 1099 | } |
| 1100 | } else if (prevWidth === CellWidth.SpacerTail && screenX > 0) { |
| 1101 | const wideCI = ci - 2 |
| 1102 | if ((cells[wideCI + 1]! & WIDTH_MASK) === CellWidth.Wide) { |
| 1103 | cells[wideCI] = EMPTY_CHAR_INDEX |
| 1104 | cells[wideCI + 1] = packWord1(screen.emptyStyleId, 0, CellWidth.Narrow) |
| 1105 | minAffectedX = Math.min(minAffectedX, screenX - 1) |
| 1106 | } |
| 1107 | } |
| 1108 |
no test coverage detected