From 6ee59e0e9ac6bd74cfd7cb79ab64b79ec8f817f9 Mon Sep 17 00:00:00 2001 From: vishalxl <> Date: Fri, 19 Aug 2022 11:51:46 +0530 Subject: [PATCH] printed number of trees displayed. added option to change number of days dispayed --- lib/console_ui.dart | 49 +++++++++++++++++++++++++++++++++------------ lib/relays.dart | 4 ++-- lib/tree_ds.dart | 14 ++++++++++--- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/lib/console_ui.dart b/lib/console_ui.dart index d2054a8..94a0f7e 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -46,21 +46,44 @@ String getShaId(String pubkey, int createdAt, String strTags, String content) { } Future otherMenuUi(Tree node, var contactList) async { + bool continueOtherMenu = true; + while(continueOtherMenu) { + print('\n\nPick an option by typing the corresponding\nnumber and then pressing :'); + int option = showMenu([ 'Display Contact List', // 1 + 'Change number of days printed', + 'Go back to main menu']); // 3 + print('You picked: $option'); + switch(option) { + case 1: + String authorName = getAuthorName(userPublicKey); + print("\nHere is the contact list for user $userPublicKey ($authorName), which has ${contactList.length} profiles in it:\n"); + contactList.forEach((x) => stdout.write("${getAuthorName(x)}, ")); + print(""); + break; + case 2: + String? $tempNumDays = stdin.readLineSync(); + String newNumDays = $tempNumDays??""; - print('\n\nPick an option by typing the corresponding\nnumber and then pressing :'); - int option = showMenu([ 'Display Contact List', // 1 - 'Go back']); // 3 - print('You picked: $option'); - switch(option) { - case 1: - String authorName = getAuthorName(userPublicKey); - print("\nHere is the contact list for user $userPublicKey ($authorName), which has ${contactList.length} profiles in it:\n"); - contactList.forEach((x) => stdout.write("${getAuthorName(x)}, ")); - print(""); - break; + try { + gNumLastDays = int.parse(newNumDays); + print("Changed number of days printed to $gNumLastDays"); + } on FormatException catch (e) { + print(e.message); + return; + } on Exception catch (e) { + print(e); + return; + } - default: - break; + break; + + case 3: + continueOtherMenu = false; + break; + + default: + break; + } } return; diff --git a/lib/relays.dart b/lib/relays.dart index c147cba..65731cd 100644 --- a/lib/relays.dart +++ b/lib/relays.dart @@ -122,7 +122,7 @@ class Relays { print( 'exception in fromJson for event'); } }, - onError: (e) { print("\n${warningColor}Warning: In SendRequest creating connection onError. Kindly check your internet connection or change the relay by command line --relay="); print(colorEndMarker); }, + onError: (err) { print("\n${warningColor}Warning: In SendRequest creating connection onError. Kindly check your internet connection or change the relay by command line --relay="); print(colorEndMarker); }, onDone: () { if( gDebug != 0) print('Info: In onDone'); } ); } on WebSocketException { @@ -151,7 +151,7 @@ class Relays { relays[relay] = fws; fws.stream.listen( (d) {}, // - onError: (e) { print("\n${warningColor}Warning: In SendRequest creating connection onError. Kindly check your internet connection or change the relay by command line --relay="); print(colorEndMarker); }, + onError: (err) { print("\n${warningColor}Warning: In SendRequest creating connection onError. Kindly check your internet connection or change the relay by command line --relay="); print(colorEndMarker); }, onDone: () { if( gDebug != 0) print('in onDone'); } ); } on WebSocketException { diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 0810f63..ddd8a87 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -110,11 +110,13 @@ class Tree { children.add(node); } - void printTree(int depth, bool onlyPrintChildren, var newerThan) { + int printTree(int depth, bool onlyPrintChildren, var newerThan) { + int numPrinted = 0; children.sort(ascendingTimeTree); if( !onlyPrintChildren) { e.printEvent(depth); + numPrinted++; } else { depth = depth - 1; } @@ -147,7 +149,7 @@ class Tree { leftShifted = true; } - children[i].printTree(depth+1, false, newerThan); + numPrinted += children[i].printTree(depth+1, false, newerThan); } if( leftShifted) { @@ -156,6 +158,12 @@ class Tree { print(">"); } + if( onlyPrintChildren) { + print("\nTotal posts/replies printed: $numPrinted for last $gNumLastDays days"); + } + + + return numPrinted; } Tree getTopTree(Tree t) { @@ -181,7 +189,7 @@ class Tree { Set temp = {}; newEventsId.retainWhere((event) => temp.add(newEventsId)); - stdout.write("\n\n\n\n\n\n---------------------------------------\nNotifications: "); + stdout.write("\n---------------------------------------\nNotifications: "); if( newEventsId.isEmpty) { stdout.write("No new replies/posts.\nTotal posts: ${count()}\n"); return;