gpt4 book ai didi

deno - 使用 Deno 的 CLI REPL

转载 作者:行者123 更新时间:2023-12-03 13:34:12 25 4
gpt4 key购买 nike

我想使用 Deno 构建一个 CLI 应用程序,但是我找不到允许我不断提示用户进行交互的模块,类似于 Node.js 上的 REPL 模块的命令行应用程序

有什么建议么?

最佳答案

您可以使用 std/io构建一个 REPL。

import { readLines } from "https://deno.land/std@v0.52.0/io/bufio.ts";


async function read() {
// Listen to stdin input, once a new line is entered return
for await(const line of readLines(Deno.stdin)) {
console.log('Received', line)
return line;
}
}

console.log('Start typing');
while(true) {
await read()
}

您可以从这里构建、处理每一行、添加命令等等。

关于deno - 使用 Deno 的 CLI REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61945291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com