mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-09-20 10:30:40 +02:00
added pubkey and maxdepth arguments. Fixed so that re-shifting of thread to left shows where the reshifting part ends
This commit is contained in:
@@ -12,19 +12,21 @@ String exename = "nostr_console";
|
|||||||
String version = "0.0.2";
|
String version = "0.0.2";
|
||||||
|
|
||||||
// well known disposable test private key
|
// well known disposable test private key
|
||||||
const String testPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
|
const String gDefaultPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
|
||||||
const String testPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180";
|
const String gDefaultPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180";
|
||||||
String userPrivateKey = testPrivateKey;
|
String userPrivateKey = gDefaultPrivateKey;
|
||||||
String userPublicKey = testPublicKey;
|
String userPublicKey = gDefaultPublicKey;
|
||||||
|
|
||||||
// program arguments1
|
// program arguments
|
||||||
const String requestArg = "request";
|
const String pubkeyArg = "pubkey";
|
||||||
const String prikeyArg = "prikey";
|
const String prikeyArg = "prikey";
|
||||||
const String lastdaysArg = "days";
|
const String lastdaysArg = "days";
|
||||||
const String relayArg = "relay";
|
const String relayArg = "relay";
|
||||||
|
const String requestArg = "request";
|
||||||
const String helpArg = "help";
|
const String helpArg = "help";
|
||||||
const String alignArg = "align"; // can be "left"
|
const String alignArg = "align"; // can be "left"
|
||||||
const String widthArg = "width";
|
const String widthArg = "width";
|
||||||
|
const String maxDepthArg = "maxdepth";
|
||||||
|
|
||||||
// By default the threads that were started in last one day are shown
|
// By default the threads that were started in last one day are shown
|
||||||
// this can be changed with 'days' command line argument
|
// this can be changed with 'days' command line argument
|
||||||
@@ -32,21 +34,27 @@ int numLastDays = 1;
|
|||||||
|
|
||||||
void printUsage() {
|
void printUsage() {
|
||||||
String usage = """$exename version $version
|
String usage = """$exename version $version
|
||||||
|
The nostr console client built using dart.
|
||||||
|
|
||||||
usage: $exename [OPTIONS]
|
usage: $exename [OPTIONS]
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
|
--pubkey <public key> The hex public key of user whose events and feed are shown. Default is a hard-coded
|
||||||
|
well known private key. When given, posts/replies can't be sent. Same as -p
|
||||||
--prikey <private key> The hex private key of user whose events and feed are shown. Also used to sign events
|
--prikey <private key> The hex private key of user whose events and feed are shown. Also used to sign events
|
||||||
sent. Default is a hard-coded well known private key. Same as -p
|
sent. Default is a hard-coded well known private key. Same as -k
|
||||||
--relay <relay wss url> The relay url that is used as main relay. Default is $defaultServerUrl . Same as -r
|
--relay <relay wss url> The relay url that is used as main relay. Default is $defaultServerUrl . Same as -r
|
||||||
--days <N as num> The latest number of days for which events are shown. Default is 1. Same as -d
|
--days <N as num> The latest number of days for which events are shown. Default is 1. Same as -d
|
||||||
--request <REQ string> This request is sent verbatim to the default relay. It can be used to recieve all events
|
--request <REQ string> This request is sent verbatim to the default relay. It can be used to recieve all events
|
||||||
from a relay. If not provided, then events for default or given user are shown. Same as -q
|
from a relay. If not provided, then events for default or given user are shown. Same as -q
|
||||||
|
UI Options
|
||||||
--align <left> When "left" is given as option to this argument, then the text is aligned to left. By default
|
--align <left> When "left" is given as option to this argument, then the text is aligned to left. By default
|
||||||
the posts or text is aligned to the center of the terminal. Same as -a
|
the posts or text is aligned to the center of the terminal. Same as -a
|
||||||
--width <width as num> This specifies how wide you want the text to be, in number of columns. Default is $gDefaultTextWidth.
|
--width <width as num> This specifies how wide you want the text to be, in number of columns. Default is $gDefaultTextWidth.
|
||||||
Cant be less than $gMinValidTextWidth. Same as -c
|
Cant be less than $gMinValidTextWidth. Same as -w
|
||||||
|
--maxdepth <depth as num> The maximum depth to which the threads can be displayed. Minimum is $gMinimumDepthAllowed and
|
||||||
|
maximum allowed is $gMaximumDepthAllowed. Same as -m
|
||||||
--help Print this usage message and exit. Same as -h
|
--help Print this usage message and exit. Same as -h
|
||||||
|
|
||||||
""";
|
""";
|
||||||
@@ -131,6 +139,11 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
// in case the program was invoked with --pubkey, then user can't send messages
|
||||||
|
if( userPrivateKey == "") {
|
||||||
|
print("Since no user private key has been supplied, messages can't sent. Invoke with --prikey \n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
stdout.write("Type comment to post/reply: ");
|
stdout.write("Type comment to post/reply: ");
|
||||||
String? $contentVar = stdin.readLineSync();
|
String? $contentVar = stdin.readLineSync();
|
||||||
String content = $contentVar??"";
|
String content = $contentVar??"";
|
||||||
@@ -169,10 +182,10 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
|
|||||||
|
|
||||||
Future<void> main(List<String> arguments) async {
|
Future<void> main(List<String> arguments) async {
|
||||||
|
|
||||||
final parser = ArgParser()..addOption(requestArg, abbr: 'q') ..addOption(prikeyArg, abbr:"p")
|
final parser = ArgParser()..addOption(requestArg, abbr: 'q') ..addOption(pubkeyArg, abbr:"p")..addOption(prikeyArg, abbr:"k")
|
||||||
..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
|
..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
|
||||||
..addFlag(helpArg, abbr:"h", defaultsTo: false)..addOption(alignArg, abbr:"a")
|
..addFlag(helpArg, abbr:"h", defaultsTo: false)..addOption(alignArg, abbr:"a")
|
||||||
..addOption(widthArg, abbr:"c");
|
..addOption(widthArg, abbr:"w")..addOption(maxDepthArg, abbr:"m");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ArgResults argResults = parser.parse(arguments);
|
ArgResults argResults = parser.parse(arguments);
|
||||||
@@ -181,14 +194,21 @@ Future<void> main(List<String> arguments) async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( argResults[relayArg] != null) {
|
if( argResults[pubkeyArg] != null) {
|
||||||
defaultServerUrl = argResults[relayArg];
|
userPublicKey = argResults[pubkeyArg];
|
||||||
print("Going to use relay: $defaultServerUrl");
|
userPrivateKey = "";
|
||||||
|
print("Going to use public key $userPublicKey. You will not be able to send posts/replies.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( argResults[prikeyArg] != null) {
|
if( argResults[prikeyArg] != null) {
|
||||||
userPrivateKey = argResults[prikeyArg];
|
userPrivateKey = argResults[prikeyArg];
|
||||||
userPublicKey = getPublicKey(userPrivateKey);
|
userPublicKey = getPublicKey(userPrivateKey);
|
||||||
|
print("Going to use the provided private key");
|
||||||
|
}
|
||||||
|
|
||||||
|
if( argResults[relayArg] != null) {
|
||||||
|
defaultServerUrl = argResults[relayArg];
|
||||||
|
print("Going to use relay: $defaultServerUrl");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( argResults[lastdaysArg] != null) {
|
if( argResults[lastdaysArg] != null) {
|
||||||
@@ -201,8 +221,8 @@ Future<void> main(List<String> arguments) async {
|
|||||||
if( tempTextWidth < gMinValidTextWidth ) {
|
if( tempTextWidth < gMinValidTextWidth ) {
|
||||||
print("Text-width cannot be less than $gMinValidTextWidth. Going to use the defalt value of $gTextWidth");
|
print("Text-width cannot be less than $gMinValidTextWidth. Going to use the defalt value of $gTextWidth");
|
||||||
} else {
|
} else {
|
||||||
print("Going to use $gTextWidth columns for text on screen.");
|
|
||||||
gTextWidth = tempTextWidth;
|
gTextWidth = tempTextWidth;
|
||||||
|
print("Going to use $gTextWidth columns for text on screen.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +230,23 @@ Future<void> main(List<String> arguments) async {
|
|||||||
gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
|
gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
|
||||||
|
|
||||||
// undo above if left option is given
|
// undo above if left option is given
|
||||||
if( argResults[alignArg] != null) {
|
if( argResults[alignArg] != null ) {
|
||||||
if( argResults[alignArg] == "left" ) {
|
if( argResults[alignArg] == "left" ) {
|
||||||
print("Going to align to left.");
|
print("Going to align to left.");
|
||||||
gAlignment = "left";
|
gAlignment = "left";
|
||||||
gNumLeftMarginSpaces = 0;
|
gNumLeftMarginSpaces = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( argResults[maxDepthArg] != null) {
|
||||||
|
|
||||||
|
int tempMaxDepth = int.parse(argResults[maxDepthArg]);
|
||||||
|
if( tempMaxDepth < gMinimumDepthAllowed || tempMaxDepth > gMaximumDepthAllowed) {
|
||||||
|
print("Maximum depth cannot be less than $gMinimumDepthAllowed and cannot be more than $gMaximumDepthAllowed. Going to use the default maximum depth, which is $gDefaultMaxDepth.");
|
||||||
|
} else {
|
||||||
|
maxDepthAllowed = tempMaxDepth;
|
||||||
|
print("Going to take threads to maximum depth of $numLastDays days");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( argResults[requestArg] != null) {
|
if( argResults[requestArg] != null) {
|
||||||
|
@@ -2,15 +2,19 @@ import 'dart:io';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
const int gMinValidTextWidth = 60;
|
const int gMinValidTextWidth = 60; // minimum text width acceptable
|
||||||
const int gDefaultTextWidth = 120;
|
const int gDefaultTextWidth = 120; // default text width
|
||||||
int gTextWidth = gDefaultTextWidth;
|
int gTextWidth = gDefaultTextWidth; // is changed by --width option
|
||||||
const int gSpacesPerDepth = 8;
|
const int gSpacesPerDepth = 8; // constant
|
||||||
int gNumLeftMarginSpaces = 0; // this number is modified in main
|
int gNumLeftMarginSpaces = 0; // this number is modified in main
|
||||||
String gAlignment = "center"; // is modified in main if --align argument is given
|
String gAlignment = "center"; // is modified in main if --align argument is given
|
||||||
|
|
||||||
const int maxDepthAllowed = 4;
|
// after depth of maxDepthAllowed the thread is re-aligned to left by leftShiftThreadBy
|
||||||
const int leftShiftThreadsBy = 2;
|
const int gMinimumDepthAllowed = 2;
|
||||||
|
const int gMaximumDepthAllowed = 12;
|
||||||
|
const int gDefaultMaxDepth = 4;
|
||||||
|
int maxDepthAllowed = gDefaultMaxDepth;
|
||||||
|
const int leftShiftThreadsBy = 2;
|
||||||
|
|
||||||
// 33 yellow, 31 red, 34 blue, 35 magenta. Add 60 for bright versions.
|
// 33 yellow, 31 red, 34 blue, 35 magenta. Add 60 for bright versions.
|
||||||
const String commentColor = "\x1B[32m"; // green
|
const String commentColor = "\x1B[32m"; // green
|
||||||
|
@@ -119,7 +119,7 @@ class Relays {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
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: (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); },
|
||||||
onDone: () { print('Info: In onDone'); }
|
onDone: () { if( gDebug != 0) print('Info: In onDone'); }
|
||||||
);
|
);
|
||||||
} on WebSocketException {
|
} on WebSocketException {
|
||||||
print('WebSocketException exception');
|
print('WebSocketException exception');
|
||||||
@@ -147,8 +147,8 @@ class Relays {
|
|||||||
relays[relay] = fws;
|
relays[relay] = fws;
|
||||||
fws.stream.listen(
|
fws.stream.listen(
|
||||||
(d) {}, //
|
(d) {}, //
|
||||||
onError: (e) { print("in onError"); print(e); },
|
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); },
|
||||||
onDone: () { print('in onDone'); }
|
onDone: () { if( gDebug != 0) print('in onDone'); }
|
||||||
);
|
);
|
||||||
} on WebSocketException {
|
} on WebSocketException {
|
||||||
print('WebSocketException exception');
|
print('WebSocketException exception');
|
||||||
|
@@ -119,6 +119,7 @@ class Tree {
|
|||||||
depth = depth - 1;
|
depth = depth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool leftShifted = false;
|
||||||
for( int i = 0; i < children.length; i++) {
|
for( int i = 0; i < children.length; i++) {
|
||||||
if(!onlyPrintChildren) {
|
if(!onlyPrintChildren) {
|
||||||
stdout.write("\n");
|
stdout.write("\n");
|
||||||
@@ -137,15 +138,24 @@ class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the thread becomes too 'deep' then reset its depth, so that its
|
// if the thread becomes too 'deep' then reset its depth, so that its
|
||||||
// children will not be displayed too much the right, but are shifted
|
// children will not be displayed too much on the right, but are shifted
|
||||||
// left by about <leftShiftDeepThreadsBy> places
|
// left by about <leftShiftThreadsBy> places
|
||||||
if( depth > maxDepthAllowed) {
|
if( depth > maxDepthAllowed) {
|
||||||
depth = maxDepthAllowed - leftShiftThreadsBy;
|
depth = maxDepthAllowed - leftShiftThreadsBy;
|
||||||
printDepth(depth+1);
|
printDepth(depth+1);
|
||||||
stdout.write("+${getNumDashes((leftShiftThreadsBy + 1) * 8 - 1)}+\n");
|
stdout.write("<${getNumDashes((leftShiftThreadsBy + 1) * gSpacesPerDepth - 1)}+\n");
|
||||||
|
leftShifted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
children[i].printTree(depth+1, false, newerThan);
|
children[i].printTree(depth+1, false, newerThan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( leftShifted) {
|
||||||
|
stdout.write("\n");
|
||||||
|
printDepth(depth+1);
|
||||||
|
print(">");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree getTopTree(Tree t) {
|
Tree getTopTree(Tree t) {
|
||||||
|
Reference in New Issue
Block a user