This commit is contained in:
parent
46a0314ce6
commit
501f5e10d5
@ -6,10 +6,10 @@ import Ansi, { AnsiColor, Ground } from '../src/common/ansi.ts';
|
||||
// Display table of the 256 type color console escape codes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const addColor = (fore: number | string, back: number | string): string => {
|
||||
const addColor = (fore: string, back: string): string => {
|
||||
let output = '';
|
||||
output += (typeof fore === 'number') ? Ansi.color(fore) : fore;
|
||||
output += (typeof back === 'number') ? Ansi.color(back) : back;
|
||||
output += fore;
|
||||
output += back;
|
||||
|
||||
return output;
|
||||
};
|
||||
@ -20,7 +20,7 @@ const padNum = (num: number): string =>
|
||||
const colorBlock = (
|
||||
start: number,
|
||||
end: number,
|
||||
block: (i: number) => [string | number, string | number],
|
||||
block: (i: number) => [string, string],
|
||||
): string => {
|
||||
let output = '';
|
||||
|
||||
@ -39,16 +39,34 @@ function print16colorTable(): void {
|
||||
let end = start + 8;
|
||||
|
||||
let blocks = [
|
||||
colorBlock(start, end, (i: number) => [i, AnsiColor.BgBlack]),
|
||||
colorBlock(start, end, (i: number) => [i, AnsiColor.BgBrightWhite]),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.textFormat(i), Ansi.color.background.Black],
|
||||
),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.textFormat(i), Ansi.color.background.BrightWhite],
|
||||
),
|
||||
];
|
||||
|
||||
start += 10;
|
||||
end += 10;
|
||||
|
||||
blocks.push(colorBlock(start, end, (i: number) => [AnsiColor.FgBlack, i]));
|
||||
blocks.push(
|
||||
colorBlock(start, end, (i: number) => [AnsiColor.FgBrightWhite, i]),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.color.Black, Ansi.textFormat(i)],
|
||||
),
|
||||
);
|
||||
blocks.push(
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.color.BrightWhite, Ansi.textFormat(i)],
|
||||
),
|
||||
);
|
||||
|
||||
return blocks.join(' '.repeat(5));
|
||||
@ -87,22 +105,26 @@ function print256colorTable(): void {
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.color256(i, Ground.Fore), AnsiColor.BgBlack],
|
||||
(
|
||||
i: number,
|
||||
) => [Ansi.color256(i, Ground.Fore), Ansi.color.background.Black],
|
||||
),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [Ansi.color256(i, Ground.Fore), AnsiColor.BgBrightWhite],
|
||||
(
|
||||
i: number,
|
||||
) => [Ansi.color256(i, Ground.Fore), Ansi.color.background.BrightWhite],
|
||||
),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [AnsiColor.FgBlack, Ansi.color256(i, Ground.Back)],
|
||||
(i: number) => [Ansi.color.Black, Ansi.color256(i, Ground.Back)],
|
||||
),
|
||||
colorBlock(
|
||||
start,
|
||||
end,
|
||||
(i: number) => [AnsiColor.FgBrightWhite, Ansi.color256(i, Ground.Back)],
|
||||
(i: number) => [Ansi.color.BrightWhite, Ansi.color256(i, Ground.Back)],
|
||||
),
|
||||
];
|
||||
|
||||
|
@ -644,12 +644,12 @@ const RowTest = {
|
||||
const normalRow = Row.from('\tFor whom the bell tolls');
|
||||
assertEquivalent(
|
||||
normalRow.find('who', 0, SearchDirection.Forward),
|
||||
Some(8),
|
||||
Some(5),
|
||||
);
|
||||
assertEquals(normalRow.find('foo', 0, SearchDirection.Forward), None);
|
||||
|
||||
const emojiRow = Row.from('\t😺😸😹');
|
||||
assertEquivalent(emojiRow.find('😹', 0, SearchDirection.Forward), Some(6));
|
||||
assertEquivalent(emojiRow.find('😹', 0, SearchDirection.Forward), Some(3));
|
||||
assertEquals(emojiRow.find('🤰🏼', 10, SearchDirection.Forward), None);
|
||||
},
|
||||
'.find backwards': () => {
|
||||
|
@ -98,7 +98,7 @@ export class Document {
|
||||
for (let y = at.y; y >= 0 && y < this.numRows; y += direction) {
|
||||
const maybeMatch = this.#rows[y].find(q, position.x, direction);
|
||||
if (maybeMatch.isSome()) {
|
||||
position.x = this.#rows[y].rxToCx(maybeMatch.unwrap());
|
||||
position.x = maybeMatch.unwrap();
|
||||
return Some(position);
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ export class Row {
|
||||
|
||||
/**
|
||||
* Search the current row for the specified string, and return
|
||||
* the render 'character' index of the start of that match
|
||||
* the 'character' index of the start of that match
|
||||
*/
|
||||
public find(
|
||||
s: string,
|
||||
@ -158,11 +158,11 @@ export class Row {
|
||||
// equal the number of characters. So
|
||||
// searching is fairly easy
|
||||
if (thisStr.length === this.chars.length) {
|
||||
return Some(this.cxToRx(byteIndex));
|
||||
return Some(byteIndex);
|
||||
}
|
||||
|
||||
// Emoji/Extended Unicode-friendly search
|
||||
return Some(this.cxToRx(this.byteIndexToCharIndex(byteIndex)));
|
||||
return Some(this.byteIndexToCharIndex(byteIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -532,7 +532,7 @@ export class Row {
|
||||
|
||||
// Highlight character literals
|
||||
const ch = this.rchars[i];
|
||||
if (ch === SINGLE_QUOTE) {
|
||||
if (ch === SINGLE_QUOTE && this.rIndexOf(SINGLE_QUOTE, i + 1).isSome()) {
|
||||
while (true) {
|
||||
this.hl.push(HighlightType.Character);
|
||||
i += 1;
|
||||
|
Loading…
Reference in New Issue
Block a user