No replacement chars #
A property that checks whether or not a replacement unicode character (U+FFFD) has been detected. That character is what a terminal shows when a program emits malformed UTF-8. This is one of the default properties for the terminal.
import { always, Formula } from "@antithesishq/bombadil";
import { extract } from "@antithesishq/bombadil/terminal";
function toHex(str: string): string {
var result = "";
for (var i = 0; i < str.length; i++) {
result += str.charCodeAt(i).toString(16);
}
return result;
}
const replacementChars = extract((state) => {
const result = [];
for (let i = 0; i < state.grid.size.rows; i++) {
for (const match of state.grid.rowText(i).matchAll(/\uFFFD/g)) {
result.push({
row: i,
column: match.index,
contents: match[0],
hex: toHex(match[0]),
});
}
}
return result;
});
export const noReplacementChars: Formula = always(
() => (replacementChars.current ?? []).length === 0,
);