mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: print hints one by one, fix unexpected breakline
This commit is contained in:
1 parent
fc13e9371c
commit
a9a63ea164
2 files changed
+13
-10
No files matched your search
@@ -3,7 +3,7 @@ const fs = require('fs').promises
|
||||
const { exit } = require('process')
|
||||
const minimist = require('minimist')
|
||||
const axios = require('axios')
|
||||
const { colorize, printResponses } = require('./print.js')
|
||||
const { colorize, printResponses, printHints } = require('./print.js')
|
||||
const discoverFiles = require('./discover.js')
|
||||
|
||||
async function readOrNone(file) {
|
||||
@@ -66,16 +66,14 @@ async function main() {
|
||||
const { responses, hints, end } = res.data
|
||||
if (responses) {
|
||||
await printResponses(responses, 60)
|
||||
await api.post('/commands/completed')
|
||||
}
|
||||
if (hints) {
|
||||
for (const hint of hints) {
|
||||
console.log(colorize(hint, 'yellow'))
|
||||
}
|
||||
await printHints(hints, 60)
|
||||
}
|
||||
if (end) {
|
||||
console.log(colorize('Quest completed!', 'blue'))
|
||||
}
|
||||
await api.post('/commands/completed')
|
||||
} catch (err) {
|
||||
if (err.response) {
|
||||
console.error(err.response.data)
|
||||
|
||||
@@ -52,6 +52,7 @@ function printLine(content, delay, color) {
|
||||
|
||||
waitForEnter().then(() => {
|
||||
clearInterval(timer)
|
||||
if (i >= printContent.length) return
|
||||
process.stdout.write(printContent.slice(i))
|
||||
process.stdout.write('\n')
|
||||
resolve()
|
||||
@@ -68,22 +69,26 @@ async function printResponses(responses, delay = 100) {
|
||||
for (const line of content) {
|
||||
await printLine(line, delay, color || 'cyan')
|
||||
}
|
||||
console.log(colorize('------------------------------', 'green'))
|
||||
console.log()
|
||||
}
|
||||
if (type === 'dialogue') {
|
||||
console.log(colorize(`${speaker}:`, 'green'))
|
||||
for (const line of content) {
|
||||
await printLine(` ${line}`, delay, color || 'cyan')
|
||||
}
|
||||
console.log(colorize('------------------------------', 'green'))
|
||||
console.log()
|
||||
}
|
||||
console.log(colorize('------------------------------', 'green'))
|
||||
console.log()
|
||||
}
|
||||
}
|
||||
|
||||
async function printHints(hints, delay = 100) {
|
||||
for (const hint of hints) {
|
||||
await printLine(hint, delay, 'yellow')
|
||||
}
|
||||
rl.close()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
printResponses,
|
||||
printHints,
|
||||
colorize,
|
||||
}
|
||||
Reference in new issue
Block a user