fix logging to terminal

pull/5370/head
yann300 3 years ago
parent efdb955dfe
commit cff5a9497c
  1. 10
      apps/remix-ide/src/app/panels/terminal.js
  2. 19
      libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx

@ -104,21 +104,11 @@ class Terminal extends Plugin {
logHtml (html) {
this.logHtmlResponse.push(html.innerText)
this.renderComponent()
this.resetLogHtml()
}
resetLogHtml () {
this.logHtmlResponse = []
}
log (message) {
this.logResponse.push(message)
this.renderComponent()
this.resetLog()
}
resetLog () {
this.logResponse = []
}
render () {

@ -68,6 +68,11 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
commandHistoryIndex: 0
})
const [logState, setLogState] = useState({
logIndex: 0,
htmlLogIndex: 0
})
const [searchInput, setSearchInput] = useState('')
const [showTableHash, setShowTableHash] = useState([])
@ -84,12 +89,18 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
}
useEffect(() => {
scriptRunnerDispatch({ type: 'html', payload: { message: logHtmlResponse } })
}, [logHtmlResponse])
if (logHtmlResponse.length > 0) {
scriptRunnerDispatch({ type: 'html', payload: { message: logHtmlResponse.slice(logState.htmlLogIndex) } })
setLogState(prevState => ({ ...prevState, htmlLogIndex: logHtmlResponse.length }))
}
}, [logHtmlResponse.length])
useEffect(() => {
scriptRunnerDispatch({ type: 'log', payload: { message: logResponse } })
}, [logResponse])
if (logResponse.length > 0) {
scriptRunnerDispatch({ type: 'log', payload: { message: logResponse.slice(logState.logIndex) } })
setLogState(prevState => ({ ...prevState, logIndex: logResponse.length }))
}
}, [logResponse.length])
// events
useEffect(() => {

Loading…
Cancel
Save