Skip to content

Commit 55387d3

Browse files
committed
Made more Driver APIs internal
1 parent 76b4b72 commit 55387d3

22 files changed

+159
-136
lines changed

Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public Region? Clip
5757
/// Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
5858
/// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
5959
/// </summary>
60-
public int Col { get; internal set; }
60+
internal int Col { get; private set; }
6161

6262
/// <summary>The number of columns visible in the terminal.</summary>
63-
public virtual int Cols
63+
internal virtual int Cols
6464
{
6565
get => _cols;
66-
internal set
66+
set
6767
{
6868
_cols = value;
6969
ClearContents ();
@@ -75,30 +75,30 @@ internal set
7575
/// <see cref="UpdateScreen"/> is called.
7676
/// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
7777
/// </summary>
78-
public Cell [,]? Contents { get; internal set; }
78+
internal Cell [,]? Contents { get; set; }
7979

8080
/// <summary>The leftmost column in the terminal.</summary>
81-
public virtual int Left { get; internal set; } = 0;
81+
internal virtual int Left { get; set; } = 0;
8282

8383
/// <summary>
8484
/// Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
8585
/// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
8686
/// </summary>
87-
public int Row { get; internal set; }
87+
internal int Row { get; private set; }
8888

8989
/// <summary>The number of rows visible in the terminal.</summary>
90-
public virtual int Rows
90+
internal virtual int Rows
9191
{
9292
get => _rows;
93-
internal set
93+
set
9494
{
9595
_rows = value;
9696
ClearContents ();
9797
}
9898
}
9999

100100
/// <summary>The topmost row in the terminal.</summary>
101-
public virtual int Top { get; internal set; } = 0;
101+
internal virtual int Top { get; set; } = 0;
102102

103103
/// <summary>
104104
/// Set this to true in any unit tests that attempt to test drivers other than FakeDriver.
@@ -125,7 +125,7 @@ internal set
125125
/// </para>
126126
/// </remarks>
127127
/// <param name="rune">Rune to add.</param>
128-
public void AddRune (Rune rune)
128+
internal void AddRune (Rune rune)
129129
{
130130
int runeWidth = -1;
131131
bool validLocation = IsValidLocation (rune, Col, Row);
@@ -300,7 +300,7 @@ public void AddRune (Rune rune)
300300
/// convenience method that calls <see cref="AddRune(Rune)"/> with the <see cref="Rune"/> constructor.
301301
/// </summary>
302302
/// <param name="c">Character to add.</param>
303-
public void AddRune (char c) { AddRune (new Rune (c)); }
303+
internal void AddRune (char c) { AddRune (new Rune (c)); }
304304

305305
/// <summary>Adds the <paramref name="str"/> to the display at the cursor position.</summary>
306306
/// <remarks>

Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ internal class CursesDriver : ConsoleDriver
1919
private UnixMainLoop _mainLoopDriver;
2020
private object _processInputToken;
2121

22-
public override int Cols
22+
internal override int Cols
2323
{
2424
get => Curses.Cols;
25-
internal set
25+
set
2626
{
2727
Curses.Cols = value;
2828
ClearContents ();
2929
}
3030
}
3131

32-
public override int Rows
32+
internal override int Rows
3333
{
3434
get => Curses.Lines;
35-
internal set
35+
set
3636
{
3737
Curses.Lines = value;
3838
ClearContents ();

Terminal.Gui/Drawing/Ruler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
namespace Terminal.Gui;
1+
#nullable enable
2+
namespace Terminal.Gui;
23

34
/// <summary>Draws a ruler on the screen.</summary>
45
/// <remarks>
56
/// <para></para>
67
/// </remarks>
7-
public class Ruler
8+
internal class Ruler
89
{
910
/// <summary>Gets or sets the foreground and background color to use.</summary>
1011
public Attribute Attribute { get; set; } = new ();
@@ -36,7 +37,7 @@ public void Draw (Point location, int start = 0)
3637
if (Orientation == Orientation.Horizontal)
3738
{
3839
string hrule =
39-
_hTemplate.Repeat ((int)Math.Ceiling (Length + 2 / (double)_hTemplate.Length)) [start..(Length + start)];
40+
_hTemplate.Repeat ((int)Math.Ceiling (Length + 2 / (double)_hTemplate.Length))! [start..(Length + start)];
4041

4142
// Top
4243
Application.Driver?.Move (location.X, location.Y);
@@ -45,7 +46,7 @@ public void Draw (Point location, int start = 0)
4546
else
4647
{
4748
string vrule =
48-
_vTemplate.Repeat ((int)Math.Ceiling ((Length + 2) / (double)_vTemplate.Length))
49+
_vTemplate.Repeat ((int)Math.Ceiling ((Length + 2) / (double)_vTemplate.Length))!
4950
[start..(Length + start)];
5051

5152
for (int r = location.Y; r < location.Y + Length; r++)

Terminal.Gui/View/View.Drawing.Primitives.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Terminal.Gui;
1+
using static Terminal.Gui.SpinnerStyle;
2+
3+
namespace Terminal.Gui;
24

35
public partial class View
46
{
@@ -31,6 +33,21 @@ public bool Move (int col, int row)
3133
return true;
3234
}
3335

36+
/// <summary>Draws the specified character at the current draw position.</summary>
37+
/// <param name="rune">The Rune.</param>
38+
public void AddRune (Rune rune)
39+
{
40+
Driver?.AddRune (rune);
41+
}
42+
43+
44+
/// <summary>
45+
/// Adds the specified <see langword="char"/> to the display at the current cursor position. This method is a
46+
/// convenience method that calls <see cref="AddRune(Rune)"/> with the <see cref="Rune"/> constructor.
47+
/// </summary>
48+
/// <param name="c">Character to add.</param>
49+
public void AddRune (char c) { AddRune (new Rune (c)); }
50+
3451
/// <summary>Draws the specified character in the specified viewport-relative column and row of the View.</summary>
3552
/// <para>
3653
/// If the provided coordinates are outside the visible content area, this method does nothing.
@@ -49,6 +66,21 @@ public void AddRune (int col, int row, Rune rune)
4966
}
5067
}
5168

69+
70+
/// <summary>Adds the <paramref name="str"/> to the display at the cursor position.</summary>
71+
/// <remarks>
72+
/// <para>
73+
/// When the method returns, <see cref="Col"/> will be incremented by the number of columns
74+
/// <paramref name="str"/> required, unless the new column value is outside of the <see cref="Clip"/> or screen
75+
/// dimensions defined by <see cref="Cols"/>.
76+
/// </para>
77+
/// <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para>
78+
/// </remarks>
79+
/// <param name="str">String.</param>
80+
public void AddStr (string str)
81+
{
82+
Driver?.AddStr (str);
83+
}
5284
/// <summary>Utility function to draw strings that contain a hotkey.</summary>
5385
/// <param name="text">String to display, the hotkey specifier before a letter flags the next letter as the hotkey.</param>
5486
/// <param name="hotColor">Hot color.</param>
@@ -74,7 +106,7 @@ public void DrawHotString (string text, Attribute hotColor, Attribute normalColo
74106
continue;
75107
}
76108

77-
Application.Driver?.AddRune (rune);
109+
AddRune (rune);
78110
SetAttribute (normalColor);
79111
}
80112
}
@@ -121,4 +153,5 @@ public void FillRect (Rectangle rect, Color? color = null)
121153
SetAttribute (prev);
122154
SetClip (prevClip);
123155
}
156+
124157
}

Terminal.Gui/Views/ColorPicker.16.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ private void DrawColorBox (int x, int y, bool selected)
222222
{
223223
for (var zoomedX = 0; zoomedX < BoxWidth; zoomedX++)
224224
{
225-
Move (x * BoxWidth + zoomedX, y * BoxHeight + zoomedY);
226-
Driver?.AddRune ((Rune)' ');
225+
AddRune (x * BoxWidth + zoomedX, y * BoxHeight + zoomedY, (Rune)' ');
227226
index++;
228227
}
229228
}

Terminal.Gui/Views/ComboBox.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ protected override bool OnDrawingContent ()
306306
{
307307
SetAttribute (ColorScheme.Focus);
308308
}
309-
Move (Viewport.Right - 1, 0);
310-
Driver?.AddRune (Glyphs.DownArrow);
309+
AddRune (Viewport.Right - 1, 0, Glyphs.DownArrow);
311310

312311
return true;
313312
}
@@ -932,7 +931,7 @@ protected override bool OnDrawingContent ()
932931
{
933932
for (var c = 0; c < f.Width; c++)
934933
{
935-
Driver?.AddRune ((Rune)' ');
934+
AddRune (0, row, (Rune)' ');
936935
}
937936
}
938937
else
@@ -948,14 +947,14 @@ protected override bool OnDrawingContent ()
948947

949948
if (AllowsMarking)
950949
{
951-
Driver?.AddRune (
950+
AddRune (
952951
Source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
953952
AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
954953
);
955-
Driver?.AddRune ((Rune)' ');
954+
AddRune ((Rune)' ');
956955
}
957956

958-
Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);
957+
Source.Render (this, isSelected, item, col, row, f.Width - col, start);
959958
}
960959
}
961960

