/** Python Console tool window: output, the input box below it, and the console's variables beside them. */ import { useEffect, useLayoutEffect, useRef, useState } from "react"; import { executeAction } from "@/platform/actions"; import { useConsoleFont } from "@/platform/consoleFont"; import { useTx } from "@/platform/i18n"; import { Button, EmptyState, IconButton, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; import { spanStyle } from "@/ui/ansi"; import { clearOutput, execute, restartConsole, sendInput, startConsole, stopConsole, useConsole } from "./store"; import styles from "./PythonConsole.module.css"; export function ConsoleView() { const { status, header, output, variables, noInterpreter } = useConsole(); const font = useConsoleFont(); const t = useTx(); const outputRef = useRef(null); const follow = useRef(true); useEffect(() => void startConsole(), []); useLayoutEffect(() => { const el = outputRef.current; if (el && follow.current) el.scrollTop = el.scrollHeight; }, [output]); if (noInterpreter && status === "stopped") { return ( } > Select an interpreter for this project to use the Python Console. ); } const fontStyle = { fontFamily: font.family, fontSize: font.size, lineHeight: `${font.rowHeight}px` }; return (
{header ?? (status === "starting" ? Starting… : null)}
{ const el = e.currentTarget; follow.current = el.scrollHeight - el.scrollTop - el.clientHeight < 4; }} > {output.map((s, i) => ( // oxlint-disable-next-line react/no-array-index-key -- styled spans repeat; position is the identity {s.text} ))}
{variables.length ? (
{variables.map((v) => (
{v.name} {v.type} {v.value}
))}
) : ( )}
); } /** Enter runs the input (or, while code runs, answers its `input()`); Shift+Enter adds a line; ↑/↓ recall. */ function ConsoleInput({ style, busy }: { style: React.CSSProperties; busy: boolean }) { const [text, setText] = useState(""); const browse = useRef(null); const t = useTx(); return (