xP: improve paging

This commit is contained in:
Přemysl Eric Janouch 2022-09-21 07:32:18 +02:00
parent 5a7f2d16df
commit 414859d309
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 42 additions and 18 deletions

View File

@ -53,8 +53,31 @@ body {
bottom: -1px; bottom: -1px;
background: #ccc; background: #ccc;
} }
.toolbar {
display: flex;
align-items: baseline;
gap: .3em;
}
button { button {
font: inherit; font: inherit;
background: transparent;
border: 1px solid transparent;
}
button:focus {
border: 1px dashed #000;
}
button:hover {
border-left: 1px solid #fff;
border-top: 1px solid #fff;
border-right: 1px solid #888;
border-bottom: 1px solid #888;
}
button:hover:active {
border-left: 1px solid #888;
border-top: 1px solid #888;
border-right: 1px solid #fff;
border-bottom: 1px solid #fff;
} }
.middle { .middle {

View File

@ -199,6 +199,7 @@ function bufferToggleUnimportant(name) {
} }
function bufferToggleLog() { function bufferToggleLog() {
// TODO: Try to restore the previous scroll offset.
if (bufferLog) { if (bufferLog) {
setTimeout(() => setTimeout(() =>
document.getElementById('input')?.focus()) document.getElementById('input')?.focus())
@ -347,6 +348,7 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => {
let visible = document.visibilityState !== 'hidden' && let visible = document.visibilityState !== 'hidden' &&
bufferLog === undefined && bufferLog === undefined &&
bufferAutoscroll &&
(e.bufferName == bufferCurrent || e.leakToActive) (e.bufferName == bufferCurrent || e.leakToActive)
b.lines.push({...line}) b.lines.push({...line})
if (!(visible || e.leakToActive) || if (!(visible || e.leakToActive) ||
@ -427,21 +429,6 @@ let linkRE = [
/[^\[\](){}<>"'\s,.:]/, /[^\[\](){}<>"'\s,.:]/,
].map(r => r.source).join('') ].map(r => r.source).join('')
let Toolbar = {
toggleAutoscroll: () => {
bufferAutoscroll = !bufferAutoscroll
},
view: vnode => {
return m('.toolbar', {}, [
m('button', {onclick: Toolbar.toggleAutoscroll},
bufferAutoscroll ? 'Scroll lock' : 'Scroll unlock'),
m('button', {onclick: event => bufferToggleLog()},
bufferLog === undefined ? 'Show log' : 'Hide log'),
])
},
}
let BufferList = { let BufferList = {
view: vnode => { view: vnode => {
let highlighted = false let highlighted = false
@ -624,7 +611,11 @@ let Buffer = {
let dateMark = new Date().toLocaleDateString() let dateMark = new Date().toLocaleDateString()
if (dateMark !== lastDateMark && lastDateMark !== undefined) if (dateMark !== lastDateMark && lastDateMark !== undefined)
lines.push(m('.date', {}, dateMark)) lines.push(m('.date', {}, dateMark))
return m('.buffer', {}, lines) return m('.buffer', {onscroll: event => {
const dom = event.target
bufferAutoscroll =
dom.scrollTop + dom.clientHeight + 0.5 >= dom.scrollHeight
}}, lines)
}, },
} }
@ -678,6 +669,16 @@ let BufferContainer = {
}, },
} }
let Toolbar = {
view: vnode => {
return m('.toolbar', {}, [
bufferLog === undefined && !bufferAutoscroll ? '⇩' : undefined,
m('button', {onclick: event => bufferToggleLog()},
bufferLog === undefined ? 'Log' : 'Hide log'),
])
},
}
let Status = { let Status = {
view: vnode => { view: vnode => {
let b = buffers.get(bufferCurrent) let b = buffers.get(bufferCurrent)
@ -687,7 +688,7 @@ let Status = {
let status = `${bufferCurrent}` let status = `${bufferCurrent}`
if (b.hideUnimportant) if (b.hideUnimportant)
status += `<H>` status += `<H>`
return m('.status', {}, status) return m('.status', {}, [status, m(Toolbar)])
}, },
} }
@ -944,7 +945,7 @@ let Main = {
return m('.xP', {}, [ return m('.xP', {}, [
overlay, overlay,
m('.title', {}, [`xP`, m(Toolbar)]), m('.title', {}, `xP`),
m('.middle', {}, [m(BufferList), m(BufferContainer)]), m('.middle', {}, [m(BufferList), m(BufferContainer)]),
m(Status), m(Status),
m('.input', {}, [m(Prompt), m(Input)]), m('.input', {}, [m(Prompt), m(Input)]),