Terminal.Gui/Views/ListView.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public interface IListDataSource : IDisposable
3333
/// <summary>This method is invoked to render a specified item, the method should cover the entire provided width.</summary>
3434
/// <returns>The render.</returns>
3535
/// <param name="container">The list view to render.</param>
36-
/// <param name="driver">The console driver to render.</param>
3736
/// <param name="selected">Describes whether the item being rendered is currently selected by the user.</param>
3837
/// <param name="item">The index of the item to render, zero for the first item and so on.</param>
3938
/// <param name="col">The column where the rendering will start</param>
@@ -46,7 +45,6 @@ public interface IListDataSource : IDisposable
4645
/// </remarks>
4746
void Render (
4847
ListView container,
49-
ConsoleDriver driver,
5048
bool selected,
5149
int item,
5250
int col,
@@ -88,7 +86,7 @@ void Render (
8886
/// </para>
8987
/// <para>
9088
/// To change the contents of the ListView, set the <see cref="Source"/> property (when providing custom
91-
/// rendering via <see cref="IListDataSource"/>) or call <see cref="SetSource"/> an <see cref="IList"/> is being
89+
/// rendering via <see cref="IListDataSource"/>) or call <see cref="SetSource{T}"/> an <see cref="IList"/> is being
9290
/// used.
9391
/// </para>
9492
/// <para>
@@ -822,7 +820,7 @@ protected override bool OnDrawingContent ()
822820
Driver?.AddRune ((Rune)' ');
823821
}
824822

825-
Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);
823+
Source.Render (this, isSelected, item, col, row, f.Width - col, start);
826824
}
827825
}
828826
return true;
@@ -1116,7 +1114,6 @@ private void CheckAndResizeMarksIfRequired ()
11161114
/// <inheritdoc/>
11171115
public void Render (
11181116
ListView container,
1119-
ConsoleDriver driver,
11201117
bool marked,
11211118
int item,
11221119
int col,
@@ -1133,17 +1130,17 @@ public void Render (
11331130

11341131
if (t is null)
11351132
{
1136-
RenderUstr (driver, "", col, line, width);
1133+
RenderUstr (container, "", col, line, width);
11371134
}
11381135
else
11391136
{
11401137
if (t is string s)
11411138
{
1142-
RenderUstr (driver, s, col, line, width, start);
1139+
RenderUstr (container, s, col, line, width, start);
11431140
}
11441141
else
11451142
{
1146-
RenderUstr (driver, t.ToString (), col, line, width, start);
1143+
RenderUstr (container, t.ToString (), col, line, width, start);
11471144
}
11481145
}
11491146
}
@@ -1239,7 +1236,7 @@ private int GetMaxLengthItem ()
12391236
return maxLength;
12401237
}
12411238

1242-
private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0)
1239+
private void RenderUstr (View driver, string ustr, int col, int line, int width, int start = 0)
12431240
{
12441241
string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (Math.Min (start, ustr.ToRunes ().Length - 1));
12451242
string u = TextFormatter.ClipAndJustify (str, width, Alignment.Start);

Terminal.Gui/Views/ProgressBar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected override bool OnDrawingContent ()
141141
{
142142
for (var i = 0; i < Viewport.Width; i++)
143143
{
144-
if (Array.IndexOf (_activityPos, i) != -1)
144+
if (Array.IndexOf (_activityPos!, i) != -1)
145145
{
146146
Driver?.AddRune (SegmentCharacter);
147147
}

Terminal.Gui/Views/Shortcut.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ void CommandViewOnSelecting (object? sender, CommandEventArgs e)
495495

496496
private void SetCommandViewDefaultLayout ()
497497
{
498-
CommandView.Margin.Thickness = GetMarginThickness ();
498+
if (CommandView.Margin is { })
499+
{
500+
CommandView.Margin.Thickness = GetMarginThickness ();
501+
}
502+
499503
CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
500504

501505
CommandView.VerticalTextAlignment = Alignment.Center;

0 commit comments

Comments
 (0)