Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public object ContinuationPromptColor
/// If the prompt function is pure, this value can be inferred, e.g.
/// the default prompt will use "> " for this value.
/// </summary>
public string PromptText { get; set; }
public string[] PromptText { get; set; }

public object DefaultTokenColor
{
Expand Down Expand Up @@ -663,7 +663,7 @@ public int AnsiEscapeTimeout

[Parameter]
[ValidateNotNull]
public string PromptText { get; set; }
public string[] PromptText { get; set; }

[Parameter]
public ViModeStyle ViModeIndicator
Expand Down
2 changes: 1 addition & 1 deletion PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ private void DelayedOneTimeInitialize()

if (i >= 0)
{
_options.PromptText = evaluatedPrompt.Substring(i);
_options.PromptText = new [] { evaluatedPrompt.Substring(i) };
}
}
}
Expand Down
29 changes: 19 additions & 10 deletions PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,18 @@ void MaybeEmphasize(int i, string currColor)
/// </returns>
private bool RenderErrorPrompt(RenderData renderData, string defaultColor)
{
// We may need to flip the color on the prompt if the error state changed.

int bufferWidth = _console.BufferWidth;
string promptText = _options.PromptText;

if (string.IsNullOrEmpty(promptText) || _initialY < 0)
if (_initialY < 0
|| _options.PromptText == null
|| _options.PromptText.Length == 0
|| String.IsNullOrEmpty(_options.PromptText[0]))
{
// No need to flip the prompt color if either the error prompt is not defined
// or the initial cursor point has already been scrolled off the buffer.
return false;
}

// We may need to flip the color on the prompt if the error state changed.

renderData.errorPrompt = (_parseErrors != null && _parseErrors.Length > 0);
if (renderData.errorPrompt == _previousRender.errorPrompt)
{
Expand All @@ -386,9 +386,15 @@ private bool RenderErrorPrompt(RenderData renderData, string defaultColor)
// We need to update the prompt
_console.SetCursorPosition(_initialX, _initialY);

string promptText =
(renderData.errorPrompt && _options.PromptText.Length == 2)
? _options.PromptText[1]
: _options.PromptText[0];

// promptBufferCells is the number of visible characters in the prompt
int promptBufferCells = LengthInBufferCells(promptText);
bool renderErrorPrompt = false;
int bufferWidth = _console.BufferWidth;

if (_console.CursorLeft >= promptBufferCells)
{
Expand Down Expand Up @@ -419,12 +425,15 @@ private bool RenderErrorPrompt(RenderData renderData, string defaultColor)

if (renderErrorPrompt)
{
string color = renderData.errorPrompt ? _options._errorColor : defaultColor;
if (renderData.errorPrompt && promptBufferCells != promptText.Length)
if (!promptText.Contains('\x1b'))
{
promptText = promptText.Substring(promptText.Length - promptBufferCells);
string color = renderData.errorPrompt ? _options._errorColor : defaultColor;
if (renderData.errorPrompt && promptBufferCells != promptText.Length)
{
promptText = promptText.Substring(promptText.Length - promptBufferCells);
}
_console.Write(color);
}
_console.Write(color);
_console.Write(promptText);
_console.Write("\x1b[0m");
}
Expand Down
6 changes: 3 additions & 3 deletions test/UnitTestReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private void SetPrompt(string prompt)
var options = new SetPSReadLineOption {ExtraPromptLineCount = 0};
if (string.IsNullOrEmpty(prompt))
{
options.PromptText = "";
options.PromptText = new [] {""};
PSConsoleReadLine.SetOptions(options);
return;
}
Expand All @@ -365,7 +365,7 @@ private void SetPrompt(string prompt)
if (!char.IsWhiteSpace(prompt[i])) break;
}

options.PromptText = prompt.Substring(i);
options.PromptText = new [] { prompt.Substring(i) };

var lineCount = 1 + prompt.Count(c => c == '\n');
if (lineCount > 1)
Expand Down Expand Up @@ -474,7 +474,7 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
MaximumKillRingCount = PSConsoleReadLineOptions.DefaultMaximumKillRingCount,
ShowToolTips = PSConsoleReadLineOptions.DefaultShowToolTips,
WordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters,
PromptText = "",
PromptText = new [] {""},
Colors = new Hashtable {
{ "ContinuationPrompt", MakeCombinedColor(_console.ForegroundColor, _console.BackgroundColor) },
{ "Emphasis", MakeCombinedColor(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor) },
Expand Down