Skip to content

Commit

Permalink
feat: add a seperator "<---STREAMING END--->" when no consoleClear
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Jun 21, 2024
1 parent 5e1fc1a commit bd8770c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/run-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ function logUpdate(...text: string[]) {
}

logUpdate.dirt = false
logUpdate.clear = () => {
logUpdate.clear = (consoleClear: boolean|undefined) => {
if (logUpdate.dirt) {
logUpdate.dirt = false
_logUpdate.clear()
if (consoleClear) {
_logUpdate.clear()
} else {
console.log(`\n${colors.magenta('<---STREAMING END--->')}\n\n`)
}
}
}

Expand Down Expand Up @@ -153,6 +157,7 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
logUpdate(llmLastContent)
} else {
process.stdout.write(s)
logUpdate.dirt = true
}
}
})
Expand All @@ -163,7 +168,7 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
} catch(error: any) {
if (error.name !== 'AbortError') {throw error}
} finally {
if (!isSilence && options.consoleClear) {logUpdate.clear()}
if (!isSilence) {logUpdate.clear(options.consoleClear)}
}

let result = runtime.result
Expand Down Expand Up @@ -242,7 +247,7 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
const what = error.data?.what ? ':'+error.data.what : ''
input.write(colors.magentaBright(`<${error.name+what}>`))
} finally {
if (!isSilence && options.consoleClear) {logUpdate.clear()}
if (!isSilence) {logUpdate.clear(options.consoleClear)}
}
if (result) {
if (typeof result !== 'string') { result = ux.colorizeJson(result, {pretty: true, theme: options.theme?.json})}
Expand Down

0 comments on commit bd8770c

Please sign in to comment.