Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/UICatalog/Scenarios/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public override void Main ()
appKeyListView.SchemeName = "Runnable";
win.Add (onSwallowedListView);

Application.Driver!.InputProcessor.AnsiSequenceSwallowed += (s, e) => { swallowedList.Add (e.Replace ("\x1b", "Esc")); };
Application.Driver!.GetInputProcessor ().AnsiSequenceSwallowed += (s, e) => { swallowedList.Add (e.Replace ("\x1b", "Esc")); };

Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down");
Application.KeyUp += (s, a) => KeyDownPressUp (a, "Up");
Expand Down
86 changes: 78 additions & 8 deletions Examples/UICatalog/Scenarios/WideGlyphs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void Main ()
};

// Build the array of codepoints once when subviews are laid out
appWindow.SubViewsLaidOut += (s, e) =>
appWindow.SubViewsLaidOut += (s, _) =>
{
View? view = s as View;
if (view is null)
Expand All @@ -34,8 +34,8 @@ public override void Main ()
}

// Only rebuild if size changed or array is null
if (_codepoints is null ||
_codepoints.GetLength (0) != view.Viewport.Height ||
if (_codepoints is null ||
_codepoints.GetLength (0) != view.Viewport.Height ||
_codepoints.GetLength (1) != view.Viewport.Width)
{
_codepoints = new Rune [view.Viewport.Height, view.Viewport.Width];
Expand All @@ -51,7 +51,9 @@ public override void Main ()
};

// Fill the window with the pre-built codepoints array
appWindow.DrawingContent += (s, e) =>
// For detailed documentation on the draw code flow from Application.Run to this event,
// see WideGlyphs.DrawFlow.md in this directory
appWindow.DrawingContent += (s, _) =>
{
View? view = s as View;
if (view is null || _codepoints is null)
Expand All @@ -73,15 +75,15 @@ public override void Main ()
}
};

Line verticalLineAtEven = new Line ()
Line verticalLineAtEven = new ()
{
X = 10,
Orientation = Orientation.Vertical,
Length = Dim.Fill ()
};
appWindow.Add (verticalLineAtEven);

Line verticalLineAtOdd = new Line ()
Line verticalLineAtOdd = new ()
{
X = 25,
Orientation = Orientation.Vertical,
Expand All @@ -97,8 +99,12 @@ public override void Main ()
Y = 5,
Width = 15,
Height = 5,
BorderStyle = LineStyle.Dashed,
//BorderStyle = LineStyle.Dashed,
};

// Proves it's not LineCanvas related
arrangeableViewAtEven!.Border!.Thickness = new (1);
arrangeableViewAtEven.Border.Add(new View () { Height = Dim.Auto(), Width = Dim.Auto(), Text = "Even" });
appWindow.Add (arrangeableViewAtEven);

View arrangeableViewAtOdd = new ()
Expand All @@ -112,6 +118,70 @@ public override void Main ()
BorderStyle = LineStyle.Dashed,
};
appWindow.Add (arrangeableViewAtOdd);

var superView = new View
{
CanFocus = true,
X = 30, // on an even column to start
Y = Pos.Center (),
Width = Dim.Auto () + 4,
Height = Dim.Auto () + 1,
BorderStyle = LineStyle.Single,
Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable
};

Rune codepoint = Glyphs.Apple;

superView.DrawingContent += (s, e) =>
{
var view = s as View;
for (var r = 0; r < view!.Viewport.Height; r++)
{
for (var c = 0; c < view.Viewport.Width; c += 2)
{
if (codepoint != default (Rune))
{
view.AddRune (c, r, codepoint);
}
}
}
e.DrawContext?.AddDrawnRectangle (view.Viewport);
e.Cancel = true;
};
appWindow.Add (superView);

var viewWithBorderAtX0 = new View
{
Text = "viewWithBorderAtX0",
BorderStyle = LineStyle.Dashed,
X = 0,
Y = 1,
Width = Dim.Auto (),
Height = 3
};

var viewWithBorderAtX1 = new View
{
Text = "viewWithBorderAtX1",
BorderStyle = LineStyle.Dashed,
X = 1,
Y = Pos.Bottom (viewWithBorderAtX0) + 1,
Width = Dim.Auto (),
Height = 3
};

