1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "ProgressBar.h" |
---|
22 | |
---|
23 | char const* const barGoLink::empty = " "; |
---|
24 | #ifdef _WIN32 |
---|
25 | char const* const barGoLink::full = "\x3D"; |
---|
26 | #else |
---|
27 | char const* const barGoLink::full = "*"; |
---|
28 | #endif |
---|
29 | |
---|
30 | barGoLink::~barGoLink() |
---|
31 | { |
---|
32 | printf( "\n" ); |
---|
33 | fflush(stdout); |
---|
34 | } |
---|
35 | |
---|
36 | barGoLink::barGoLink( int row_count ) |
---|
37 | { |
---|
38 | rec_no = 0; |
---|
39 | rec_pos = 0; |
---|
40 | indic_len = 50; |
---|
41 | num_rec = row_count; |
---|
42 | #ifdef _WIN32 |
---|
43 | printf( "\x3D" ); |
---|
44 | #else |
---|
45 | printf( "[" ); |
---|
46 | #endif |
---|
47 | for ( int i = 0; i < indic_len; i++ ) printf( empty ); |
---|
48 | #ifdef _WIN32 |
---|
49 | printf( "\x3D 0%%\r\x3D" ); |
---|
50 | #else |
---|
51 | printf( "] 0%%\r[" ); |
---|
52 | #endif |
---|
53 | fflush(stdout); |
---|
54 | } |
---|
55 | |
---|
56 | void barGoLink::step( void ) |
---|
57 | { |
---|
58 | int i, n; |
---|
59 | |
---|
60 | if ( num_rec == 0 ) return; |
---|
61 | ++rec_no; |
---|
62 | n = rec_no * indic_len / num_rec; |
---|
63 | if ( n != rec_pos ) |
---|
64 | { |
---|
65 | #ifdef _WIN32 |
---|
66 | printf( "\r\x3D" ); |
---|
67 | #else |
---|
68 | printf( "\r[" ); |
---|
69 | #endif |
---|
70 | for ( i = 0; i < n; i++ ) printf( full ); |
---|
71 | for ( ; i < indic_len; i++ ) printf( empty ); |
---|
72 | float percent = (((float)n/(float)indic_len)*100); |
---|
73 | #ifdef _WIN32 |
---|
74 | printf( "\x3D %i%% \r\x3D", (int)percent); |
---|
75 | #else |
---|
76 | printf( "] %i%% \r[", (int)percent); |
---|
77 | #endif |
---|
78 | fflush(stdout); |
---|
79 | |
---|
80 | rec_pos = n; |
---|
81 | } |
---|
82 | } |
---|