click to replay prompt

This commit is contained in:
Chris Wanstrath 2025-09-29 22:36:08 -07:00
parent d99b4d53e1
commit f828384dba
2 changed files with 21 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import { initHistory } from "./history.js"
import { initHyperlink } from "./hyperlink.js" import { initHyperlink } from "./hyperlink.js"
import { initInput } from "./input.js" import { initInput } from "./input.js"
import { initResize } from "./resize.js" import { initResize } from "./resize.js"
import { initScrollback } from "./scrollback.js"
import { startVramCounter } from "./vram.js" import { startVramCounter } from "./vram.js"
import { startConnection } from "./websocket.js" import { startConnection } from "./websocket.js"
@ -19,6 +20,7 @@ initHistory()
initHyperlink() initHyperlink()
initInput() initInput()
initResize() initResize()
initScrollback()
startConnection() startConnection()
startVramCounter() startVramCounter()

View File

@ -2,12 +2,16 @@
// The scrollback shows your history of interacting with the shell. // The scrollback shows your history of interacting with the shell.
// input, output, etc // input, output, etc
import { scrollback, $$ } from "./dom.js"
import { randomId } from "../shared/utils.js"
import type { CommandOutput } from "../shared/types.js" import type { CommandOutput } from "../shared/types.js"
import { scrollback, cmdInput, $$ } from "./dom.js"
import { randomId } from "../shared/utils.js"
type InputStatus = "waiting" | "streaming" | "ok" | "error" type InputStatus = "waiting" | "streaming" | "ok" | "error"
export function initScrollback() {
window.addEventListener("click", handleInputClick)
}
export function autoScroll() { export function autoScroll() {
// requestAnimationFrame(() => scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight) // requestAnimationFrame(() => scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight)
// scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight // scrollback.scrollTop = scrollback.scrollHeight - scrollback.clientHeight
@ -63,10 +67,11 @@ export function addOutput(id: string, output: CommandOutput) {
item.textContent = content item.textContent = content
const input = document.querySelector(`[data-id="${id}"].input`) const input = document.querySelector(`[data-id="${id}"].input`)
if (input instanceof HTMLLIElement) if (input instanceof HTMLLIElement) {
input.parentNode!.insertBefore(item, input.nextSibling) input.parentNode!.insertBefore(item, input.nextSibling)
else } else {
insert(item) insert(item)
}
autoScroll() autoScroll()
} }
@ -135,3 +140,13 @@ function processOutput(output: CommandOutput): ["html" | "text", string] {
return [html ? "html" : "text", content] return [html ? "html" : "text", content]
} }
function handleInputClick(e: MouseEvent) {
const target = e.target
if (!(target instanceof HTMLElement)) return
if (target.matches(".input .content")) {
cmdInput.value = target.textContent
}
}