var viewWithBorderAtX2 = new View
{
Text = "viewWithBorderAtX2",
BorderStyle = LineStyle.Dashed,
X = 2,
Y = Pos.Bottom (viewWithBorderAtX1) + 1,
Width = Dim.Auto (),
Height = 3
};

superView.Add (viewWithBorderAtX0, viewWithBorderAtX1, viewWithBorderAtX2);

// Run - Start the application.
Application.Run (appWindow);
appWindow.Dispose ();
Expand All @@ -124,6 +194,6 @@ private Rune GetRandomWideCodepoint ()
{
Random random = new ();
int codepoint = random.Next (0x4E00, 0x9FFF);
return new Rune (codepoint);
return new (codepoint);
}
}
3 changes: 2 additions & 1 deletion Terminal.Gui/Drivers/DotNetDriver/NetOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected override void AppendOrWriteAttribute (StringBuilder output, Attribute
/// <inheritdoc />
protected override void Write (StringBuilder output)
{
base.Write (output);
try
{
Console.Out.Write (output);
Expand Down Expand Up @@ -140,7 +141,7 @@ protected override bool SetCursorPositionImpl (int col, int row)
}
catch (Exception)
{
return false;
return true;
}
}

Expand Down
35 changes: 21 additions & 14 deletions Terminal.Gui/Drivers/DriverImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public DriverImpl (
ISizeMonitor sizeMonitor
)
{
InputProcessor = inputProcessor;
_inputProcessor = inputProcessor;
_output = output;
OutputBuffer = outputBuffer;
_ansiRequestScheduler = ansiRequestScheduler;

InputProcessor.KeyDown += (s, e) => KeyDown?.Invoke (s, e);
InputProcessor.KeyUp += (s, e) => KeyUp?.Invoke (s, e);
GetInputProcessor ().KeyDown += (s, e) => KeyDown?.Invoke (s, e);
GetInputProcessor ().KeyUp += (s, e) => KeyUp?.Invoke (s, e);

InputProcessor.MouseEvent += (s, e) =>
{
//Logging.Logger.LogTrace ($"Mouse {e.Flags} at x={e.ScreenPosition.X} y={e.ScreenPosition.Y}");
MouseEvent?.Invoke (s, e);
};
GetInputProcessor ().MouseEvent += (s, e) =>
{
//Logging.Logger.LogTrace ($"Mouse {e.Flags} at x={e.ScreenPosition.X} y={e.ScreenPosition.Y}");
MouseEvent?.Invoke (s, e);
};

SizeMonitor = sizeMonitor;
SizeMonitor.SizeChanged += OnSizeMonitorOnSizeChanged;
Expand All @@ -73,15 +73,18 @@ ISizeMonitor sizeMonitor
public void Init () { throw new NotSupportedException (); }

/// <inheritdoc/>
public void Refresh () { _output.Write (OutputBuffer); }
public void Refresh ()
{
_output.Write (OutputBuffer);
}

/// <inheritdoc/>
public string? GetName () => InputProcessor.DriverName?.ToLowerInvariant ();
public string? GetName () => GetInputProcessor ().DriverName?.ToLowerInvariant ();

/// <inheritdoc/>
public virtual string GetVersionInfo ()
{
string type = InputProcessor.DriverName ?? throw new ArgumentNullException (nameof (InputProcessor.DriverName));
string type = GetInputProcessor ().DriverName ?? throw new InvalidOperationException ("Driver name is not set.");

return type;
}
Expand Down Expand Up @@ -143,8 +146,12 @@ public void Dispose ()

private readonly IOutput _output;

public IOutput GetOutput () => _output;

private readonly IInputProcessor _inputProcessor;

/// <inheritdoc/>
public IInputProcessor InputProcessor { get; }
public IInputProcessor GetInputProcessor () => _inputProcessor;

/// <inheritdoc/>
public IOutputBuffer OutputBuffer { get; }
Expand All @@ -157,7 +164,7 @@ public void Dispose ()

private void CreateClipboard ()
{
if (InputProcessor.DriverName is { } && InputProcessor.DriverName.Contains ("fake"))
if (GetInputProcessor ().DriverName is { } && GetInputProcessor ()!.DriverName!.Contains ("fake"))
{
if (Clipboard is null)
{
Expand Down Expand Up @@ -414,7 +421,7 @@ public bool SetCursorVisibility (CursorVisibility visibility)
public event EventHandler<Key>? KeyUp;

/// <inheritdoc/>
public void EnqueueKeyEvent (Key key) { InputProcessor.EnqueueKeyDownEvent (key); }
public void EnqueueKeyEvent (Key key) { GetInputProcessor ().EnqueueKeyDownEvent (key); }

#endregion Input Events

Expand Down
40 changes: 20 additions & 20 deletions Terminal.Gui/Drivers/FakeDriver/FakeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ namespace Terminal.Gui.Drivers;
/// </summary>
public class FakeOutput : OutputBase, IOutput
{
private readonly StringBuilder _output = new ();
// private readonly StringBuilder _outputStringBuilder = new ();
private int _cursorLeft;
private int _cursorTop;
private Size _consoleSize = new (80, 25);
private IOutputBuffer? _lastBuffer;

/// <summary>
///
/// </summary>
public FakeOutput ()
{
LastBuffer = new OutputBufferImpl ();
LastBuffer.SetSize (80, 25);
_lastBuffer = new OutputBufferImpl ();
_lastBuffer.SetSize (80, 25);
}

/// <summary>
/// Gets or sets the last output buffer written.
/// Gets or sets the last output buffer written. The <see cref="IOutputBuffer.Contents"/> contains
/// a reference to the buffer last written with <see cref="Write(IOutputBuffer)"/>.
/// </summary>
public IOutputBuffer? LastBuffer { get; set; }
public IOutputBuffer? GetLastBuffer () => _lastBuffer;

/// <summary>
/// Gets the captured output as a string.
/// </summary>
public string Output => _output.ToString ();
///// <inheritdoc cref="IOutput.GetLastOutput"/>
//public override string GetLastOutput () => _outputStringBuilder.ToString ();

/// <inheritdoc />
public Point GetCursorPosition ()
Expand Down Expand Up @@ -61,28 +61,28 @@ protected override bool SetCursorPositionImpl (int col, int row)
/// <inheritdoc/>
public void Write (ReadOnlySpan<char> text)
{
_output.Append (text);
// _outputStringBuilder.Append (text);
}

/// <inheritdoc cref="IDriver"/>
/// <inheritdoc cref="IOutput.Write(IOutputBuffer)"/>
public override void Write (IOutputBuffer buffer)
{
LastBuffer = buffer;
_lastBuffer = buffer;
base.Write (buffer);
}

///// <inheritdoc/>
//protected override void Write (StringBuilder output)
//{
// _outputStringBuilder.Append (output);
//}

/// <inheritdoc cref="IDriver"/>
public override void SetCursorVisibility (CursorVisibility visibility)
{
// Capture but don't act on it in fake output
}

/// <inheritdoc/>
public void Dispose ()
{
// Nothing to dispose
}

/// <inheritdoc/>
protected override void AppendOrWriteAttribute (StringBuilder output, Attribute attr, TextStyle redrawTextStyle)
{
Expand Down Expand Up @@ -123,8 +123,8 @@ protected override void AppendOrWriteAttribute (StringBuilder output, Attribute
}

/// <inheritdoc/>
protected override void Write (StringBuilder output)
public void Dispose ()
{
_output.Append (output);
// Nothing to dispose
}
}
7 changes: 6 additions & 1 deletion Terminal.Gui/Drivers/IDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public interface IDriver : IDisposable
/// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
/// and detecting and processing ansi escape sequences.
/// </summary>
IInputProcessor InputProcessor { get; }
IInputProcessor GetInputProcessor ();

/// <summary>
/// Gets the output handler responsible for writing to the terminal.
/// </summary>
IOutput GetOutput ();

/// <summary>Get the operating system clipboard.</summary>
IClipboard? Clipboard { get; }
Expand Down
6 changes: 6 additions & 0 deletions Terminal.Gui/Drivers/IOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public interface IOutput : IDisposable
/// <param name="buffer"></param>
void Write (IOutputBuffer buffer);

/// <summary>
/// Gets a string containing the ANSI escape sequences and content most recently written
/// to the terminal via <see cref="Write(IOutputBuffer)"/>
/// </summary>
string GetLastOutput ();

/// <summary>
/// Generates an ANSI escape sequence string representation of the given <paramref name="buffer"/> contents.
/// This is the same output that would be written to the terminal to recreate the current screen contents.
Expand Down
Loading
Loading