printed number of trees displayed. added option to change number of days dispayed

This commit is contained in:
vishalxl
2022-08-19 11:51:46 +05:30
parent cb0baaa4f2
commit 6ee59e0e9a
3 changed files with 49 additions and 18 deletions

View File

@ -46,21 +46,44 @@ String getShaId(String pubkey, int createdAt, String strTags, String content) {
} }
Future<void> otherMenuUi(Tree node, var contactList) async { Future<void> otherMenuUi(Tree node, var contactList) async {
bool continueOtherMenu = true;
while(continueOtherMenu) {
print('\n\nPick an option by typing the corresponding\nnumber and then pressing <enter>:');
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 <enter>:'); try {
int option = showMenu([ 'Display Contact List', // 1 gNumLastDays = int.parse(newNumDays);
'Go back']); // 3 print("Changed number of days printed to $gNumLastDays");
print('You picked: $option'); } on FormatException catch (e) {
switch(option) { print(e.message);
case 1: return;
String authorName = getAuthorName(userPublicKey); } on Exception catch (e) {
print("\nHere is the contact list for user $userPublicKey ($authorName), which has ${contactList.length} profiles in it:\n"); print(e);
contactList.forEach((x) => stdout.write("${getAuthorName(x)}, ")); return;
print(""); }
break;
default: break;
break;
case 3:
continueOtherMenu = false;
break;
default:
break;
}
} }
return; return;

View File

@ -122,7 +122,7 @@ class Relays {
print( 'exception in fromJson for event'); 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=<relay wss url>"); 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=<relay wss url>"); print(colorEndMarker); },
onDone: () { if( gDebug != 0) print('Info: In onDone'); } onDone: () { if( gDebug != 0) print('Info: In onDone'); }
); );
} on WebSocketException { } on WebSocketException {
@ -151,7 +151,7 @@ class Relays {
relays[relay] = fws; relays[relay] = fws;
fws.stream.listen( fws.stream.listen(
(d) {}, // (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=<relay wss url>"); 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=<relay wss url>"); print(colorEndMarker); },
onDone: () { if( gDebug != 0) print('in onDone'); } onDone: () { if( gDebug != 0) print('in onDone'); }
); );
} on WebSocketException { } on WebSocketException {

View File

@ -110,11 +110,13 @@ class Tree {
children.add(node); 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); children.sort(ascendingTimeTree);
if( !onlyPrintChildren) { if( !onlyPrintChildren) {
e.printEvent(depth); e.printEvent(depth);
numPrinted++;
} else { } else {
depth = depth - 1; depth = depth - 1;
} }
@ -147,7 +149,7 @@ class Tree {
leftShifted = true; leftShifted = true;
} }
children[i].printTree(depth+1, false, newerThan); numPrinted += children[i].printTree(depth+1, false, newerThan);
} }
if( leftShifted) { if( leftShifted) {
@ -156,6 +158,12 @@ class Tree {
print(">"); print(">");
} }
if( onlyPrintChildren) {
print("\nTotal posts/replies printed: $numPrinted for last $gNumLastDays days");
}
return numPrinted;
} }
Tree getTopTree(Tree t) { Tree getTopTree(Tree t) {
@ -181,7 +189,7 @@ class Tree {
Set temp = {}; Set temp = {};
newEventsId.retainWhere((event) => temp.add(newEventsId)); newEventsId.retainWhere((event) => temp.add(newEventsId));
stdout.write("\n\n\n\n\n\n---------------------------------------\nNotifications: "); stdout.write("\n---------------------------------------\nNotifications: ");
if( newEventsId.isEmpty) { if( newEventsId.isEmpty) {
stdout.write("No new replies/posts.\nTotal posts: ${count()}\n"); stdout.write("No new replies/posts.\nTotal posts: ${count()}\n");
return; return;