diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-09-07 21:43:01 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-09-07 21:43:01 +0200 |
commit | e2a37cf9c1c1e209dec015ded939b8eb5226bbf3 (patch) | |
tree | 58dbb7417df550200f26edfe6a200e54fe4ed25d | |
parent | 26cdc783c935a2a9b41af0083dcafe401589d41e (diff) | |
download | cssh-e2a37cf9c1c1e209dec015ded939b8eb5226bbf3.tar.gz cssh-e2a37cf9c1c1e209dec015ded939b8eb5226bbf3.tar.bz2 |
..
-rw-r--r-- | src/cssh.c | 1 | ||||
-rw-r--r-- | src/progressbar.c | 17 | ||||
-rw-r--r-- | src/progressbar.h | 5 | ||||
-rw-r--r-- | tests/progressbartest.c | 2 |
4 files changed, 23 insertions, 2 deletions
@@ -1364,6 +1364,7 @@ int main( int argc, char *argv[] ) break; } } + redraw_progressbars( &progressbars ); } break; } } diff --git a/src/progressbar.c b/src/progressbar.c index 3d07e4e..e8cd54b 100644 --- a/src/progressbar.c +++ b/src/progressbar.c @@ -20,6 +20,8 @@ int create_progressbar( cssh_progressbar_t *progressbar, uint64_t min_value, uin (void)vsnprintf( progressbar->label, size, label_fmt, va ); + progressbar->value = progressbar->min_value; + va_end( va ); return 0; @@ -32,7 +34,12 @@ void free_progressbar( cssh_progressbar_t *progressbar ) void set_value_of_progressbar( cssh_progressbar_t *progressbar, uint64_t value ) { - fprintf( stderr, "%s %"PRIu64" \n", progressbar->label, value ); + progressbar->value = value; +} + +void redraw_progressbar( cssh_progressbar_t *progressbar ) +{ + fprintf( stderr, "%s %"PRIu64" \n", progressbar->label, progressbar->value ); } int create_progressbar_pool( cssh_progressbar_pool_t *pool, size_t initial_size ) @@ -88,4 +95,12 @@ int remove_progressbar_from_pool( cssh_progressbar_pool_t *pool, cssh_progressba return -1; } +void redraw_progressbars( cssh_progressbar_pool_t *pool ) +{ + + for( size_t i = 0; i < pool->N; i++ ) { + redraw_progressbar( pool->progressbar[i] ); + } + printf( "\33[%dF\n", pool->N + 1 ); +} diff --git a/src/progressbar.h b/src/progressbar.h index 71eaed1..3bcc65b 100644 --- a/src/progressbar.h +++ b/src/progressbar.h @@ -12,6 +12,7 @@ typedef struct cssh_progressbar_t { uint64_t min_value; uint64_t max_value; char *label; + uint64_t value; } cssh_progressbar_t; typedef struct cssh_progressbar_pool_t { @@ -26,6 +27,8 @@ void free_progressbar( cssh_progressbar_t *progressbar ); void set_value_of_progressbar( cssh_progressbar_t *progressbar, uint64_t value ); +void redraw_progressbar( cssh_progressbar_t *progressbar ); + int create_progressbar_pool( cssh_progressbar_pool_t *pool, size_t initial_size ); void free_progressbar_pool( cssh_progressbar_pool_t *pool ); @@ -34,4 +37,6 @@ int append_progressbar_to_pool( cssh_progressbar_pool_t *pool, cssh_progressbar_ int remove_progressbar_from_pool( cssh_progressbar_pool_t *pool, cssh_progressbar_t *progressbar ); +void redraw_progressbars( cssh_progressbar_pool_t *pool ); + #endif diff --git a/tests/progressbartest.c b/tests/progressbartest.c index 8e6e0bf..9459578 100644 --- a/tests/progressbartest.c +++ b/tests/progressbartest.c @@ -18,8 +18,8 @@ int main( void ) for( unsigned int i = 0; i < 100; i++ ) { set_value_of_progressbar( &p1, i ); set_value_of_progressbar( &p2, 100 - i ); + redraw_progressbars( &pool ); cssh_msleep( 100 ); - printf( "\33[3F\n" ); } free_progressbar( &p1 ); |