1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { colors } from "@cliffy/ansi/colors";
import { tty } from "@cliffy/ansi/tty";
import { delay } from "@std/async/delay";
const error = colors.bold.red;
const warn = colors.bold.yellow;
const info = colors.bold.blue;
console.log(info("This is an info message!"));
console.log(warn("This is a warning!"));
console.log(error("This is an error message!"));
console.log(error.underline("This is a critical error message!"));
await delay(3000);
tty.cursorLeft.cursorUp(4).eraseDown();
Copy
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
import { Command } from "@cliffy/command";
await new Command()
.name("reverse-proxy")
.description("A simple reverse proxy example cli.")
.version("v1.0.0")
.option("-p, --port <port:number>", "The port number for the local server.", {
default: 8080,
})
.option("--host <hostname>", "The host name for the local server.", {
default: "localhost",
})
.arguments("[domain]")
.action(({ port, host }, domain = "deno.land") => {
console.log(`Listening on http://${host}:${port}`);
Deno.serve({
hostname: host,
port,
}, (req: Request) => {
const url = new URL(req.url);
url.protocol = "https:";
url.hostname = domain;
url.port = "443";
console.log("Proxy request to:", url.href);
return fetch(url.href, {
headers: req.headers,
method: req.method,
body: req.body,
});
});
})
.parse();
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { parseFlags } from "@cliffy/flags";
const { flags } = parseFlags(Deno.args, {
stopEarly: true,
flags: [{
name: "silent",
}, {
name: "port",
type: "number",
default: 8080,
}, {
name: "host",
aliases: ["hostname"],
type: "string",
default: "localhost",
}, {
name: "verbose",
aliases: ["v"],
collect: true,
value: (_, verbose = 0) => ++verbose,
}],
});
console.log("Parsed flags: %O", flags);
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { KeyCode, parse } from "@cliffy/keycode";
while (true) {
const data = new Uint8Array(8);
Deno.stdin.setRaw(true);
const nread = await Deno.stdin.read(data);
Deno.stdin.setRaw(false);
if (nread === null) {
break;
}
const keys: Array<KeyCode> = parse(data.subarray(0, nread));
for (const key of keys) {
if (key.ctrl && key.name === "c") {
console.log("exit");
Deno.exit();
}
console.log("Key pressed: %O", key);
}
}
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { keypress, KeyPressEvent } from "@cliffy/keypress";
const event: KeyPressEvent = await keypress();
console.log("Key pressed: %s", event.key);
for await (const event of keypress()) {
console.log("Key pressed: %s", event.key);
if (event.ctrlKey && event.key === "c") {
console.log("exit");
break;
}
}
keypress().addEventListener("keydown", (event: KeyPressEvent) => {
console.log("Key pressed: %s", event.key);
if (event.ctrlKey && event.key === "c") {
console.log("exit");
keypress().dispose();
}
});
Copy
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
import { Confirm, Input, Number, Secret } from "@cliffy/prompt";
let hostname: string, port: number, password: string;
await main();
async function main() {
hostname = await Input.prompt({
message: "Enter the hostname",
default: hostname ?? "localhost",
});
port = await Number.prompt({
message: "Enter the port number",
default: port ?? 80,
});
password = await Secret.prompt({
message: "Enter your password",
default: password,
});
console.log({ port, hostname, password });
if (!await Confirm.prompt("Is everything correct?")) {
await main();
}
}
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Cell, Table } from "@cliffy/table";
const table = new Table(
[
new Cell("Row 1 & 2 / Column 1").rowSpan(2),
"Row 1 / Column 2",
"Row 1 / Column 3",
],
[new Cell("Row 2 / Column 2 & 3").colSpan(2)],
[
new Cell("Row 3 & 4 / Column 1").rowSpan(2),
"Row 3 / Column 2",
"Row 3 / Column 3",
],
[new Cell("Row 4 / Column 2 & 3").colSpan(2)],
[
"Row 5 / Column 1",
new Cell("Row 5 & 6 / Column 2 & 3").rowSpan(2).colSpan(2),
],
);
table.push(["Row 6 / Column 1"]);
table.border().render();
Copy