Skip to content

Commit

Permalink
AsyncDialog: set_storyfile_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Mar 17, 2024
1 parent 8c543b8 commit 20366f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/dialog/common/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type AutosaveData = {
}

export interface DialogDirectories {
storyfile: string
temp: string
working: string
}
Expand All @@ -42,6 +43,8 @@ export interface AsyncDialog {
prompt(extension: string, save: boolean): Promise<string | null>
/** Read a file */
read(path: string): Promise<Uint8Array | null>
/** Set storyfile directory and return directories */
set_storyfile_dir(path: string): DialogDirectories
/** Write a file */
write(path: string, data: Uint8Array): void
}
Expand Down
21 changes: 16 additions & 5 deletions src/dialog/node/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ import {get_stdio, HackableReadline} from '../../glkote/cheap/stdio.js'

export class CheapAsyncDialog implements AsyncDialog {
'async' = true as const
private dirs: DialogDirectories
private rl: HackableReadline
private stdout: MuteStream

constructor() {
const cwd = process.cwd()
this.dirs = {
storyfile: cwd,
temp: os.tmpdir(),
working: cwd,
}

const cheap_stdio = get_stdio()
this.rl = cheap_stdio.rl
this.stdout = cheap_stdio.stdout
Expand All @@ -49,11 +57,8 @@ export class CheapAsyncDialog implements AsyncDialog {
}
}

get_dirs(): DialogDirectories {
return {
temp: os.tmpdir(),
working: process.cwd(),
}
get_dirs() {
return this.dirs
}

prompt(extension: string, _save: boolean): Promise<string | null> {
Expand All @@ -74,6 +79,12 @@ export class CheapAsyncDialog implements AsyncDialog {
}
}

set_storyfile_dir(path: string) {
this.dirs.storyfile = path
this.dirs.working = path
return this.dirs
}

write(path: string, data: Uint8Array) {
fs.writeFileSync(path, data, {flush: true})
}
Expand Down

0 comments on commit 20366f0

Please sign in to comment.