@@ -1875,47 +1875,69 @@ ToolRegistry.register({
18751875 } ,
18761876} )
18771877
1878- function ConsoleOutput ( props : { copy : string ; children : JSX . Element ; variant ?: "shell" } ) {
1878+ function ConsoleOutput ( props : { command : string ; output : string } ) {
18791879 const i18n = useI18n ( )
1880- const [ copied , setCopied ] = createSignal ( false )
1881-
1882- const copy = async ( ) => {
1883- if ( ! props . copy ) return
1884-
1885- if ( ! ( await writeClipboard ( props . copy ) ) ) return
1886- setCopied ( true )
1887- setTimeout ( ( ) => setCopied ( false ) , 2000 )
1888- }
18891880
18901881 return (
1891- < div data-component = "bash-output" data-variant = { props . variant } dir = "ltr" >
1892- < div data-slot = "bash-copy" >
1893- < Tooltip value = { copied ( ) ? i18n . t ( "ui.message.copied" ) : i18n . t ( "ui.message.copy" ) } placement = "top" >
1894- < IconButton
1895- icon = { < Icon name = { copied ( ) ? "check" : "outline-copy" } size = "small" /> }
1896- size = "normal"
1897- variant = "ghost-muted"
1898- onMouseDown = { ( event ) => event . preventDefault ( ) }
1899- onClick = { copy }
1900- aria-label = { copied ( ) ? i18n . t ( "ui.message.copied" ) : i18n . t ( "ui.message.copy" ) }
1901- />
1902- </ Tooltip >
1903- </ div >
1882+ < div data-component = "bash-output" data-variant = "shell" dir = "ltr" >
19041883 < div
19051884 data-slot = "bash-scroll"
19061885 data-scrollable
19071886 tabIndex = { 0 }
19081887 role = "region"
19091888 aria-label = { i18n . t ( "ui.scrollView.ariaLabel" ) }
19101889 >
1911- < pre data-slot = "bash-pre" >
1912- < code > { props . children } </ code >
1913- </ pre >
1890+ < div data-slot = "bash-command" >
1891+ < ConsoleCopy text = { props . command } label = { i18n . t ( "ui.message.copy" ) } />
1892+ < pre data-slot = "bash-pre" >
1893+ < code > { props . command } </ code >
1894+ </ pre >
1895+ </ div >
1896+ < Show when = { props . output } >
1897+ { ( output ) => (
1898+ < div data-slot = "bash-result" >
1899+ < ConsoleCopy text = { output ( ) } label = { i18n . t ( "ui.message.copyOutput" ) } />
1900+ < pre data-slot = "bash-pre" >
1901+ < code > { output ( ) } </ code >
1902+ </ pre >
1903+ </ div >
1904+ ) }
1905+ </ Show >
19141906 </ div >
19151907 </ div >
19161908 )
19171909}
19181910
1911+ // The button sits beside its section's <pre>, not inside it, so selecting and copying text never picks it up.
1912+ function ConsoleCopy ( props : { text : string ; label : string } ) {
1913+ const i18n = useI18n ( )
1914+ const [ copied , setCopied ] = createSignal ( false )
1915+ const label = ( ) => ( copied ( ) ? i18n . t ( "ui.message.copied" ) : props . label )
1916+
1917+ const copy = async ( ) => {
1918+ if ( ! props . text ) return
1919+
1920+ if ( ! ( await writeClipboard ( props . text ) ) ) return
1921+ setCopied ( true )
1922+ setTimeout ( ( ) => setCopied ( false ) , 2000 )
1923+ }
1924+
1925+ return (
1926+ < div data-slot = "bash-copy" >
1927+ < Tooltip value = { label ( ) } placement = "top" >
1928+ < IconButton
1929+ icon = { < Icon name = { copied ( ) ? "check" : "outline-copy" } size = "small" /> }
1930+ size = "normal"
1931+ variant = "ghost-muted"
1932+ onMouseDown = { ( event ) => event . preventDefault ( ) }
1933+ onClick = { copy }
1934+ aria-label = { label ( ) }
1935+ />
1936+ </ Tooltip >
1937+ </ div >
1938+ )
1939+ }
1940+
19191941ToolRegistry . register ( {
19201942 name : "execute" ,
19211943 render ( props ) {
@@ -1946,10 +1968,7 @@ ToolRegistry.register({
19461968 </ div >
19471969 ) }
19481970 >
1949- < ConsoleOutput copy = { code ( ) } variant = "shell" >
1950- < span data-slot = "bash-command" > { code ( ) } </ span >
1951- < Show when = { output ( ) } > { ( value ) => < span data-slot = "bash-result" > { value ( ) } </ span > } </ Show >
1952- </ ConsoleOutput >
1971+ < ConsoleOutput command = { code ( ) } output = { output ( ) } />
19531972 </ BasicTool >
19541973 )
19551974 } ,
@@ -1998,12 +2017,7 @@ ToolRegistry.register({
19982017 ) ,
19992018 )
20002019
2001- return (
2002- < ConsoleOutput copy = { command ( ) } variant = "shell" >
2003- < span data-slot = "bash-command" > { command ( ) } </ span >
2004- < Show when = { output ( ) } > { ( value ) => < span data-slot = "bash-result" > { value ( ) } </ span > } </ Show >
2005- </ ConsoleOutput >
2006- )
2020+ return < ConsoleOutput command = { command ( ) } output = { output ( ) } />
20072021 }
20082022
20092023 return (
0 commit comments