Skip to content

Commit e965afd

Browse files
committed
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
2 parents 1137d7d + 6e8fb2f commit e965afd

File tree

6 files changed

+45
-27
lines changed

6 files changed

+45
-27
lines changed

.vscode/tasks.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
"args": [
1717
"-c",
1818
"Invoke-Build",
19-
"Build"
19+
// Build both modules
20+
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools, Microsoft.PowerShell.ConsoleGuiTools",
21+
// Build only Out-GridView
22+
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools",
23+
// Build only Out-ConsoleGridView
24+
"Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools",
2025
],
2126
"problemMatcher": "$msCompile",
2227
"group": {

Build.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
Invoke-Build Build
2-
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Process | Out-GridView -PassThru"
3-
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Process | Out-ConsoleGridView -OutputMode Single"
1+
# Build script for buildling/testing from the commnad line. See tasks.json for how build is invoked within VS Code
2+
# GraphicalTools includes two modules: Microsoft.PowerShell.GraphicalTools and Microsoft.PowerShell.ConsoleGuiTools
3+
# To build them all leave -ModuleName off the `InvokeBuild` command (e.g. Invoke-Build Build).
4+
# To build only one, specify it using the -ModuleName paramater (e.g. Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools).
5+
6+
# Build...
7+
Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools
8+
9+
# Run what was built...
10+
# pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Module -all | Out-GridView -OutputMode Single -Title 'Imported Modules'
11+
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Module -all | Out-ConsoleGridView -OutputMode Single -Title 'Imported Modules' -Filter power"

GraphicalTools.build.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ param(
33
[ValidateSet("Debug", "Release")]
44
[string]$Configuration = "Debug",
55

6-
[string[]]$ModuleName = @( "Microsoft.PowerShell.GraphicalTools", "Microsoft.PowerShell.ConsoleGuiTools" )
6+
[string[]]$ModuleName = @(
7+
"Microsoft.PowerShell.GraphicalTools",
8+
"Microsoft.PowerShell.ConsoleGuiTools" )
79
)
810

911
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ namespace OutGridView.Cmdlet
1414
internal class ConsoleGui : IDisposable
1515
{
1616
private const string FILTER_LABEL = "Filter";
17+
// This adjusts the left margin of all controls
18+
private const int MARGIN_LEFT = 2;
19+
// Width of Terminal.Gui ListView selection/check UI elements (old == 4, new == 2)
20+
private const int CHECK_WIDTH = 4;
1721
private bool _cancelled;
1822
private GridViewDataSource _itemSource;
23+
private Label _filterLabel;
1924
private TextField _filterField;
2025
private ListView _listView;
2126
private ApplicationData _applicationData;
@@ -28,9 +33,8 @@ public HashSet<int> Start(ApplicationData applicationData)
2833
_gridViewDetails = new GridViewDetails
2934
{
3035
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
31-
// they have a 8 character addition of a checkbox (".....[ ]" or ".....( )")
32-
// that we have to factor in.
33-
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
36+
// 2 columns are required for the check/selection indicator and space.
37+
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? MARGIN_LEFT + CHECK_WIDTH : MARGIN_LEFT
3438
};
3539

3640
Window win = AddTopLevelWindow();
@@ -91,7 +95,7 @@ private Window AddTopLevelWindow()
9195
Y = 0,
9296
// By using Dim.Fill(), it will automatically resize without manual intervention
9397
Width = Dim.Fill(),
94-
Height = Dim.Fill()
98+
Height = Dim.Fill(1)
9599
};
96100

97101
Application.Top.Add(win);
@@ -166,8 +170,7 @@ private void CalculateColumnWidths(List<string> gridHeaders)
166170
}
167171

