mirror of
https://github.com/He4eT/cheap-glkote.git
synced 2026-05-05 00:47:28 +00:00
Remove the restriction for number of windows
This commit is contained in:
parent
5c23d809c1
commit
30f79c60b4
3 changed files with 38 additions and 37 deletions
46
bin/stdio.js
46
bin/stdio.js
|
|
@ -15,6 +15,8 @@ const rl = readline.createInterface({
|
||||||
prompt: ''
|
prompt: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let currentWindow = null
|
||||||
|
|
||||||
let send = _ => _
|
let send = _ => _
|
||||||
|
|
||||||
const setSend = fn => {
|
const setSend = fn => {
|
||||||
|
|
@ -29,8 +31,24 @@ const onInit = () => {
|
||||||
rl.resume()
|
rl.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateContent = messages =>
|
const onUpdateWindows = windows => {
|
||||||
messages.text.forEach(({ append, content }) => {
|
currentWindow = windows
|
||||||
|
.filter(x => x.type === 'buffer')
|
||||||
|
.slice(-1)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
const onUpdateInputs = type => {
|
||||||
|
type
|
||||||
|
? attach_handlers(type)
|
||||||
|
: detach_handlers()
|
||||||
|
}
|
||||||
|
|
||||||
|
const onUpdateContent = allMessages => {
|
||||||
|
const messages = allMessages.filter(
|
||||||
|
content => content.id === currentWindow.id
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
return messages.text.forEach(({ append, content }) => {
|
||||||
if (!append) {
|
if (!append) {
|
||||||
stdout.write('\n')
|
stdout.write('\n')
|
||||||
}
|
}
|
||||||
|
|
@ -53,17 +71,6 @@ const onUpdateContent = messages =>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const onUpdateInputs = type => {
|
|
||||||
type
|
|
||||||
? attach_handlers(type)
|
|
||||||
: detach_handlers()
|
|
||||||
}
|
|
||||||
|
|
||||||
const onExit = () => {
|
|
||||||
detach_handlers()
|
|
||||||
rl.close()
|
|
||||||
stdout.write('\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDisable = disable =>
|
const onDisable = disable =>
|
||||||
|
|
@ -71,6 +78,12 @@ const onDisable = disable =>
|
||||||
? detach_handlers()
|
? detach_handlers()
|
||||||
: attach_handlers()
|
: attach_handlers()
|
||||||
|
|
||||||
|
const onExit = () => {
|
||||||
|
detach_handlers()
|
||||||
|
rl.close()
|
||||||
|
stdout.write('\n')
|
||||||
|
}
|
||||||
|
|
||||||
const onFileNameRequest = (tosave, usage, gameid, callback) => {
|
const onFileNameRequest = (tosave, usage, gameid, callback) => {
|
||||||
stdout.write('\n')
|
stdout.write('\n')
|
||||||
rl.question(
|
rl.question(
|
||||||
|
|
@ -104,7 +117,7 @@ const handle_char_input = (str, key) => {
|
||||||
str ||
|
str ||
|
||||||
key.name.replace(/f(\d+)/, 'func$1')
|
key.name.replace(/f(\d+)/, 'func$1')
|
||||||
|
|
||||||
send(res)
|
send(res, currentWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
const attach_handlers = type => {
|
const attach_handlers = type => {
|
||||||
|
|
@ -129,14 +142,15 @@ const handle_line_input = line => {
|
||||||
}
|
}
|
||||||
detach_handlers()
|
detach_handlers()
|
||||||
|
|
||||||
send(line)
|
send(line, currentWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.handlers = {
|
module.exports.handlers = {
|
||||||
onInit,
|
onInit,
|
||||||
|
onUpdateWindows,
|
||||||
|
onUpdateInputs,
|
||||||
onUpdateContent,
|
onUpdateContent,
|
||||||
onDisable,
|
onDisable,
|
||||||
onUpdateInputs,
|
|
||||||
onFileNameRequest,
|
onFileNameRequest,
|
||||||
onFileRead,
|
onFileRead,
|
||||||
onFileWrite,
|
onFileWrite,
|
||||||
|
|
|
||||||
|
|
@ -8,28 +8,20 @@ class CheapGlkOte extends GlkOte {
|
||||||
constructor(handlers, loggers) {
|
constructor(handlers, loggers) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.window = null
|
|
||||||
this.current_input_type = null
|
this.current_input_type = null
|
||||||
|
|
||||||
this.handlers = handlers
|
this.handlers = handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
sendFn(message) {
|
sendFn(message, window) {
|
||||||
this.send_response(
|
this.send_response(
|
||||||
this.current_input_type,
|
this.current_input_type,
|
||||||
this.window,
|
window,
|
||||||
message)
|
message)
|
||||||
this.current_input_type = null
|
this.current_input_type = null
|
||||||
}
|
}
|
||||||
|
|
||||||
init(iface) {
|
init(iface) {
|
||||||
/* Only one window can be opened */
|
|
||||||
const glk_window_open = iface.Glk.glk_window_open
|
|
||||||
iface.Glk.glk_window_open = (splitwin, ...args) =>
|
|
||||||
splitwin
|
|
||||||
? null
|
|
||||||
: glk_window_open(splitwin, ...args)
|
|
||||||
|
|
||||||
this.handlers.onInit()
|
this.handlers.onInit()
|
||||||
super.init(iface)
|
super.init(iface)
|
||||||
}
|
}
|
||||||
|
|
@ -62,11 +54,7 @@ class CheapGlkOte extends GlkOte {
|
||||||
}
|
}
|
||||||
|
|
||||||
update_content(messages) {
|
update_content(messages) {
|
||||||
const filtered = messages.filter(
|
this.handlers.onUpdateContent(messages)
|
||||||
content => content.id === this.window.id
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
this.handlers.onUpdateContent(filtered)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit() {
|
exit() {
|
||||||
|
|
@ -86,12 +74,10 @@ class CheapGlkOte extends GlkOte {
|
||||||
this.handlers.onDisable(disable)
|
this.handlers.onDisable(disable)
|
||||||
}
|
}
|
||||||
|
|
||||||
update_windows(data) {
|
update_windows(windows) {
|
||||||
data.forEach(win => {
|
if (windows.length) {
|
||||||
if (win.type === 'buffer') {
|
this.handlers.onUpdateWindows(windows)
|
||||||
this.window = win
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log(message) {
|
log(message) {
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ const noop = () => void null
|
||||||
|
|
||||||
const noopHandlers = [
|
const noopHandlers = [
|
||||||
'onInit',
|
'onInit',
|
||||||
|
'onUpdateWindows',
|
||||||
|
'onUpdateInputs',
|
||||||
'onUpdateContent',
|
'onUpdateContent',
|
||||||
'onDisable',
|
'onDisable',
|
||||||
'onUpdateInputs',
|
|
||||||
'onFileNameRequest',
|
'onFileNameRequest',
|
||||||
'onFileRead',
|
'onFileRead',
|
||||||
'onFileWrite',
|
'onFileWrite',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue