diff options
Diffstat (limited to 'xP')
-rw-r--r-- | xP/public/xP.js | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index c2e0e03..4c740ba 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -137,7 +137,7 @@ let bufferCurrent = undefined let bufferLog = undefined let bufferAutoscroll = true -function resetBufferStats(b) { +function bufferResetStats(b) { b.newMessages = 0 b.newUnimportantMessages = 0 b.highlighted = false @@ -147,6 +147,29 @@ function bufferActivate(name) { rpc.send({command: 'BufferActivate', bufferName: name}) } +function bufferToggleLog() { + if (bufferLog) { + setTimeout(() => + document.getElementById('input')?.focus()) + + bufferLog = undefined + m.redraw() + return + } + + let name = bufferCurrent + rpc.send({ + command: 'BufferLog', + bufferName: name, + }).then(resp => { + if (bufferCurrent !== name) + return + + bufferLog = rpc.base64decode(resp.log) + m.redraw() + }) +} + let connecting = true rpc.connect().then(result => { buffers.clear() @@ -175,7 +198,7 @@ rpc.addEventListener('BufferUpdate', event => { let e = event.detail, b = buffers.get(e.bufferName) if (b === undefined) { buffers.set(e.bufferName, (b = {lines: []})) - resetBufferStats(b) + bufferResetStats(b) } b.hideUnimportant = e.hideUnimportant }) @@ -206,7 +229,7 @@ rpc.addEventListener('BufferRemove', event => { rpc.addEventListener('BufferActivate', event => { let old = buffers.get(bufferCurrent) if (old !== undefined) - resetBufferStats(old) + bufferResetStats(old) bufferLast = bufferCurrent let e = event.detail, b = buffers.get(e.bufferName) @@ -307,26 +330,11 @@ let Toolbar = { bufferAutoscroll = !bufferAutoscroll }, - toggleLog: () => { - if (bufferLog) { - bufferLog = undefined - return - } - - rpc.send({ - command: 'BufferLog', - bufferName: bufferCurrent, - }).then(resp => { - bufferLog = rpc.base64decode(resp.log) - m.redraw() - }) - }, - view: vnode => { return m('.toolbar', {}, [ m('button', {onclick: Toolbar.toggleAutoscroll}, bufferAutoscroll ? 'Scroll lock' : 'Scroll unlock'), - m('button', {onclick: Toolbar.toggleLog}, + m('button', {onclick: event => bufferToggleLog()}, bufferLog === undefined ? 'Show log' : 'Hide log'), ]) }, @@ -500,8 +508,8 @@ let Buffer = { let Log = { oncreate: vnode => { - if (vnode.dom !== undefined) - vnode.dom.scrollTop = vnode.dom.scrollHeight + vnode.dom.scrollTop = vnode.dom.scrollHeight + vnode.dom.focus() }, linkify: text => { @@ -629,6 +637,8 @@ document.addEventListener('keydown', event => { if (event.altKey && event.key == 'Tab') { if (bufferLast !== undefined) bufferActivate(bufferLast) + } else if (event.altKey && event.key == 'h') { + bufferToggleLog() } else if (event.altKey && event.key == 'a') { for (const [name, b] of buffers) if (name !== bufferCurrent && b.newMessages) { |