Skip to content

Commit c39f93e

Browse files
committed
Basic handling of status line prompt in screen reader mode
It does not handle added text like in incremental history search, but it does display correctly.
1 parent 1d90910 commit c39f93e

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

PSReadLine/Render.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,18 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
286286

287287
// For screen readers, we are just comparing the previous and current buffer text
288288
// (without colors) and only writing the differences.
289-
string currentBuffer = ParseInput();
289+
string parsedInput = ParseInput();
290+
StringBuilder buffer = new(parsedInput);
291+
292+
// Really simple handling of a status line: append it!
293+
if (!string.IsNullOrEmpty(_statusLinePrompt))
294+
{
295+
buffer.Append("\n");
296+
buffer.Append(_statusLinePrompt);
297+
buffer.Append(_statusBuffer);
298+
}
299+
300+
string currentBuffer = buffer.ToString();
290301
string previousBuffer = _previousRender.lines[0].Line;
291302

292303
// In case the buffer was resized.
@@ -310,7 +321,7 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
310321
{
311322
// Buffers share a common prefix but previous buffer has additional content.
312323
// Move cursor to where the difference starts, clear forward, and write the data.
313-
var diffPoint = ConvertOffsetToPoint(commonPrefixLength);
324+
var diffPoint = ConvertOffsetToPoint(commonPrefixLength, buffer);
314325
_console.SetCursorPosition(diffPoint.X, diffPoint.Y);
315326
var changedData = currentBuffer.Substring(commonPrefixLength);
316327
_console.Write("\x1b[0J");
@@ -325,7 +336,7 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
325336
}
326337

327338
// If we had to wrap to render everything, update _initialY
328-
var endPoint = ConvertOffsetToPoint(currentBuffer.Length);
339+
var endPoint = ConvertOffsetToPoint(currentBuffer.Length, buffer);
329340
if (endPoint.Y >= bufferHeight)
330341
{
331342

@@ -349,7 +360,7 @@ static int FindCommonPrefixLength(string leftStr, string rightStr)
349360
_previousRender = renderData;
350361

351362
// Calculate the coord to place the cursor for the next input.
352-
var point = ConvertOffsetToPoint(_current);
363+
var point = ConvertOffsetToPoint(_current, buffer);
353364

354365
if (point.Y == bufferHeight)
355366
{
@@ -1327,8 +1338,12 @@ internal Point EndOfBufferPosition()
13271338
return ConvertOffsetToPoint(_buffer.Length);
13281339
}
13291340

1330-
internal Point ConvertOffsetToPoint(int offset)
1341+
internal Point ConvertOffsetToPoint(int offset, StringBuilder buffer = null)
13311342
{
1343+
// This lets us re-use the logic in the screen reader rendering implementation
1344+
// where the status line is added to the buffer without modifying the locabl state.
1345+
buffer ??= _buffer;
1346+
13321347
int x = _initialX;
13331348
int y = _initialY;
13341349

@@ -1337,7 +1352,7 @@ internal Point ConvertOffsetToPoint(int offset)
13371352

13381353
for (int i = 0; i < offset; i++)
13391354
{
1340-
char c = _buffer[i];
1355+
char c = buffer[i];
13411356
if (c == '\n')
13421357
{
13431358
y += 1;
@@ -1355,7 +1370,7 @@ internal Point ConvertOffsetToPoint(int offset)
13551370

13561371
// If cursor is at column 0 and the next character is newline, let the next loop
13571372
// iteration increment y.
1358-
if (x != 0 || !(i + 1 < offset && _buffer[i + 1] == '\n'))
1373+
if (x != 0 || !(i + 1 < offset && buffer[i + 1] == '\n'))
13591374
{
13601375
y += 1;
13611376
}
@@ -1364,9 +1379,9 @@ internal Point ConvertOffsetToPoint(int offset)
13641379
}
13651380

13661381
// If next character actually exists, and isn't newline, check if wider than the space left on the current line.
1367-
if (_buffer.Length > offset && _buffer[offset] != '\n')
1382+
if (buffer.Length > offset && buffer[offset] != '\n')
13681383
{
1369-
int size = LengthInBufferCells(_buffer[offset]);
1384+
int size = LengthInBufferCells(buffer[offset]);
13701385
if (x + size > bufferWidth)
13711386
{
13721387
// Character was wider than remaining space, so character, and cursor, appear on next line.

test/DigitArgumentTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public void DigitArgumentValues()
4646
[SkippableFact]
4747
public void DigitArgumentPrompt()
4848
{
49-
Skip.If(ScreenReaderModeEnabled, "Digit argument prompt is not supported in screen reader mode.");
50-
5149
TestSetup(KeyMode.Emacs);
5250

5351
Test("", Keys(

test/HistoryTest.VI.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public void ViHistory()
5353
[SkippableFact]
5454
public void ViSearchHistory()
5555
{
56-
Skip.If(ScreenReaderModeEnabled, "Incremental search prompt is not supported in screen reader mode.");
57-
5856
TestSetup(KeyMode.Vi);
5957

6058
// Clear history in case the above added some history (but it shouldn't)

test/HistoryTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,6 @@ public void EndOfHistory()
882882
[SkippableFact]
883883
public void InteractiveHistorySearch()
884884
{
885-
Skip.If(ScreenReaderModeEnabled, "Incremental search prompt is not supported in screen reader mode.");
886-
887885
TestSetup(KeyMode.Emacs);
888886

889887
SetHistory("echo aaa");

test/KeyBindingsTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public partial class ReadLine
99
[SkippableFact]
1010
public void WhatIsKey()
1111
{
12-
Skip.If(ScreenReaderModeEnabled, "The what-is-key prompt is not supported in screen reader mode.");
13-
1412
TestSetup(KeyMode.Cmd);
1513

1614
Test("", Keys(

0 commit comments

Comments
 (0)