From b0c8bc79881037ce98d5d8a99def64b64e14bd50 Mon Sep 17 00:00:00 2001 From: Dwight Fowler Date: Sat, 17 Sep 2022 00:00:17 -0400 Subject: [PATCH 1/3] Serial Monitor message history #1404 --- .../monitor/serial-monitor-send-input.tsx | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-input.tsx b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-input.tsx index f96636455..20ec58664 100644 --- a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-input.tsx +++ b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-input.tsx @@ -6,6 +6,75 @@ import { BoardsServiceProvider } from '../../boards/boards-service-provider'; import { MonitorModel } from '../../monitor-model'; import { Unknown } from '../../../common/nls'; +class RingList { + protected ring: string[]; + protected size: number; + protected begin: number; + protected index: number; + protected end: number; + + constructor(size: number = 100) { + this.Init = this.Init.bind(this); + this.Push = this.Push.bind(this); + this.Prev = this.Prev.bind(this); + this.Next = this.Next.bind(this); + this.Init(size); + } + + public Init(size: number = 100) + { + this.ring = []; + this.size = (size > 0) ? size : 1; + this.begin = 0; + this.index = 0; + this.end = -1; + } + + public Push(val: string): number { + this.end++; + if (this.ring.length >= this.size) + { + if (this.end >= this.size) + this.end = 0; + if (this.end === this.begin) + { + this.begin++; + if (this.begin >= this.size) + this.begin = 0; + } + } + this.ring[this.end] = val; + this.index = this.end; + + return this.index; + } + + public Prev(): string { + if (this.ring.length < 1) { + return ""; + } + + if (this.index !== this.begin) { + this.index = (this.index > 0) ? --this.index : this.size - 1; + } + + return this.ring[this.index]; + } + + public Next(): string { + if (this.ring.length < 1) { + return ""; + } + + if (this.index !== this.end) { + this.index = (++this.index < this.size) ? this.index : 0; + } + + return this.ring[this.index]; + } + +} + export namespace SerialMonitorSendInput { export interface Props { readonly boardsServiceProvider: BoardsServiceProvider; @@ -16,6 +85,7 @@ export namespace SerialMonitorSendInput { export interface State { text: string; connected: boolean; + history: RingList; } } @@ -27,7 +97,7 @@ export class SerialMonitorSendInput extends React.Component< constructor(props: Readonly) { super(props); - this.state = { text: '', connected: true }; + this.state = { text: '', connected: true, history: new RingList() }; this.onChange = this.onChange.bind(this); this.onSend = this.onSend.bind(this); this.onKeyDown = this.onKeyDown.bind(this); @@ -110,7 +180,17 @@ export class SerialMonitorSendInput extends React.Component< if (keyCode) { const { key } = keyCode; if (key === Key.ENTER) { + // NOTE: order of operations is critical here. Push the current state.text + // onto the history stack before sending. After sending, state.text is empty + // and you'd end up pushing '' onto the history stack. + if (this.state.text.length > 0) this.state.history.Push(this.state.text); this.onSend(); + } else + if (key === Key.ARROW_UP) { + this.setState({ text: this.state.history.Prev()}); + } else + if (key === Key.ARROW_DOWN) { + this.setState({ text: this.state.history.Next()}); } } } From c3556e3ea0c1703ce4e778dc4b4093bdbbb28282 Mon Sep 17 00:00:00 2001 From: Dwight Fowler Date: Fri, 16 Sep 2022 01:27:55 -0400 Subject: [PATCH 2/3] Serial Monitor autoscroll only makes bottom line partially visible #972 --- .../src/browser/serial/monitor/serial-monitor-send-output.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx index 136180202..85ac3d3dc 100644 --- a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx +++ b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx @@ -114,7 +114,7 @@ const _Row = ({ return ( (data.lines[index].lineLen && (
-
+        
           {timestamp}
           {data.lines[index].message}
         
From 9b4b6827bdf0cf4b4ea3a572736a4e5b427cce93 Mon Sep 17 00:00:00 2001 From: Dwight Fowler Date: Sat, 17 Sep 2022 01:09:27 -0400 Subject: [PATCH 3/3] Reconsidered how to fix Serial Monitor autoscroll only makes bottom line partially visible #972 --- .../src/browser/serial/monitor/serial-monitor-send-output.tsx | 2 +- arduino-ide-extension/src/browser/style/monitor.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx index 85ac3d3dc..136180202 100644 --- a/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx +++ b/arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx @@ -114,7 +114,7 @@ const _Row = ({ return ( (data.lines[index].lineLen && (
-
+        
           {timestamp}
           {data.lines[index].message}
         
diff --git a/arduino-ide-extension/src/browser/style/monitor.css b/arduino-ide-extension/src/browser/style/monitor.css index 9e8bd44cc..fdcdfc21c 100644 --- a/arduino-ide-extension/src/browser/style/monitor.css +++ b/arduino-ide-extension/src/browser/style/monitor.css @@ -14,6 +14,10 @@ font-family: monospace } +.serial-monitor-messages pre { + margin: 0px; +} + .serial-monitor .head { display: flex; padding: 5px;