diff options
author | Antony Kellermann | 2018-06-06 13:47:55 -0400 |
---|---|---|
committer | Antony Kellermann | 2018-06-06 13:47:55 -0400 |
commit | 90386ef48106231d8dcf9018d81d7dfdfc5fc37f (patch) | |
tree | a9a5c76f2bf336ead8bcd051d391bedb538b17e8 | |
parent | 85ff6adfe00f287f9777e4fc90892fd74b7c8d82 (diff) | |
download | aur-90386ef48106231d8dcf9018d81d7dfdfc5fc37f.tar.gz |
Changed print all to take Info_Array as argument
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | portfolio.c | 19 | ||||
-rw-r--r-- | portfolio.h | 7 |
3 files changed, 14 insertions, 14 deletions
@@ -58,7 +58,7 @@ int main(int argc, char* argv[]) { // Check else if (strcmp(cmd, "check") == 0 && (argc == 2 || argc == 3)) { if (argc == 2) - portfolio_print_all(); + portfolio_print_all(portfolio_get_info_array()); else portfolio_print_stock(sym); } diff --git a/portfolio.c b/portfolio.c index c02aa170f27d..267028f87abe 100644 --- a/portfolio.c +++ b/portfolio.c @@ -177,9 +177,13 @@ Info_Array* portfolio_get_info_array(void) { } void* temp = NULL; + int load_len = 0; for (size_t i = 0; i < portfolio_data->length; i++) { - mvprintw(0, 0, "Loading data (%d/%d)\n", (int) i + 1, (int) portfolio_data->length); // Print loading string - refresh(); // flushes output buffer + if (i > 0) + for (int j = 0; j < load_len; j++) + putchar('\b'); + load_len = printf("Loading data (%d/%d)", (int) i + 1, (int) portfolio_data->length); // Print loading string + fflush(stdout); if (strcmp(syms[i], "USD$") != 0) { if (pthread_join(threads[i], &temp)) EXIT_MSG("Error joining thread!") @@ -261,17 +265,14 @@ void portfolio_sort(Info_Array* portfolio_data, int sort_option) { } } -void portfolio_print_all(void) { +void portfolio_print_all(Info_Array* portfolio_data) { + if (portfolio_data == NULL) + return; + initscr(); noecho(); // Don't echo keystrokes keypad(stdscr, TRUE); // Enables extra keystrokes curs_set(FALSE); // Hides cursor - Info_Array* portfolio_data = portfolio_get_info_array(); - if (portfolio_data == NULL) { // Error reading portfolio, wrong password, empty portfolio array - endwin(); - return; - } - double total_owned = 0, total_spent = 0, total_profit_1d = 0, total_profit_7d = 0, total_profit_30d = 0; for (size_t i = 0; i < portfolio_data->length; i++) { // Add collected values to totals total_owned += portfolio_data->array[i]->current_value; diff --git a/portfolio.h b/portfolio.h index 50fa48a4b348..0afdcdd25b72 100644 --- a/portfolio.h +++ b/portfolio.h @@ -26,6 +26,7 @@ #define HIGHLIGHT_NONE -1 #define KEY_ESCAPE 27 + extern char* portfolio_file; /** @@ -70,10 +71,8 @@ String* portfolio_file_get_string(char** password_ref); void portfolio_modify(const char* symbol, double quantity_shares, double usd_spent, int mod_option); /** - * Returns an SDA array containing data from the portfolio. + * Returns an Info_Array containing data from the portfolio. * length is the number of securities in the portfolio - * sec_data is an array of SD pointers to SD structs with the fields symbol, amount, and total_spent populated. - * The rest of the values are uninitialized * @return SDA array */ Info_Array* portfolio_get_info_array(void); @@ -91,7 +90,7 @@ void portfolio_sort(Info_Array* portfolio_data, int sort_option); * Prints to stdout information about every security contained in the portfolio: symbol, number of shares, USD spent, * current value, profit, and 24h profit. Additionally, print a grand total with info from all securities. */ -void portfolio_print_all(void); +void portfolio_print_all(Info_Array* portfolio_data); /** * Prints to stdout information about a specific security contained in the portfolio: symbol, number of shares, USD spent, |