mirror of
https://github.com/He4eT/cheap-glkote.git
synced 2026-05-05 00:47:28 +00:00
stdio: Add basic grid windows support
This commit is contained in:
parent
38e8e34ba8
commit
b51dc35e75
1 changed files with 39 additions and 11 deletions
46
bin/stdio.js
46
bin/stdio.js
|
|
@ -15,6 +15,7 @@ const rl = readline.createInterface({
|
||||||
prompt: ''
|
prompt: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let currentWindowId = null
|
||||||
let currentWindow = null
|
let currentWindow = null
|
||||||
let currentInputType = null
|
let currentInputType = null
|
||||||
|
|
||||||
|
|
@ -30,16 +31,22 @@ const onInit = () => {
|
||||||
}
|
}
|
||||||
readline.emitKeypressEvents(stdin)
|
readline.emitKeypressEvents(stdin)
|
||||||
rl.resume()
|
rl.resume()
|
||||||
|
clearScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateWindows = windows => {
|
const onUpdateWindows = windows => {
|
||||||
currentWindow = windows
|
currentWindow = currentWindowId
|
||||||
|
? windows
|
||||||
|
.find(x => x.id === currentWindowId)
|
||||||
|
: windows
|
||||||
.filter(x => x.type === 'buffer')
|
.filter(x => x.type === 'buffer')
|
||||||
.slice(-1)[0]
|
.slice(-1)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateInputs = data => {
|
const onUpdateInputs = data => {
|
||||||
const { type } = data[0]
|
const { id, type } = data[0]
|
||||||
|
|
||||||
|
currentWindowId = id
|
||||||
|
|
||||||
if (['char', 'line'].includes(type)) {
|
if (['char', 'line'].includes(type)) {
|
||||||
detach_handlers()
|
detach_handlers()
|
||||||
|
|
@ -47,14 +54,12 @@ const onUpdateInputs = data => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateContent = allMessages => {
|
const clearScreen = () => {
|
||||||
detach_handlers()
|
stdout.write('\u001B[2J\u001B[0;0f')
|
||||||
|
}
|
||||||
|
|
||||||
const messages = allMessages.filter(
|
const drawBuffer = messages => {
|
||||||
content => content.id === currentWindow.id
|
messages.text.forEach(({ append, content }) => {
|
||||||
)[0]
|
|
||||||
|
|
||||||
return messages.text.forEach(({ append, content }) => {
|
|
||||||
if (!append) {
|
if (!append) {
|
||||||
stdout.write('\n')
|
stdout.write('\n')
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +84,29 @@ const onUpdateContent = allMessages => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const drawGrid = messages => {
|
||||||
|
clearScreen()
|
||||||
|
messages.lines
|
||||||
|
.map(x => x.content)
|
||||||
|
.map(([x]) => x)
|
||||||
|
.map(({text}) => text)
|
||||||
|
.map(x => x.trim())
|
||||||
|
.forEach(x => stdout.write(`${x}\n`))
|
||||||
|
}
|
||||||
|
|
||||||
|
const onUpdateContent = allMessages => {
|
||||||
|
detach_handlers()
|
||||||
|
|
||||||
|
const messages = allMessages.find(
|
||||||
|
content => content.id === currentWindow.id
|
||||||
|
)
|
||||||
|
|
||||||
|
;({
|
||||||
|
'buffer': drawBuffer,
|
||||||
|
'grid': drawGrid
|
||||||
|
})[currentWindow.type](messages)
|
||||||
|
}
|
||||||
|
|
||||||
const onDisable = disable => {
|
const onDisable = disable => {
|
||||||
if (disable) detach_handlers()
|
if (disable) detach_handlers()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue