From 548063d2d8fac4c63b901da4cf690862077fe20e Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Mon, 6 Sep 2021 10:44:58 -0400 Subject: [PATCH] Add `LengthInBufferCells` implementation Without redirecting this call to `internalRawUI` any formatting with ANSI escapes will likely be truncated in the wrong spot --- .../Host/TerminalPSHostRawUserInterface.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostRawUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostRawUserInterface.cs index eea9276b8..423a00e9c 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostRawUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostRawUserInterface.cs @@ -265,6 +265,53 @@ public override void SetBufferContents( this.internalRawUI.SetBufferContents(origin, contents); } + /// + /// Determines the number of BufferCells a character occupies. + /// + /// + /// The character whose length we want to know. + /// + /// + /// The length in buffer cells according to the original host + /// implementation for the process. + /// + public override int LengthInBufferCells(char source) + { + return this.internalRawUI.LengthInBufferCells(source); + } + /// + /// Determines the number of BufferCells a string occupies. + /// + /// + /// The string whose length we want to know. + /// + /// + /// The length in buffer cells according to the original host + /// implementation for the process. + /// + public override int LengthInBufferCells(string source) + { + return this.internalRawUI.LengthInBufferCells(source); + } + + /// + /// Determines the number of BufferCells a substring of a string occupies. + /// + /// + /// The string whose substring length we want to know. + /// + /// + /// Offset where the substring begins in + /// + /// + /// The length in buffer cells according to the original host + /// implementation for the process. + /// + public override int LengthInBufferCells(string source, int offset) + { + return this.internalRawUI.LengthInBufferCells(source, offset); + } + #endregion ///