Skip to content

Commit 9d89ae5

Browse files
committed
feat: modify tx/rx message block
1 parent 277d3d0 commit 9d89ae5

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

cspell.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ ignorePaths:
1313
- .gitignore
1414
- "*.svg"
1515
words:
16+
- rgba
17+
- Roboto
1618
- tabler

src/components/terminal/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ function SendIcon() {
2727
);
2828
}
2929

30+
interface Massage {
31+
type: "tx" | "rx";
32+
message: string;
33+
}
34+
3035
export default function Terminal() {
3136
const [port] = useState(SerialPortManager.getInstance());
32-
const [rxMessage, setRxMessage] = useState<string[]>([]);
3337
const [txMessage, setTxMessage] = useState("");
38+
const [msgHistory, setMsgHistory] = useState<Massage[]>([]);
3439
const [userScript, setUserScript] = useState("return raw;");
3540
const [rxCount, setRxCount] = useState(0);
3641
const [txCount, setTxCount] = useState(0);
@@ -40,6 +45,7 @@ export default function Terminal() {
4045
const scriptFunction = new Function("raw", userScript);
4146
const processedData = scriptFunction(new TextEncoder().encode(txMessage));
4247
await port.write(processedData);
48+
setMsgHistory((prev) => [...prev, { type: "tx", message: txMessage }]);
4349
} catch (err) {
4450
console.log(err);
4551
}
@@ -58,7 +64,8 @@ export default function Terminal() {
5864
setTxCount(port.txCount);
5965

6066
const handleReceive = (v: Uint8Array) => {
61-
setRxMessage((prev) => [...prev, new TextDecoder().decode(v)]);
67+
const newMessage = new TextDecoder().decode(v);
68+
setMsgHistory((prev) => [...prev, { type: "rx", message: newMessage }]);
6269
setRxCount(port.rxCount);
6370
};
6471

@@ -69,8 +76,8 @@ export default function Terminal() {
6976
return (
7077
<div className="flex flex-col h-screen gap-2 p-4">
7178
<ScrollArea className=" rounded-md border w-full flex-grow h-3/5">
72-
{rxMessage?.map((v, i) => (
73-
<MessageBlock key={i} type="rx" message={v} />
79+
{msgHistory?.map((m, i) => (
80+
<MessageBlock key={i} type={m.type} message={m.message} />
7481
))}
7582
</ScrollArea>
7683
<div className="flex w-full gap-2 h-1/5">

src/components/terminal/message-block.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
.message-block {
22
display: flex;
33
align-items: center;
4-
gap: 0.5rem;
5-
padding: 0.5rem 1rem;
4+
margin: 0;
65
border-radius: 0.25rem;
7-
font-family: monospace;
6+
font-family: "Roboto Mono", monospace;
7+
font-size: 0.8rem;
88
}
99

1010
.message-tx {
11-
color: chartreuse;
11+
color: rgba(14, 116, 144, 0.8);
1212
}
1313

1414
.message-rx {
15-
color: brown;
15+
color: unset;
1616
}
1717

1818
.message-content {

0 commit comments

Comments
 (0)