11import { TextAttributes } from "@opentui/core"
22import { useKeyboard , useRenderer , useTerminalDimensions } from "@opentui/solid"
3+ import * as Clipboard from "@tui/util/clipboard"
34import { win32FlushInputBuffer } from "../win32"
45import { getScrollAcceleration } from "../util/scroll"
6+ import { createSignal } from "solid-js"
57
68export function ErrorComponent ( props : {
79 error : Error
@@ -12,6 +14,7 @@ export function ErrorComponent(props: {
1214} ) {
1315 const term = useTerminalDimensions ( )
1416 const renderer = useRenderer ( )
17+ const [ copied , setCopied ] = createSignal ( false )
1518
1619 const handleExit = async ( ) => {
1720 await props . onBeforeExit ?.( )
@@ -21,9 +24,22 @@ export function ErrorComponent(props: {
2124 await props . onExit ( )
2225 }
2326
27+ const errorText = ( ) => [ props . error . message , props . error . stack ] . filter ( Boolean ) . join ( "\n\n" )
28+ const handleCopy = async ( ) => {
29+ await Clipboard . copy ( errorText ( ) ) . catch ( ( ) => { } )
30+ setCopied ( true )
31+ setTimeout ( ( ) => setCopied ( false ) , 2000 )
32+ }
33+
2434 useKeyboard ( ( evt ) => {
2535 if ( evt . ctrl && evt . name === "c" ) {
2636 void handleExit ( )
37+ return
38+ }
39+ if ( evt . name === "y" ) {
40+ evt . preventDefault ( )
41+ evt . stopPropagation ( )
42+ void handleCopy ( )
2743 }
2844 } )
2945
@@ -42,13 +58,17 @@ export function ErrorComponent(props: {
4258 < text attributes = { TextAttributes . BOLD } fg = { colors . text } >
4359 A fatal error occurred!
4460 </ text >
61+ < box onMouseUp = { ( ) => void handleCopy ( ) } backgroundColor = { colors . primary } padding = { 1 } >
62+ < text fg = { colors . bg } > Copy error</ text >
63+ </ box >
4564 < box onMouseUp = { props . reset } backgroundColor = { colors . primary } padding = { 1 } >
4665 < text fg = { colors . bg } > Reset TUI</ text >
4766 </ box >
4867 < box onMouseUp = { handleExit } backgroundColor = { colors . primary } padding = { 1 } >
4968 < text fg = { colors . bg } > Exit</ text >
5069 </ box >
5170 </ box >
71+ < text fg = { colors . muted } > { copied ( ) ? "Error copied to clipboard" : "Press Y to copy the full error log" } </ text >
5272 < scrollbox height = { Math . floor ( term ( ) . height * 0.7 ) } scrollAcceleration = { getScrollAcceleration ( ) } >
5373 < text fg = { colors . muted } > { props . error . stack } </ text >
5474 </ scrollbox >
0 commit comments