@@ -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 } ;
0 commit comments