initial cli api, some movement on tool selection
This commit is contained in:
30
util/asciiArt.ts
Normal file
30
util/asciiArt.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export async function getAsciiArt(art: string) {
|
||||
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
|
||||
getBearmetalAsciiPath();
|
||||
if (!artFilePath) return art;
|
||||
let artFileText: string;
|
||||
if (artFilePath.startsWith("http")) {
|
||||
artFileText = await fetch(artFilePath).then((res) => res.text());
|
||||
} else {
|
||||
artFileText = await Deno.readTextFile(artFilePath);
|
||||
}
|
||||
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
|
||||
let result = parserRX.exec(artFileText);
|
||||
|
||||
while (result !== null) {
|
||||
const [_, name, artText] = result;
|
||||
if (name === art) return artText;
|
||||
result = parserRX.exec(artFileText);
|
||||
}
|
||||
return art;
|
||||
}
|
||||
|
||||
function getBearmetalAsciiPath() {
|
||||
const filenameRX = /asciiarts?\.txt$/;
|
||||
for (const filename of Deno.readDirSync(".")) {
|
||||
if (filename.isFile && filenameRX.test(filename.name)) {
|
||||
return filename.name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
Reference in New Issue
Block a user