feat: change to use Zsh

* show message from server response
* send output and error to server
This commit is contained in:
wancat committed 2023-08-08 20:38:27 +08:00
1 parent 0153eae673
commit 6204bd0b17
10 files changed
+96 -104

No files matched your search

+42 -14
View File
@@ -1,5 +1,10 @@
/* eslint-disable no-restricted-syntax */
const fs = require('fs').promises
const { exit } = require('process')
const readline = require('readline')
const RETURN_SYMBOL = '\u21B5'
process.stdin.setRawMode(true)
const rl = readline.createInterface({
@@ -8,13 +13,6 @@ const rl = readline.createInterface({
terminal: false,
})
async function printResponses(responses, delay = 100) {
for (const response of responses) {
await printResponse(response, delay)
}
rl.close()
}
function waitForEnter() {
return new Promise((resolve) => {
rl.once('line', resolve)
@@ -35,18 +33,48 @@ function printResponse(response, delay) {
waitForEnter().then(() => {
clearInterval(timer)
process.stdout.write(response.slice(i) + '\n')
process.stdout.write(response.slice(i))
process.stdout.write('\n')
resolve()
})
})
}
async function request() {
const { API_ENDPOINT, TOKEN, PWD, COMMAND, OUTPUT, EXIT_CODE } = process.env
async function printResponses(responses, delay = 100) {
for (const response of responses) {
// eslint-disable-next-line no-await-in-loop
await printResponse(response + RETURN_SYMBOL, delay)
}
rl.close()
}
async function readOrNone(file) {
try {
return await fs.readFile(file, 'utf8')
} catch (err) {
return ''
}
}
async function main() {
const {
API_ENDPOINT,
TOKEN,
PWD,
CMD_NAME,
CMD_OUTPUT_FILE,
CMD_ERROR_FILE,
CMD_EXIT_CODE,
} = process.env
if (!CMD_NAME) exit(0)
const output = await readOrNone(CMD_OUTPUT_FILE)
const error = await readOrNone(CMD_ERROR_FILE)
const payload = {
command: COMMAND,
output: OUTPUT,
exit_code: EXIT_CODE,
command: CMD_NAME,
output,
error,
exit_code: CMD_EXIT_CODE,
token: TOKEN,
pwd: PWD,
}
@@ -67,4 +95,4 @@ async function request() {
}
}
request()
main()