Skip to content

Commit 17856e9

Browse files
committed
Remove demo mode
Demo mode doesn't work right now, and I found a better alternative here: https://github.com/Code52/carnac Fixes #192
1 parent 8773a18 commit 17856e9

File tree

10 files changed

+11
-221
lines changed

10 files changed

+11
-221
lines changed

PSReadLine/BasicEditing.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ private bool AcceptLineImpl(bool validate)
220220
// and that requires rendering.
221221
bool renderNeeded = _emphasisStart >= 0 || _queuedKeys.Count > 0;
222222

223-
_renderForDemoNeeded = false;
224223
_emphasisStart = -1;
225224
_emphasisLength = 0;
226225

PSReadLine/Changes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ New cmdlet:
5252
* Remove-PSReadlineKeyHandler
5353
This will remove a key binding for previously bound keys.
5454

55+
Breaking change:
56+
* Demo mode removed
57+
- Trying to bind functions EnableDemoMode or DisableDemoMode will result in an error.
58+
5559
### Version 1.0.0.12
5660

5761
New features:

PSReadLine/History.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ private string MaybeAddToHistory(string result, List<EditItem> edits, int undoEd
6060
IncrementalHistoryWrite();
6161
}
6262
}
63-
if (_demoMode)
64-
{
65-
ClearDemoWindow();
66-
}
6763

6864
// Clear the saved line unless we used AcceptAndGetNext in which
6965
// case we're really still in middle of history and might want

PSReadLine/PSReadLineResources.Designer.cs

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSReadLine/PSReadLineResources.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@
297297
<data name="AcceptAndGetNextDescription" xml:space="preserve">
298298
<value>Accept the current line and recall the next line from history after the current line finishes executing</value>
299299
</data>
300-
<data name="DisableDemoModeDescription" xml:space="preserve">
301-
<value>Disable demo mode</value>
302-
</data>
303-
<data name="EnableDemoModeDescription" xml:space="preserve">
304-
<value>Displays a window below the input line that shows which keys are typed</value>
305-
</data>
306300
<data name="KeyIsUnbound" xml:space="preserve">
307301
<value>Key is unbound</value>
308302
</data>

PSReadLine/ReadLine.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary<ConsoleKeyInfo, KeyHandler> di
426426
}
427427
if (handler != null)
428428
{
429-
_renderForDemoNeeded = _demoMode;
430-
431429
if (handler.ScriptBlock != null)
432430
{
433431
CalloutUsingDefaultConsoleMode(() => handler.Action(key, arg));
@@ -436,11 +434,6 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary<ConsoleKeyInfo, KeyHandler> di
436434
{
437435
handler.Action(key, arg);
438436
}
439-
440-
if (_renderForDemoNeeded)
441-
{
442-
Render();
443-
}
444437
}
445438
else if (!ignoreIfNoAction && key.KeyChar != 0)
446439
{
@@ -486,8 +479,6 @@ private PSConsoleReadLine()
486479

487480
_captureKeys = false;
488481
_savedKeys = new Queue<ConsoleKeyInfo>();
489-
_demoStrings = new HistoryQueue<string>(100);
490-
_demoMode = false;
491482

492483
SetDefaultWindowsBindings();
493484

@@ -612,11 +603,6 @@ private static void Chord(ConsoleKeyInfo? key = null, object arg = null)
612603
Dictionary<ConsoleKeyInfo, KeyHandler> secondKeyDispatchTable;
613604
if (_singleton._chordDispatchTable.TryGetValue(key.Value, out secondKeyDispatchTable))
614605
{
615-
if (_singleton._demoMode)
616-
{
617-
// Render so the first key of the chord appears in the demo window
618-
_singleton.Render();
619-
}
620606
var secondKey = ReadKey();
621607
_singleton.ProcessOneKey(secondKey, secondKeyDispatchTable, ignoreIfNoAction: true, arg: arg);
622608
}

PSReadLine/Render.cs

Lines changed: 7 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ private void Render()
7272

7373
private void ReallyRender()
7474
{
75-
_renderForDemoNeeded = false;
76-
7775
var text = ParseInput();
7876

7977
int statusLineCount = GetStatusLineCount();
80-
int bufferLineCount = ConvertOffsetToCoordinates(text.Length).Y - _initialY + 1 + _demoWindowLineCount + statusLineCount;
78+
int bufferLineCount = ConvertOffsetToCoordinates(text.Length).Y - _initialY + 1 + statusLineCount;
8179
int bufferWidth = Console.BufferWidth;
8280
if (_consoleBuffer.Length != bufferLineCount * bufferWidth)
8381
{
@@ -202,7 +200,7 @@ private void ReallyRender()
202200
}
203201
}
204202

205-
for (; j < (_consoleBuffer.Length - ((statusLineCount + _demoWindowLineCount) * _bufferWidth)); j++)
203+
for (; j < (_consoleBuffer.Length - (statusLineCount * _bufferWidth)); j++)
206204
{
207205
_consoleBuffer[j] = _space;
208206
}
@@ -225,17 +223,12 @@ private void ReallyRender()
225223
_consoleBuffer[j].BackgroundColor = backgroundColor;
226224
}
227225

228-
for (; j < (_consoleBuffer.Length - (_demoWindowLineCount * _bufferWidth)); j++)
226+
for (; j < _consoleBuffer.Length; j++)
229227
{
230228
_consoleBuffer[j] = _space;
231229
}
232230
}
233231

