Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6af1903
Fixed #58: Multi-line commands rendering wrong
tig Mar 11, 2020
a69373e
Fixed #58 - Newlines in commands render incorrectly
tig Mar 11, 2020
f155262
Added debug instructions to readme
tig Mar 11, 2020
440833e
Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs
tig Mar 11, 2020
dd2e765
simplified stripping of newline/linefeed
tig Mar 12, 2020
e66f614
Merge branch 'master' of tig:tig/GraphicalTools
tig Mar 14, 2020
ebcb92f
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Apr 12, 2020
dce01c8
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Apr 17, 2020
a2c0238
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Apr 19, 2020
2184386
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Apr 19, 2020
668c5c5
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Apr 20, 2020
9d2c85a
Merge branch 'master' of tig:tig/GraphicalTools
tig May 13, 2020
d15fb38
Merge branch 'master' of tig:PowerShell/GraphicalTools
tig Aug 24, 2020
49b9559
Merge branch 'master' of tig:tig/GraphicalTools into master
tig Sep 25, 2020
4175dc0
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Sep 27, 2020
53b1203
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Sep 27, 2020
941cef7
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Sep 29, 2020
06c8a1f
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Sep 29, 2020
474826e
made column spacing tigher
tig Sep 29, 2020
3112550
update to new Terminal.gui package; no code changes
tig Sep 29, 2020
67911d3
tweaked widths
tig Sep 29, 2020
86a72b5
removed excess padding on right
tig Sep 29, 2020
c95abc5
removed excess rows at bottom
tig Sep 29, 2020
869b578
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Sep 29, 2020
bed1c3d
Merge branch 'master' into tighter_columns
tig Sep 29, 2020
142ffe5
status bar wsa occluding window
tig Sep 29, 2020
fd934e1
fixed build scripts to only build ocgv
tig Oct 1, 2020
aac2d2c
use built-in command in build.ps1
tig Oct 2, 2020
9db8c90
fixed the other one too
tig Oct 3, 2020
1137d7d
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
tig Oct 3, 2020
b1ffbe9
Merge branch 'master' into tighter_columns
tig Oct 3, 2020
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
7 changes: 6 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
"args": [
"-c",
"Invoke-Build",
"Build"
// Build both modules
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools, Microsoft.PowerShell.ConsoleGuiTools",
// Build only Out-GridView
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools",
// Build only Out-ConsoleGridView
"Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools",
],
"problemMatcher": "$msCompile",
"group": {
Expand Down
14 changes: 11 additions & 3 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Invoke-Build Build
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Process | Out-GridView -PassThru"
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Process | Out-ConsoleGridView -OutputMode Single"
# Build script for buildling/testing from the commnad line. See tasks.json for how build is invoked within VS Code
# GraphicalTools includes two modules: Microsoft.PowerShell.GraphicalTools and Microsoft.PowerShell.ConsoleGuiTools
# To build them all leave -ModuleName off the `InvokeBuild` command (e.g. Invoke-Build Build).
# To build only one, specify it using the -ModuleName paramater (e.g. Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools).

# Build...
Invoke-Build Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools

# Run what was built...
# pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Module -all | Out-GridView -OutputMode Single -Title 'Imported Modules'
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Module -all | Out-ConsoleGridView -OutputMode Single -Title 'Imported Modules' -Filter power"
4 changes: 3 additions & 1 deletion GraphicalTools.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",

[string[]]$ModuleName = @( "Microsoft.PowerShell.GraphicalTools", "Microsoft.PowerShell.ConsoleGuiTools" )
[string[]]$ModuleName = @(
"Microsoft.PowerShell.GraphicalTools",
"Microsoft.PowerShell.ConsoleGuiTools" )
)

