summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-06-23 15:43:59 +0000
committerMike Buland <eichlan@xagasoft.com>2010-06-23 15:43:59 +0000
commit5d8fad38edc321f4bda8084b24b0350c5af82a1d (patch)
tree325d966d5f35fdaef114745d2cccab5220768f8a /src/tools
parent6feb3e31d7a6a614d7977afa4e48b07c25f6bb61 (diff)
downloadlibbu++-5d8fad38edc321f4bda8084b24b0350c5af82a1d.tar.gz
libbu++-5d8fad38edc321f4bda8084b24b0350c5af82a1d.tar.bz2
libbu++-5d8fad38edc321f4bda8084b24b0350c5af82a1d.tar.xz
libbu++-5d8fad38edc321f4bda8084b24b0350c5af82a1d.zip
Minor visual and usability updates. Search is almost done.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/viewcsv.cpp91
1 files changed, 81 insertions, 10 deletions
diff --git a/src/tools/viewcsv.cpp b/src/tools/viewcsv.cpp
index d6c09c9..649ec9e 100644
--- a/src/tools/viewcsv.cpp
+++ b/src/tools/viewcsv.cpp
@@ -2,6 +2,8 @@
2#include <bu/optparser.h> 2#include <bu/optparser.h>
3#include <bu/csvreader.h> 3#include <bu/csvreader.h>
4#include <bu/file.h> 4#include <bu/file.h>
5#include <bu/newline.h>
6#include <bu/buffer.h>
5#include <bu/util.h> 7#include <bu/util.h>
6#include <ncurses.h> 8#include <ncurses.h>
7 9
@@ -207,14 +209,25 @@ public:
207 { 209 {
208 int maxx, maxy; 210 int maxx, maxy;
209 getmaxyx( stdscr, maxy, maxx ); 211 getmaxyx( stdscr, maxy, maxx );
210 move( 0, maxy-2 ); 212 move( 0, maxy-((bHeaderRow)?(4):(3)) );
211 } 213 }
212 214
213 void pageUp() 215 void pageUp()
214 { 216 {
215 int maxx, maxy; 217 int maxx, maxy;
216 getmaxyx( stdscr, maxy, maxx ); 218 getmaxyx( stdscr, maxy, maxx );
217 move( 0, -(maxy-2) ); 219 move( 0, -(maxy-((bHeaderRow)?(4):(3))) );
220 }
221
222 void home()
223 {
224 iYOff = 0;
225 if( bHeaderRow ) iYOff++;
226 }
227
228 void end()
229 {
230 iYOff = doc.sgData.getSize()-1;
218 } 231 }
219 232
220 void setHeaderRow( bool bOn ) 233 void setHeaderRow( bool bOn )
@@ -231,6 +244,46 @@ public:
231 setHeaderRow( !bHeaderRow ); 244 setHeaderRow( !bHeaderRow );
232 } 245 }
233 246
247 Bu::FString prompt( const Bu::FString &sPrompt )
248 {
249 int maxx, maxy;
250 Bu::FString sStr;
251
252 curs_set( 1 );
253 for(;;)
254 {
255 getmaxyx( stdscr, maxy, maxx );
256 for( int j = 0; j < maxx; j++ )
257 {
258 mvaddch( maxy-1, j, ' ' );
259 }
260 mvaddstr( maxy-1, 0, sPrompt.getStr() );
261
262 mvaddstr( maxy-1, sPrompt.getSize(), sStr.getStr() );
263
264 int iCh = getch();
265 switch( iCh )
266 {
267 case '\n':
268 case '\r':
269 case KEY_ENTER:
270 curs_set( 0 );
271 return sStr;
272 break;
273
274 case KEY_BACKSPACE:
275 if( sStr.getSize() > 0 )
276 sStr.setSize( sStr.getSize()-1 );
277 break;
278
279 default:
280 if( iCh < 127 )
281 sStr += (char)iCh;
282 break;
283 }
284 }
285 }
286
234 CsvDoc &doc; 287 CsvDoc &doc;
235 int iXOff; 288 int iXOff;
236 int iYOff; 289 int iYOff;
@@ -248,15 +301,19 @@ int main( int argc, char *argv[] )
248 } 301 }
249 302
250 CsvDoc doc; 303 CsvDoc doc;
251 File fIn( opt.sFileIn, File::Read );
252 CsvReader cr( fIn );
253
254 while( !fIn.isEos() )
255 { 304 {
256 StrArray sa = cr.readLine(); 305 File fIn( opt.sFileIn, File::Read );
257 if( fIn.isEos() ) 306 NewLine nlIn( fIn );
258 break; 307 Buffer bIn( nlIn );
259 doc.addRow( sa ); 308 CsvReader cr( bIn );
309
310 while( !fIn.isEos() )
311 {
312 StrArray sa = cr.readLine();
313 if( fIn.isEos() )
314 break;
315 doc.addRow( sa );
316 }
260 } 317 }
261 318
262 initscr(); 319 initscr();
@@ -306,6 +363,20 @@ int main( int argc, char *argv[] )
306 view.pageUp(); 363 view.pageUp();
307 break; 364 break;
308 365
366 case KEY_HOME:
367 view.home();
368 break;
369
370 case KEY_END:
371 view.end();
372 break;
373
374 case '/':
375 {
376 Bu::FString sIn = view.prompt("find: ");
377 }
378 break;
379
309 case 'h': 380 case 'h':
310 view.toggleHeaderRow(); 381 view.toggleHeaderRow();
311 break; 382 break;