Skip to content

Commit 8b8a080

Browse files
committed
Handle incremental history search with prompt
This one's the hairest, but seems to be working like Zsh
1 parent e6f2301 commit 8b8a080

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

PSReadLine/History.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ private void UpdateHistoryDuringInteractiveSearch(string toMatch, int direction,
11431143
? HistoryMoveCursor.ToEnd
11441144
: HistoryMoveCursor.DontMove;
11451145
UpdateFromHistory(moveCursor);
1146+
SafeRender($"\x1b[s\x1b[1E\x1b[K{_statusLinePrompt}{toMatch}_\x1b[u");
11461147
return;
11471148
}
11481149
}
@@ -1157,7 +1158,8 @@ private void UpdateHistoryDuringInteractiveSearch(string toMatch, int direction,
11571158
_emphasisStart = -1;
11581159
_emphasisLength = 0;
11591160
_statusLinePrompt = direction > 0 ? _failedForwardISearchPrompt : _failedBackwardISearchPrompt;
1160-
Render();
1161+
// Deletes the original status line and then renders the new one
1162+
SafeRender($"\x1b[s\x1b[1E\x1b[K{_statusLinePrompt}{toMatch}_\x1b[u");
11611163
}
11621164

11631165
private void InteractiveHistorySearchLoop(int direction)
@@ -1193,6 +1195,7 @@ private void InteractiveHistorySearchLoop(int direction)
11931195
{
11941196
toMatch.Remove(toMatch.Length - 1, 1);
11951197
_statusBuffer.Remove(_statusBuffer.Length - 2, 1);
1198+
SafeRender($"\x1b[s\x1b[1E\x1b[{_statusLinePrompt.Length + toMatch.Length}C\x1b[P\x1b[u");
11961199
searchPositions.Pop();
11971200
searchFromPoint = _currentHistoryIndex = searchPositions.Peek();
11981201
var moveCursor = Options.HistorySearchCursorMovesToEnd
@@ -1223,7 +1226,8 @@ private void InteractiveHistorySearchLoop(int direction)
12231226
_current = startIndex;
12241227
_emphasisStart = startIndex;
12251228
_emphasisLength = toMatch.Length;
1226-
Render();
1229+
// Deletes the original status line prompt and then renders the new one
1230+
SafeRender($"\x1b[s\x1b[1E\x1b[K{_statusLinePrompt}{toMatch}_\x1b[u");
12271231
}
12281232
}
12291233
else
@@ -1264,7 +1268,7 @@ private void InteractiveHistorySearchLoop(int direction)
12641268
_current = startIndex;
12651269
_emphasisStart = startIndex;
12661270
_emphasisLength = toMatch.Length;
1267-
Render();
1271+
SafeRender(toAppend.ToString());
12681272
}
12691273
searchPositions.Push(_currentHistoryIndex);
12701274
}
@@ -1280,13 +1284,15 @@ private void InteractiveHistorySearch(int direction)
12801284
_statusLinePrompt = direction > 0 ? _forwardISearchPrompt : _backwardISearchPrompt;
12811285
_statusBuffer.Append("_");
12821286

1283-
Render(); // Render prompt
1287+
// Saves cursor, renders new line with status prompt, restores cursor
1288+
SafeRender($"\x1b[s\n{_statusLinePrompt}_\x1b[u");
12841289
InteractiveHistorySearchLoop(direction);
12851290

12861291
_emphasisStart = -1;
12871292
_emphasisLength = 0;
12881293

12891294
// Remove our status line, this will render
1295+
// TODO: Evaluate this under a screen reader
12901296
ClearStatusMessage(render: true);
12911297
}
12921298

0 commit comments

Comments
 (0)