Skip to content

Commit

Permalink
Read whole terminal frame at once to avoid console data append glitch…
Browse files Browse the repository at this point in the history
…es (#299)

* Read whole terminal frame at once to avoid console data append glitches

* Simplify calculation logic with Math.Max
  • Loading branch information
maxhora authored and felixse committed Apr 7, 2019
1 parent 8e5d3de commit 39960dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion FluentTerminal.SystemTray/Services/ConPty/ConPtySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ConPtySession : ITerminalSession
private TerminalsManager _terminalsManager;
private Terminal _terminal;
private bool _exited;
private TerminalSize _terminalSize;

public int Id { get; private set; }

Expand All @@ -26,12 +27,14 @@ public void Close()
public void Resize(TerminalSize size)
{
_terminal.Resize(size.Columns, size.Rows);
_terminalSize = size;
}

public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
{
Id = request.Id;
_terminalsManager = terminalsManager;
_terminalSize = request.Size;

ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
var cwd = GetWorkingDirectory(request.Profile);
Expand Down Expand Up @@ -80,7 +83,7 @@ private void ListenToStdOut()
{
do
{
var buffer = new byte[1024];
var buffer = new byte[Math.Max(1024, _terminalSize.Columns * _terminalSize.Rows * 4)];
var readBytes = await _terminal.ConsoleOutStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
var read = new byte[readBytes];
Buffer.BlockCopy(buffer, 0, read, 0, readBytes);
Expand Down
5 changes: 4 additions & 1 deletion FluentTerminal.SystemTray/Services/WinPty/WinPtySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public class WinPtySession : IDisposable, ITerminalSession
private TerminalsManager _terminalsManager;
private Process _shellProcess;
private bool _exited;
private TerminalSize _terminalSize;

public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
{
Id = request.Id;
_terminalsManager = terminalsManager;
_terminalSize = request.Size;

var configHandle = IntPtr.Zero;
var spawnConfigHandle = IntPtr.Zero;
Expand Down Expand Up @@ -145,6 +147,7 @@ public void Resize(TerminalSize size)
{
throw new Exception(winpty_error_msg(errorHandle));
}
_terminalSize = size;
}
finally
{
Expand Down Expand Up @@ -198,7 +201,7 @@ private void ListenToStdOut()
{
do
{
var buffer = new byte[1024];
var buffer = new byte[Math.Max(1024, _terminalSize.Columns * _terminalSize.Rows * 4)];
var readBytes = await _stdout.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
var read = new byte[readBytes];
Buffer.BlockCopy(buffer, 0, read, 0, readBytes);
Expand Down

0 comments on commit 39960dd

Please sign in to comment.