mirror of
https://github.com/He4eT/cheap-glkote.git
synced 2026-05-04 16:37:23 +00:00
Extracting file processing handlers
This commit is contained in:
parent
b367e16941
commit
aa6f7cabf1
3 changed files with 16 additions and 8 deletions
|
|
@ -7,30 +7,28 @@ class FakeDialog {
|
|||
constructor(handlers) {
|
||||
this.streaming = false
|
||||
this.handlers = handlers
|
||||
this.path = 'fake/path'
|
||||
}
|
||||
|
||||
file_ref_exists = ref => false
|
||||
|
||||
file_construct_ref(filename, usage, gameid) {
|
||||
return {
|
||||
filename: [this.path, filename].join('/'),
|
||||
filename,
|
||||
usage: usage || ''
|
||||
}
|
||||
}
|
||||
|
||||
file_read(dirent, israw) {
|
||||
console.log('fake_file_read', dirent, israw)
|
||||
return 'content'
|
||||
return this.handlers.onFileRead(dirent, israw)
|
||||
}
|
||||
|
||||
file_write(dirent, content, israw) {
|
||||
if (content.length === 0) return (void null)
|
||||
console.log('fake_file_write', dirent, israw, content.length)
|
||||
this.handlers.onFileWrite(dirent, content, israw)
|
||||
}
|
||||
|
||||
open(tosave, usage, gameid, callback) {
|
||||
this.handlers.onFileNameRequest(tosave, usage, callback)
|
||||
this.handlers.onFileNameRequest(tosave, usage, gameid, callback)
|
||||
}
|
||||
|
||||
log(message) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ const noopHandlers = [
|
|||
'onDisable',
|
||||
'onUpdateInputs',
|
||||
'onFileNameRequest',
|
||||
'onFileRead',
|
||||
'onFileWrite',
|
||||
'onExit',
|
||||
'setSend'
|
||||
].reduce((acc, x) => ((acc[x] = noop), acc), {})
|
||||
|
|
|
|||
12
src/stdio.js
12
src/stdio.js
|
|
@ -71,15 +71,21 @@ const onDisable = disable =>
|
|||
? detach_handlers()
|
||||
: attach_handlers()
|
||||
|
||||
const onFileNameRequest = (tosave, usage, callback) => {
|
||||
const onFileNameRequest = (tosave, usage, gameid, callback) => {
|
||||
stdout.write('\n')
|
||||
rl.question(
|
||||
'Please enter a file name (without an extension): ',
|
||||
'Please enter a file name: ',
|
||||
filename => callback(filename
|
||||
? { filename, usage }
|
||||
: null))
|
||||
}
|
||||
|
||||
const onFileRead = (dirent, israw) =>
|
||||
void console.log('onFileRead:', dirent)
|
||||
|
||||
const onFileWrite = (dirent, content, israw) =>
|
||||
void console.log('onFileWrite:', dirent, content.length)
|
||||
|
||||
const handle_char_input = (str, key) => {
|
||||
const key_replacements = {
|
||||
'\x7F': 'delete',
|
||||
|
|
@ -132,6 +138,8 @@ module.exports.handlers = {
|
|||
onDisable,
|
||||
onUpdateInputs,
|
||||
onFileNameRequest,
|
||||
onFileRead,
|
||||
onFileWrite,
|
||||
onExit,
|
||||
setSend
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue