summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-06-21 22:22:16 +0000
committerMike Buland <eichlan@xagasoft.com>2010-06-21 22:22:16 +0000
commit6feb3e31d7a6a614d7977afa4e48b07c25f6bb61 (patch)
tree3ca9f23aac01d1ea52d25a6fbf5076f6af3b43ca
parent6fdb5f76b3036e24dd3c99ec51c74405d8600bb7 (diff)
downloadlibbu++-6feb3e31d7a6a614d7977afa4e48b07c25f6bb61.tar.gz
libbu++-6feb3e31d7a6a614d7977afa4e48b07c25f6bb61.tar.bz2
libbu++-6feb3e31d7a6a614d7977afa4e48b07c25f6bb61.tar.xz
libbu++-6feb3e31d7a6a614d7977afa4e48b07c25f6bb61.zip
Little tweaks to the viewcsv program. I think I want to at least add a search
feature. Then I'm probably good.
-rw-r--r--src/tools/viewcsv.cpp63
1 files changed, 51 insertions, 12 deletions
diff --git a/src/tools/viewcsv.cpp b/src/tools/viewcsv.cpp
index 429c099..d6c09c9 100644
--- a/src/tools/viewcsv.cpp
+++ b/src/tools/viewcsv.cpp
@@ -10,10 +10,16 @@ using namespace Bu;
10class Options : public Bu::OptParser 10class Options : public Bu::OptParser
11{ 11{
12public: 12public:
13 Options( int argc, char *argv[] ) 13 Options( int argc, char *argv[] ) :
14 bHeader( true )
14 { 15 {
16 addOption( bHeader, "no-header",
17 "Don't use the first line as a header row. This behaviour can "
18 "also be toggled while running with 'h'." );
15 setNonOption( slot( this, &Options::onNonOption ) ); 19 setNonOption( slot( this, &Options::onNonOption ) );
16 addHelpOption(); 20 addHelpOption();
21
22 setOverride( "no-header", "true" );
17 parse( argc, argv ); 23 parse( argc, argv );
18 } 24 }
19 25
@@ -30,6 +36,7 @@ public:
30 } 36 }
31 37
32 Bu::FString sFileIn; 38 Bu::FString sFileIn;
39 bool bHeader;
33}; 40};
34 41
35typedef Bu::Array<StrArray> StrGrid; 42typedef Bu::Array<StrArray> StrGrid;
@@ -88,7 +95,7 @@ public:
88 int maxx, maxy; 95 int maxx, maxy;
89 getmaxyx( stdscr, maxy, maxx ); 96 getmaxyx( stdscr, maxy, maxx );
90 97
91 int iRows = min( (int)doc.sgData.getSize(), maxy-1 ); 98 int iRows = min( (int)doc.sgData.getSize(), maxy-((bHeaderRow)?(4):(3)) );
92 int iCols = min( doc.iMaxCols, (int)maxx-1 ); 99 int iCols = min( doc.iMaxCols, (int)maxx-1 );
93 100
94 int iHdrHeight = 1; 101 int iHdrHeight = 1;
@@ -98,6 +105,8 @@ public:
98 // Draw the headers 105 // Draw the headers
99 for( int iRow = 0; iRow < iRows; iRow++ ) 106 for( int iRow = 0; iRow < iRows; iRow++ )
100 { 107 {
108 if( iRow+iYOff >= doc.sgData.getSize() )
109 break;
101 char buf[6]; 110 char buf[6];
102 snprintf( buf, 6, "%5d", iRow+iYOff ); 111 snprintf( buf, 6, "%5d", iRow+iYOff );
103 mvaddnstr( iRow+iHdrHeight+1, 0, buf, 5 ); 112 mvaddnstr( iRow+iHdrHeight+1, 0, buf, 5 );
@@ -108,8 +117,9 @@ public:
108 { 117 {
109 for( int iCol = 0; iCol < iCols; iCol++ ) 118 for( int iCol = 0; iCol < iCols; iCol++ )
110 { 119 {
111 if( iXPos + doc.aWidths[iCol+iXOff]+2 >= maxx ) 120 if( iXPos >= maxx )
112 break; 121 break;
122 int iWidth = min( doc.aWidths[iCol+iXOff], maxx-iXPos-1 );
113 char buf[6]; 123 char buf[6];
114 snprintf( buf, 6, "%d", iCol+iXOff ); 124 snprintf( buf, 6, "%d", iCol+iXOff );
115 mvaddch( 0, iXPos, ACS_VLINE ); 125 mvaddch( 0, iXPos, ACS_VLINE );
@@ -117,17 +127,23 @@ public:
117 mvaddnstr( 0, iXPos+1, buf, 5 ); 127 mvaddnstr( 0, iXPos+1, buf, 5 );
118 if( bHeaderRow ) 128 if( bHeaderRow )
119 { 129 {
120 mvaddstr( 1, iXPos+1, doc.sgData[0][iCol+iXOff].getStr() ); 130 mvaddnstr(
131 1, iXPos+1, doc.sgData[0][iCol+iXOff].getStr(), iWidth
132 );
121 mvaddch( 1, iXPos, ACS_VLINE ); 133 mvaddch( 1, iXPos, ACS_VLINE );
122 } 134 }
123 for( int j = 0; j <= doc.aWidths[iCol+iXOff]; j++ ) 135 for( int j = 0; j < iWidth; j++ )
124 { 136 {
125 mvaddch( iHdrHeight, iXPos+j+1, ACS_HLINE ); 137 mvaddch( iHdrHeight, iXPos+j+1, ACS_HLINE );
126 } 138 }
127 iXPos += doc.aWidths[iCol+iXOff]+2; 139 iXPos += iWidth+1;
128 } 140 }
129 } 141 }
130 catch(...) { } 142 catch(...) { }
143 for( int j = 0; j < 6; j++ )
144 {
145 mvaddch( iHdrHeight, j, ACS_HLINE );
146 }
131 147
132 // Draw some data 148 // Draw some data
133 for( int iRow = 0; iRow < iRows; iRow++ ) 149 for( int iRow = 0; iRow < iRows; iRow++ )
@@ -137,15 +153,29 @@ public:
137 int iXPos = 6; 153 int iXPos = 6;
138 for( int iCol = 0; iCol < iCols; iCol++ ) 154 for( int iCol = 0; iCol < iCols; iCol++ )
139 { 155 {
140 if( iXPos + doc.aWidths[iCol+iXOff]+2 >= maxx ) 156 if( iXPos >= maxx )
141 break; 157 break;
158 int iWidth = min( doc.aWidths[iCol+iXOff], maxx-iXPos-1 );
142 mvaddch( iRow+iHdrHeight+1, iXPos, ACS_VLINE ); 159 mvaddch( iRow+iHdrHeight+1, iXPos, ACS_VLINE );
143 mvaddstr( iRow+iHdrHeight+1, iXPos+1, 160 mvaddnstr( iRow+iHdrHeight+1, iXPos+1,
144 doc.sgData[iRow+iYOff][iCol+iXOff].getStr() ); 161 doc.sgData[iRow+iYOff][iCol+iXOff].getStr(), iWidth );
145 iXPos += doc.aWidths[iCol+iXOff]+2; 162 iXPos += iWidth+1;
146 } 163 }
147 } catch(...) { } 164 } catch(...) { }
148 } 165 }
166
167 attron( A_REVERSE );
168 for( int j = 0; j < maxx; j++ )
169 {
170 mvaddch( maxy-1, j, ' ' );
171 }
172 mvaddstr( maxy-1, 1, "q) quit h) toggle header row" );
173 char buf[30];
174 int iWidth = sprintf( buf, "[%dx%ld]",
175 doc.iMaxCols, doc.sgData.getSize()
176 );
177 mvaddstr( maxy-1, maxx-iWidth-1, buf );
178 attroff( A_REVERSE );
149 } 179 }
150 180
151 void move( int iX, int iY ) 181 void move( int iX, int iY )
@@ -165,6 +195,12 @@ public:
165 if( iYOff < 0 ) 195 if( iYOff < 0 )
166 iYOff = 0; 196 iYOff = 0;
167 } 197 }
198
199 if( iYOff >= doc.sgData.getSize() )
200 iYOff = doc.sgData.getSize()-1;
201
202 if( iXOff >= doc.iMaxCols )
203 iXOff = doc.iMaxCols-1;
168 } 204 }
169 205
170 void pageDown() 206 void pageDown()
@@ -183,8 +219,11 @@ public:
183 219
184 void setHeaderRow( bool bOn ) 220 void setHeaderRow( bool bOn )
185 { 221 {
222 if( bHeaderRow == bOn )
223 return;
224
186 bHeaderRow = bOn; 225 bHeaderRow = bOn;
187 move( 0, 0 ); 226 move( 0, ((bOn)?(1):(-1)) );
188 } 227 }
189 228
190 void toggleHeaderRow() 229 void toggleHeaderRow()
@@ -229,7 +268,7 @@ int main( int argc, char *argv[] )
229 curs_set( 0 ); 268 curs_set( 0 );
230 269
231 CsvView view( doc ); 270 CsvView view( doc );
232 view.toggleHeaderRow(); 271 view.setHeaderRow( opt.bHeader );
233 272
234 bool bRun = true; 273 bool bRun = true;
235 do 274 do