diff --git a/src/components/player/TextBuffer.jsx b/src/components/player/TextBuffer.jsx index 6f158c9..ad3727a 100644 --- a/src/components/player/TextBuffer.jsx +++ b/src/components/player/TextBuffer.jsx @@ -1,6 +1,15 @@ import { h } from 'preact' import { useState, useEffect } from 'preact/hooks' +import TextMessage from './TextMessage' + +const trimImputPrompt = messages => + messages.length < 1 + ? messages + : messages.slice(-1)[0].text === '>' + ? messages.slice(0, messages.length - 1) + : messages + const parseInbox = (inbox, currentWindow) => { const currentInbox = inbox.find(({ id }) => @@ -16,7 +25,7 @@ const parseInbox = (inbox, currentWindow) => { const { clear, text: inboxMessagesRaw } = currentInbox - const incoming = + const incoming = trimImputPrompt( inboxMessagesRaw /* Normalize. */ .map(({ content }) => @@ -32,7 +41,7 @@ const parseInbox = (inbox, currentWindow) => { return prev.style === 'emptyLine' ? acc : [...acc, x] - }, []) + }, [])) return { clear, incoming } } @@ -50,9 +59,8 @@ export default function ({ inbox, currentWindow }) { }, [inbox]) return ( -
- {messages.map(({ text }) => - (
{text}
))} -
+
+ {messages.map(TextMessage)} +
) } diff --git a/src/components/player/TextMessage.jsx b/src/components/player/TextMessage.jsx new file mode 100644 index 0000000..ef93625 --- /dev/null +++ b/src/components/player/TextMessage.jsx @@ -0,0 +1,16 @@ +import { h } from 'preact' + +export default function ({ style, text }) { + const defaultContent = ({text}) + + const content = ({ + emptyLine: (
), + subheader: ({text}) + })[style] || defaultContent + + return ( +
+ {content} +
+ ) +}