Skip to content

Commit

Permalink
feat: handle ZX_REPL_HISTORY envvar (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Jan 7, 2025
1 parent 55d13eb commit 53718a7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { inspect } from 'node:util'
import { ProcessOutput, defaults } from './core.js'
import { chalk } from './vendor-core.js'

const HISTORY = path.join(os.homedir(), '.zx_repl_history')
const HISTORY =
process.env.ZX_REPL_HISTORY ?? path.join(os.homedir(), '.zx_repl_history')

export async function startRepl(history = HISTORY) {
defaults.verbose = false
Expand All @@ -28,10 +29,9 @@ export async function startRepl(history = HISTORY) {
useGlobal: true,
preview: false,
writer(output: any) {
if (output instanceof ProcessOutput) {
return output.toString().replace(/\n$/, '')
}
return inspect(output, { colors: true })
return output instanceof ProcessOutput
? output.toString().replace(/\n$/, '')
: inspect(output, { colors: true })
},
})
r.setupHistory(history, () => {})
Expand Down

0 comments on commit 53718a7

Please sign in to comment.