168172
// if the total width is wider than the usable width, remove 1 from widest column until it fits
169-
// the gui loses 3 chars on the left and 2 chars on the right
170-
_gridViewDetails.UsableWidth = Application.Top.Frame.Width - 3 - listViewColumnWidths.Length - _gridViewDetails.ListViewOffset - 2;
173+
_gridViewDetails.UsableWidth = Application.Top.Frame.Width - MARGIN_LEFT - listViewColumnWidths.Length - _gridViewDetails.ListViewOffset;
171174
int columnWidthsSum = listViewColumnWidths.Sum();
172175
while (columnWidthsSum >= _gridViewDetails.UsableWidth)
173176
{
@@ -189,25 +192,25 @@ private void CalculateColumnWidths(List<string> gridHeaders)
189192

190193
private void AddFilter(Window win)
191194
{
192-
var filterLabel = new Label(FILTER_LABEL)
195+
_filterLabel = new Label(FILTER_LABEL)
193196
{
194-
X = 2
197+
X = MARGIN_LEFT
195198
};
196199

197200
_filterField = new TextField(string.Empty)
198201
{
199-
X = Pos.Right(filterLabel) + 1,
200-
Y = Pos.Top(filterLabel),
202+
X = Pos.Right(_filterLabel) + 1,
203+
Y = Pos.Top(_filterLabel),
201204
CanFocus = true,
202-
Width = Dim.Fill() - filterLabel.Text.Length
205+
Width = Dim.Fill() - _filterLabel.Text.Length
203206
};
204207

205208
var filterErrorLabel = new Label(string.Empty)
206209
{
207-
X = Pos.Right(filterLabel) + 1,
208-
Y = Pos.Top(filterLabel) + 1,
210+
X = Pos.Right(_filterLabel) + 1,
211+
Y = Pos.Top(_filterLabel) + 1,
209212
ColorScheme = Colors.Base,
210-
Width = Dim.Fill() - filterLabel.Text.Length
213+
Width = Dim.Fill() - _filterLabel.Text.Length
211214
};
212215

213216
_filterField.TextChanged += (str) =>
@@ -232,14 +235,14 @@ private void AddFilter(Window win)
232235
}
233236
};
234237

235-
win.Add(filterLabel, _filterField, filterErrorLabel);
238+
win.Add(_filterLabel, _filterField, filterErrorLabel);
236239
}
237240

238241
private void AddHeaders(Window win, List<string> gridHeaders)
239242
{
240243
var header = new Label(GridViewHelpers.GetPaddedString(
241244
gridHeaders,
242-
_gridViewDetails.ListViewOffset + _gridViewDetails.ListViewOffset - 1,
245+
_gridViewDetails.ListViewOffset,
243246
_gridViewDetails.ListViewColumnWidths))
244247
{
245248
X = 0,
@@ -286,7 +289,7 @@ private void LoadData()
286289
valueList.Add(dataValue);
287290
}
288291

289-
string displayString = GridViewHelpers.GetPaddedString(valueList, _gridViewDetails.ListViewOffset, _gridViewDetails.ListViewColumnWidths);
292+
string displayString = GridViewHelpers.GetPaddedString(valueList, 0, _gridViewDetails.ListViewColumnWidths);
290293

291294
items.Add(new GridViewRow
292295
{
@@ -304,10 +307,10 @@ private void AddRows(Window win)
304307
{
305308
_listView = new ListView(_itemSource)
306309
{
307-
X = 3,
308-
Y = 4,
310+
X = Pos.Left(_filterLabel),
311+
Y = Pos.Bottom(_filterLabel) + 3, // 1 for space, 1 for header, 1 for header underline
309312
Width = Dim.Fill(2),
310-
Height = Dim.Fill(2),
313+
Height = Dim.Fill(),
311314
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
312315
AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple,
313316
};

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void RenderUstr(ConsoleDriver driver, ustring ustr, int col, int line, i
4747
{
4848
(var rune, var size) = Utf8.DecodeRune(ustr, index, index - ustr.Length);
4949
var count = Rune.ColumnWidth(rune);
50-
if (used + count >= width) break;
50+
if (used + count > width) break;
5151
driver.AddRune(rune);
5252
used += count;
5353
index += size;

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class GridViewDetails
88
// Contains the width of each column in the grid view.
99
public int[] ListViewColumnWidths { get; set; }
1010

11-
// Dictates where the grid should actually start considering
11+
// Dictates where the header should actually start considering
1212
// some offset is needed to factor in the checkboxes
1313
public int ListViewOffset { get; set; }
1414

0 commit comments

Comments
 (0)