autoscroll

This commit is contained in:
Chris Wanstrath 2025-09-20 21:08:43 -07:00
parent 94b64c29b1
commit 6a7f10f8d5
3 changed files with 17 additions and 2 deletions

View File

@ -1,7 +1,7 @@
:root { :root {
--cli-spacing-vertical: 5px; --cli-spacing-vertical: 5px;
--cli-spacing-horizontal: 5px; --cli-spacing-horizontal: 5px;
--cli-margin: 10px 0 0 25px; --cli-margin: 5px 0 0 25px;
--cli-font-size: 20px; --cli-font-size: 20px;
--cli-height: 30px; --cli-height: 30px;
--cli-status-width: 8px; --cli-status-width: 8px;
@ -20,7 +20,7 @@
#command-prompt { #command-prompt {
position: absolute; position: absolute;
top: 10px; top: 5px;
} }
#command-textbox { #command-textbox {
@ -75,11 +75,17 @@
/* The scrollback shows your previous inputs and outputs. */ /* The scrollback shows your previous inputs and outputs. */
#scrollback { #scrollback {
overflow-y: auto;
margin: 0; margin: 0;
padding: 0; padding: 0;
max-height: 95vh;
font-size: var(--cli-font-size); font-size: var(--cli-font-size);
} }
[data-mode="cinema"] #scrollback {
max-height: 505px;
}
#scrollback li { #scrollback li {
list-style: none; list-style: none;
margin: 0; margin: 0;

View File

@ -3,6 +3,7 @@
import { scrollback } from "./dom.js" import { scrollback } from "./dom.js"
import { resize } from "./resize.js" import { resize } from "./resize.js"
import { autoScroll } from "./scrollback.js"
export const commands: string[] = [] export const commands: string[] = []
@ -13,6 +14,7 @@ export const browserCommands: Record<string, () => any> = {
mode: () => { mode: () => {
document.body.dataset.mode = document.body.dataset.mode === "tall" ? "cinema" : "tall" document.body.dataset.mode = document.body.dataset.mode === "tall" ? "cinema" : "tall"
resize() resize()
autoScroll()
} }
} }

View File

@ -44,4 +44,11 @@ export function addOutput(id: string, output: string) {
item.dataset.id = id item.dataset.id = id
scrollback.append(item) scrollback.append(item)
autoScroll()
}
export function autoScroll() {
setTimeout(() => {
requestAnimationFrame(() => scrollback.scrollTop = scrollback.scrollHeight)
}, 10)
} }