$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
Expand Down
43 changes: 23 additions & 20 deletions src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ namespace OutGridView.Cmdlet
internal class ConsoleGui : IDisposable
{
private const string FILTER_LABEL = "Filter";
// This adjusts the left margin of all controls
private const int MARGIN_LEFT = 2;
// Width of Terminal.Gui ListView selection/check UI elements (old == 4, new == 2)
private const int CHECK_WIDTH = 4;
private bool _cancelled;
private GridViewDataSource _itemSource;
private Label _filterLabel;
private TextField _filterField;
private ListView _listView;
private ApplicationData _applicationData;
Expand All @@ -28,9 +33,8 @@ public HashSet<int> Start(ApplicationData applicationData)
_gridViewDetails = new GridViewDetails
{
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
// they have a 8 character addition of a checkbox (".....[ ]" or ".....( )")
// that we have to factor in.
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
// 2 columns are required for the check/selection indicator and space.
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? MARGIN_LEFT + CHECK_WIDTH : MARGIN_LEFT
};

Window win = AddTopLevelWindow();
Expand Down Expand Up @@ -91,7 +95,7 @@ private Window AddTopLevelWindow()
Y = 0,
// By using Dim.Fill(), it will automatically resize without manual intervention
Width = Dim.Fill(),
Height = Dim.Fill()
Height = Dim.Fill(1)
};

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

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

private void AddFilter(Window win)
{
var filterLabel = new Label(FILTER_LABEL)
_filterLabel = new Label(FILTER_LABEL)
{
X = 2
X = MARGIN_LEFT
};

_filterField = new TextField(string.Empty)
{
X = Pos.Right(filterLabel) + 1,
Y = Pos.Top(filterLabel),
X = Pos.Right(_filterLabel) + 1,
Y = Pos.Top(_filterLabel),
CanFocus = true,
Width = Dim.Fill() - filterLabel.Text.Length
Width = Dim.Fill() - _filterLabel.Text.Length
};

var filterErrorLabel = new Label(string.Empty)
{
X = Pos.Right(filterLabel) + 1,
Y = Pos.Top(filterLabel) + 1,
X = Pos.Right(_filterLabel) + 1,
Y = Pos.Top(_filterLabel) + 1,
ColorScheme = Colors.Base,
Width = Dim.Fill() - filterLabel.Text.Length
Width = Dim.Fill() - _filterLabel.Text.Length
};

_filterField.TextChanged += (str) =>
Expand All @@ -232,14 +235,14 @@ private void AddFilter(Window win)
}
};

win.Add(filterLabel, _filterField, filterErrorLabel);
win.Add(_filterLabel, _filterField, filterErrorLabel);
}

private void AddHeaders(Window win, List<string> gridHeaders)
{
var header = new Label(GridViewHelpers.GetPaddedString(
gridHeaders,
_gridViewDetails.ListViewOffset + _gridViewDetails.ListViewOffset - 1,
_gridViewDetails.ListViewOffset,
_gridViewDetails.ListViewColumnWidths))
{
X = 0,
Expand Down Expand Up @@ -286,7 +289,7 @@ private void LoadData()
valueList.Add(dataValue);
}

string displayString = GridViewHelpers.GetPaddedString(valueList, _gridViewDetails.ListViewOffset, _gridViewDetails.ListViewColumnWidths);
string displayString = GridViewHelpers.GetPaddedString(valueList, 0, _gridViewDetails.ListViewColumnWidths);

items.Add(new GridViewRow
{
Expand All @@ -304,10 +307,10 @@ private void AddRows(Window win)
{
_listView = new ListView(_itemSource)
{
X = 3,
Y = 4,
X = Pos.Left(_filterLabel),
Y = Pos.Bottom(_filterLabel) + 3, // 1 for space, 1 for header, 1 for header underline
Width = Dim.Fill(2),
Height = Dim.Fill(2),
Height = Dim.Fill(),
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void RenderUstr(ConsoleDriver driver, ustring ustr, int col, int line, i
{
(var rune, var size) = Utf8.DecodeRune(ustr, index, index - ustr.Length);
var count = Rune.ColumnWidth(rune);
if (used + count >= width) break;
if (used + count > width) break;
driver.AddRune(rune);
used += count;
index += size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class GridViewDetails
// Contains the width of each column in the grid view.
public int[] ListViewColumnWidths { get; set; }

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

Expand Down