-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_testutil.ts
More file actions
43 lines (42 loc) · 1.06 KB
/
_testutil.ts
File metadata and controls
43 lines (42 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { Denops } from "@denops/std";
import * as fn from "@denops/std/function";
import { collect } from "@denops/std/batch";
import * as iterutil from "@core/iterutil/pipe";
import { range } from "@core/iterutil";
import { pipe } from "@core/pipe";
/**
* Get screen text in the specified range.
*
* > [!WARN]
* > It seems 'screenstring' doesn't work on Vim when `-es` option is specified.
* > So test using this function only works on Neovim.
*/
export async function screentext(
denops: Denops,
row: number,
col: number,
width: number,
height: number,
): Promise<string[]> {
const ps = Array.from(pipe(
range(row, row + height - 1),
iterutil.map((row) =>
pipe(
range(col, col + width - 1),
iterutil.map((col) => [row, col] as const),
)
),
iterutil.flatten,
));
const strings = await collect(
denops,
(denops) => ps.map((p) => fn.screenstring(denops, ...p)),
);
return Array.from(
pipe(
strings,
iterutil.chunked(width),
iterutil.map((line) => line.join("")),
),
);
}