234-
if (_demoMode)
235-
{
236-
RenderDemoWindow(j);
237-
}
238-
239232
bool rendered = false;
240233
if (_parseErrors.Length > 0)
241234
{
@@ -266,9 +259,9 @@ private void ReallyRender()
266259

267260
PlaceCursor();
268261

269-
if ((_initialY + bufferLineCount + (_demoMode ? 1 : 0)) > (Console.WindowTop + Console.WindowHeight))
262+
if ((_initialY + bufferLineCount) > (Console.WindowTop + Console.WindowHeight))
270263
{
271-
Console.WindowTop = _initialY + bufferLineCount + (_demoMode ? 1 : 0) - Console.WindowHeight;
264+
Console.WindowTop = _initialY + bufferLineCount - Console.WindowHeight;
272265
}
273266

274267
_lastRenderTime.Restart();
@@ -487,9 +480,9 @@ private static void ScrollBuffer(int lines)
487480
private void PlaceCursor(int x, ref int y)
488481
{
489482
int statusLineCount = GetStatusLineCount();
490-
if ((y + _demoWindowLineCount + statusLineCount) >= Console.BufferHeight)
483+
if ((y + statusLineCount) >= Console.BufferHeight)
491484
{
492-
ScrollBuffer((y + _demoWindowLineCount + statusLineCount) - Console.BufferHeight + 1);
485+
ScrollBuffer((y + statusLineCount) - Console.BufferHeight + 1);
493486
y = Console.BufferHeight - 1;
494487
}
495488
Console.SetCursorPosition(x, y);
@@ -631,139 +624,6 @@ private bool PromptYesOrNo(string s)
631624
return key.Key == ConsoleKey.Y;
632625
}
633626

634-
#region Demo mode
635-
636-
private readonly HistoryQueue<string> _demoStrings;
637-
private bool _demoMode;
638-
private int _demoWindowLineCount;
639-
private bool _renderForDemoNeeded;
640-
641-
/// <summary>
642-
/// Turn on demo mode (display events like keys pressed)
643-
/// </summary>
644-
public static void EnableDemoMode(ConsoleKeyInfo? key = null, object arg = null)
645-
{
646-
const int windowLineCount = 4; // 1 blank line, 2 border lines, 1 line of info
647-
_singleton._captureKeys = true;
648-
_singleton._demoMode = true;
649-
_singleton._demoWindowLineCount = windowLineCount;
650-
var newBuffer = new CHAR_INFO[_singleton._consoleBuffer.Length + (windowLineCount * _singleton._bufferWidth)];
651-
Array.Copy(_singleton._consoleBuffer, newBuffer,
652-
_singleton._initialX + (_singleton.Options.ExtraPromptLineCount * _singleton._bufferWidth));
653-
_singleton._consoleBuffer = newBuffer;
654-
_singleton.Render();
655-
}
656-
657-
/// <summary>
658-
/// Turn off demo mode (display events like keys pressed)
659-
/// </summary>
660-
public static void DisableDemoMode(ConsoleKeyInfo? key = null, object arg = null)
661-
{
662-
_singleton._savedKeys.Clear();
663-
_singleton._captureKeys = false;
664-
_singleton._demoMode = false;
665-
_singleton._demoStrings.Clear();
666-
_singleton._demoWindowLineCount = 0;
667-
_singleton.ClearDemoWindow();
668-
}
669-
670-
671-
private void RenderDemoWindow(int windowStart)
672-
{
673-
int i;
674-
675-
Action<int, char> setChar = (index, c) =>
676-
{
677-
_consoleBuffer[index].UnicodeChar = c;
678-
_consoleBuffer[index].ForegroundColor = ConsoleColor.DarkCyan;
679-
_consoleBuffer[index].BackgroundColor = ConsoleColor.White;
680-
};
681-
682-
for (i = 0; i < _bufferWidth; i++)
683-
{
684-
_consoleBuffer[windowStart + i].UnicodeChar = ' ';
685-
_consoleBuffer[windowStart + i].ForegroundColor = _initialForegroundColor;
686-
_consoleBuffer[windowStart + i].BackgroundColor = _initialBackgroundColor;
687-
}
688-
windowStart += _bufferWidth;
689-
690-
const int extraSpace = 2;
691-
// Draw the box
692-
setChar(windowStart + extraSpace, (char)9484); // upper left
693-
setChar(windowStart + _bufferWidth * 2 + extraSpace, (char)9492); // lower left
694-
setChar(windowStart + _bufferWidth - 1 - extraSpace, (char)9488); // upper right
695-
setChar(windowStart + _bufferWidth * 3 - 1 - extraSpace, (char)9496); // lower right
696-
setChar(windowStart + _bufferWidth + extraSpace, (char)9474); // side
697-
setChar(windowStart + _bufferWidth * 2 - 1 - extraSpace, (char)9474); // side
698-
699-
for (i = 1 + extraSpace; i < _bufferWidth - 1 - extraSpace; i++)
700-
{
701-
setChar(windowStart + i, (char)9472);
702-
setChar(windowStart + i + 2 * _bufferWidth, (char)9472);
703-
}
704-
705-
while (_savedKeys.Count > 0)
706-
{
707-
var key = _savedKeys.Dequeue();
708-
_demoStrings.Enqueue(key.ToGestureString());
709-
}
710-
711-
int charsToDisplay = _bufferWidth - 2 - (2 * extraSpace);
712-
i = windowStart + _bufferWidth + 1 + extraSpace;
713-
bool first = true;
714-
for (int j = _demoStrings.Count; j > 0; j--)
715-
{
716-
string eventString = _demoStrings[j - 1];
717-
if ((eventString.Length + (first ? 0 : 1)) > charsToDisplay)
718-
break;
719-
720-
if (!first)
721-
{
722-
setChar(i++, ' ');
723-
charsToDisplay--;
724-
}
725-
726-
foreach (char c in eventString)
727-
{
728-
setChar(i, c);
729-
if (first)
730-
{
731-
// Invert the first word to highlight it
732-
var color = _consoleBuffer[i].ForegroundColor;
733-
_consoleBuffer[i].ForegroundColor = _consoleBuffer[i].BackgroundColor;
734-
_consoleBuffer[i].BackgroundColor = color;
735-
}
736-
i++;
737-
charsToDisplay--;
738-
}
739-
740-
first = false;
741-
}
742-
while (charsToDisplay-- > 0)
743-
{
744-
setChar(i++, ' ');
745-
}
746-
}
747-
748-
private void ClearDemoWindow()
749-
{
750-
int bufferWidth = Console.BufferWidth;
751-
var charInfoBuffer = new CHAR_INFO[bufferWidth * 3];
752-
753-
for (int i = 0; i < charInfoBuffer.Length; i++)
754-
{
755-
charInfoBuffer[i].UnicodeChar = ' ';
756-
charInfoBuffer[i].ForegroundColor = _initialForegroundColor;
757-
charInfoBuffer[i].BackgroundColor= _initialBackgroundColor;
758-
}
759-
760-
int bufferLineCount = ConvertOffsetToCoordinates(_buffer.Length).Y - _initialY + 1;
761-
int y = _initialY + bufferLineCount + 1;
762-
WriteBufferLines(charInfoBuffer, ref y);
763-
}
764-
765-
#endregion Demo mode
766-
767627
#region Screen scrolling
768628

769629
/// <summary>

PSReadLine/SamplePSReadlineProfile.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ Set-PSReadlineKeyHandler -Key Ctrl+Shift+Q -Function TabCompletePrevious
3838
Set-PSReadlineKeyHandler -Key Shift+Ctrl+C -Function Copy
3939
Set-PSReadlineKeyHandler -Key Ctrl+V -Function Paste
4040

41-
# Demo mode is great for giving demos of PSReadline,
42-
Set-PSReadlineKeyHandler -Chord 'Ctrl+D,Ctrl+E' -Function EnableDemoMode
43-
Set-PSReadlineKeyHandler -Chord 'Ctrl+D,Ctrl+D' -Function DisableDemoMode
44-
4541
# CaptureScreen is good for blog posts or email showing a transaction
4642
# of what you did when asking for help or demonstrating a technique.
4743
Set-PSReadlineKeyHandler -Chord 'Ctrl+D,Ctrl+C' -Function CaptureScreen

PSReadLine/en-US/about_PSReadline.help.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,6 @@ LONG DESCRIPTION
436436
multiple lines. After selecting, press Enter to copy the text. Escape/Ctrl+C/Ctrl+G
437437
will cancel so nothing is copied to the clipboard.
438438

439-
DisableDemoMode (Cmd: unbound Emacs: unbound)
440-
441-
Turn off demo mode.
442-
443-
EnableDemoMode (Cmd: unbound Emacs: unbound)
444-
445-
Turn on demo mode. Displays a window below the input line that shows which
446-
keys are typed.
447-
448439
InvokePrompt (Cmd: unbound Emacs: unbound)
449440

450441
Erases the current prompt and calls the prompt function to redisplay

UnitTestPSReadLine/RenderTest.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,6 @@ public void TestLongLine()
157157
Test(input, Keys(input));
158158
}
159159

160-
[TestMethod]
161-
public void TestDemoWindow()
162-
{
163-
TestSetup(KeyMode.Cmd,
164-
new KeyHandler("Ctrl+D,Ctrl+E", PSConsoleReadLine.EnableDemoMode),
165-
new KeyHandler("Ctrl+D,Ctrl+D", PSConsoleReadLine.DisableDemoMode));
166-
167-
Test("a", Keys(
168-
_.CtrlD, _.CtrlE,
169-
"a",
170-
_.CtrlD, _.CtrlD));
171-
172-
// To test:
173-
// * Actually check rendering
174-
// * With status line
175-
// * WIth show completions
176-
}
177-
178160
[TestMethod]
179161
public void TestInvokePrompt()
180162
{

0 commit comments

Comments
 (0)