-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutil.ts
64 lines (57 loc) · 1.27 KB
/
util.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Colors, writeAllSync } from "./deps.ts";
// Terminal escape sequences
const ESC = "\x1b[";
/**
* The colors to be used with the Kia spinner
*/
export type Color =
| "black"
| "red"
| "green"
| "yellow"
| "blue"
| "magenta"
| "cyan"
| "white"
| "gray";
/**
* Converts the Kia color type to the Deno color functions
* @param color The color string
*/
export function colorise(color: Color) {
return Colors[color];
}
/**
* Overwrites text on the current line
* @param encoder A TextEncoder object
* @param text The text to be written
*/
export function writeLine(
writer: Deno.WriterSync,
encoder: TextEncoder,
text: string,
indent?: number,
) {
writeAllSync(
writer,
encoder.encode(`\r${indent ? ESC + indent + "C" : ""}${text}`),
);
}
/**
* Clears the line and performs a carriage return
*/
export function clearLine(writer: Deno.WriterSync, encoder: TextEncoder) {
writeAllSync(writer, encoder.encode(ESC + "2K\r"));
}
/**
* Hides the terminal cursor
*/
export function hideCursor(writer: Deno.WriterSync, encoder: TextEncoder) {
writeAllSync(writer, encoder.encode(ESC + "?25l"));
}
/**
* Shows the terminal cursor
*/
export function showCursor(writer: Deno.WriterSync, encoder: TextEncoder) {
writeAllSync(writer, encoder.encode(ESC + "?25h"));
}