Skip to content

Commit

Permalink
add a way to render the buffer from a given line, add a lazy handler …
Browse files Browse the repository at this point in the history
…to close the app after program exit.
  • Loading branch information
doubleyewdee committed Nov 24, 2018
1 parent 1162c9f commit fc90989
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/ConsoleBuffer/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Append(byte[] bytes, int length)
switch (this.parser.Append(this.currentChar))
{
case ParserAppendResult.Render:
this.RenderAtCursor(this.currentChar);
this.PrintAtCursor(this.currentChar);
break;
case ParserAppendResult.Complete:
this.ExecuteParserCommand();
Expand All @@ -103,7 +103,7 @@ public void Append(byte[] bytes, int length)
/// Renders the current character at the cursor, advances the cursor, and proceeds to the next line if necessary while scrolling the buffer.
/// </summary>
/// <param name="ch"></param>
private void RenderAtCursor(int ch)
private void PrintAtCursor(int ch)
{

if (this.cursorX == this.MaxCursorX && this.wrapCharacter == this.receivedCharacters - 1)
Expand Down Expand Up @@ -385,17 +385,38 @@ private void ScrollDown(int lines = 1)
/// <summary>
/// Render character-by-character onto the specified target.
/// </summary>
/// <param name="target">target to render on to.</param>
public void Render(IRenderTarget target)
{
this.RenderFromLine(target, int.MaxValue);
}

/// <summary>
/// Render character-by-character onto the specified target.
/// </summary>
/// <param name="target">Target to render on to.</param>
/// <param name="startLine">Starting line to render from.</param>
/// <remarks>
/// If the starting line would not produce a full render it is silently set to the current top visible line,
/// producing a render of the current visible screen-buffer. Similarly negative line numbers are treated as 0.
/// </remarks>
public void RenderFromLine(IRenderTarget target, int startLine)
{
lock (this.renderLock)
{
startLine = Math.Max(0, startLine);
if (startLine > this.topVisibleLine)
{
startLine = this.topVisibleLine;
}

for (var y = 0; y < this.Height; ++y)
{
var renderLine = this.topVisibleLine + y;
var renderLine = startLine + y;
var line = this.lines[renderLine];

for (var x = 0; x < this.Width; ++x)
{
{
target.RenderCharacter(line.Get(x), x, y);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/condo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ private void OnLoaded(object sender, RoutedEventArgs e)
this.KeyDown += this.keyHandler.OnKeyDown;
this.TextInput += this.keyHandler.OnTextInput;

this.console.PropertyChanged += (_, args) =>
{
if (args.PropertyName == "Running" && this.console.Running == false)
{
this.KeyDown += (keySender, keyArgs) =>
{
if (keyArgs.Key == System.Windows.Input.Key.Enter)
{
this.Close();
}
};
}
};

this.Closing += this.HandleClosing;
}

Expand Down

0 comments on commit fc90989

Please sign in to comment.