mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-07-28 13:02:12 +02:00
Added color option and made file as default of name all_nostr_events.txt which can be disabled with --disable-file
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -19,3 +19,5 @@ doc/api/
|
|||||||
*.js_
|
*.js_
|
||||||
*.js.deps
|
*.js.deps
|
||||||
*.js.map
|
*.js.map
|
||||||
|
del*.txt
|
||||||
|
all_nostr_events.txt
|
||||||
|
@@ -19,7 +19,10 @@ const String alignArg = "align"; // can be "left"
|
|||||||
const String widthArg = "width";
|
const String widthArg = "width";
|
||||||
const String maxDepthArg = "maxdepth";
|
const String maxDepthArg = "maxdepth";
|
||||||
const String eventFileArg = "file";
|
const String eventFileArg = "file";
|
||||||
|
const String disableFileArg = "disable-file";
|
||||||
|
|
||||||
const String translateArg = "translate";
|
const String translateArg = "translate";
|
||||||
|
const String colorArg = "color";
|
||||||
|
|
||||||
void printUsage() {
|
void printUsage() {
|
||||||
print(gUsage);
|
print(gUsage);
|
||||||
@@ -30,7 +33,9 @@ Future<void> main(List<String> arguments) async {
|
|||||||
..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:"w")..addOption(maxDepthArg, abbr:"m")
|
..addOption(widthArg, abbr:"w")..addOption(maxDepthArg, abbr:"m")
|
||||||
..addOption(eventFileArg, abbr:"f")..addFlag(translateArg, abbr: "t", defaultsTo: false);
|
..addOption(eventFileArg, abbr:"f", defaultsTo: gDefaultEventsFilename)..addFlag(disableFileArg, abbr:"n", defaultsTo: false)
|
||||||
|
..addFlag(translateArg, abbr: "t", defaultsTo: false)
|
||||||
|
..addOption(colorArg, abbr:"c");
|
||||||
try {
|
try {
|
||||||
ArgResults argResults = parser.parse(arguments);
|
ArgResults argResults = parser.parse(arguments);
|
||||||
if( argResults[helpArg]) {
|
if( argResults[helpArg]) {
|
||||||
@@ -97,25 +102,54 @@ Future<void> main(List<String> arguments) async {
|
|||||||
print("Going to take threads to maximum depth of $gNumLastDays days");
|
print("Going to take threads to maximum depth of $gNumLastDays days");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( argResults[eventFileArg] != null) {
|
|
||||||
gEventsFilename = argResults[eventFileArg];
|
if( argResults[colorArg] != null) {
|
||||||
if( gEventsFilename != "") {
|
String colorGiven = argResults[colorArg].toString().toLowerCase();
|
||||||
print("Going to use file to read from and store events: $gEventsFilename");
|
if( gColorMap.containsKey(colorGiven)) {
|
||||||
|
String color = gColorMap[colorGiven]??"";
|
||||||
|
if( color == "") {
|
||||||
|
print("Invalid color.");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
gCommentColor = color;
|
||||||
|
print("Going to use color $gCommentColor.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Invalid color.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( argResults[disableFileArg]) {
|
||||||
|
gEventsFilename = "";
|
||||||
|
print("Not going to use any file to read/write events.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String whetherDefault = "the given ";
|
||||||
|
if( argResults[eventFileArg] != null && !argResults[disableFileArg]) {
|
||||||
|
if( gDefaultEventsFilename == argResults[eventFileArg]) {
|
||||||
|
whetherDefault = "default ";
|
||||||
|
}
|
||||||
|
|
||||||
|
gEventsFilename = argResults[eventFileArg];
|
||||||
|
|
||||||
|
if( gEventsFilename != "") {
|
||||||
|
print("Going to use ${whetherDefault}file to read from and store events: $gEventsFilename");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if( gEventsFilename != "") {
|
if( gEventsFilename != "") {
|
||||||
print("\n");
|
print("\n");
|
||||||
stdout.write('Reading events from the given file.......');
|
stdout.write('Reading events from ${whetherDefault}file.......');
|
||||||
List<Event> eventsFromFile = readEventsFromFile(gEventsFilename);
|
List<Event> eventsFromFile = readEventsFromFile(gEventsFilename);
|
||||||
setRelaysIntialEvents(eventsFromFile);
|
setRelaysIntialEvents(eventsFromFile);
|
||||||
eventsFromFile.forEach((element) { element.eventData.kind == 1? numFileEvents++: numFileEvents;});
|
eventsFromFile.forEach((element) { element.eventData.kind == 1? numFileEvents++: numFileEvents;});
|
||||||
print("read $numFileEvents posts from file \"$gEventsFilename\"");
|
print("read $numFileEvents posts from file \"$gEventsFilename\"");
|
||||||
}
|
}
|
||||||
if( argResults[requestArg] != null) {
|
if( argResults[requestArg] != null) {
|
||||||
//stdout.write("Got argument request: ${argResults[requestArg]}");
|
|
||||||
stdout.write('Sending request and waiting for events...');
|
stdout.write('Sending request and waiting for events...');
|
||||||
sendRequest(gListRelayUrls, argResults[requestArg]);
|
sendRequest(gListRelayUrls, argResults[requestArg]);
|
||||||
Future.delayed(const Duration(milliseconds: 6000), () {
|
Future.delayed(const Duration(milliseconds: numWaitSeconds * 2), () {
|
||||||
List<Event> receivedEvents = getRecievedEvents();
|
List<Event> receivedEvents = getRecievedEvents();
|
||||||
stdout.write("received ${receivedEvents.length - numFileEvents} events\n");
|
stdout.write("received ${receivedEvents.length - numFileEvents} events\n");
|
||||||
|
|
||||||
|
@@ -13,8 +13,8 @@ Future<void> processNotifications(Tree node) async {
|
|||||||
|
|
||||||
List<String> newEventsId = node.insertEvents(getRecievedEvents());
|
List<String> newEventsId = node.insertEvents(getRecievedEvents());
|
||||||
String nameToDisplay = userPrivateKey.length == 64?
|
String nameToDisplay = userPrivateKey.length == 64?
|
||||||
"$commentColor${getAuthorName(userPublicKey)}$colorEndMarker":
|
"$gCommentColor${getAuthorName(userPublicKey)}$colorEndMarker":
|
||||||
"${warningColor}You are not signed in$colorEndMarker but are using public key $userPublicKey";
|
"${gWarningColor}You are not signed in$colorEndMarker but are using public key $userPublicKey";
|
||||||
node.printNotifications(newEventsId, nameToDisplay);
|
node.printNotifications(newEventsId, nameToDisplay);
|
||||||
clearEvents();
|
clearEvents();
|
||||||
});
|
});
|
||||||
|
@@ -317,10 +317,10 @@ class EventData {
|
|||||||
printDepth(depth);
|
printDepth(depth);
|
||||||
stdout.write("|Message: ");
|
stdout.write("|Message: ");
|
||||||
if( isNotification) {
|
if( isNotification) {
|
||||||
printInColor(contentShifted, notificationColor);
|
printInColor(contentShifted, gNotificationColor);
|
||||||
isNotification = false;
|
isNotification = false;
|
||||||
} else {
|
} else {
|
||||||
printInColor(contentShifted, commentColor);
|
printInColor(contentShifted, gCommentColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ class EventData {
|
|||||||
String reactorId = reactors[i][0];
|
String reactorId = reactors[i][0];
|
||||||
if( newLikes.contains(reactorId)) {
|
if( newLikes.contains(reactorId)) {
|
||||||
// colorify
|
// colorify
|
||||||
reactorNames += notificationColor + getAuthorName(reactorId) + colorEndMarker;
|
reactorNames += gNotificationColor + getAuthorName(reactorId) + colorEndMarker;
|
||||||
} else {
|
} else {
|
||||||
reactorNames += getAuthorName(reactorId);
|
reactorNames += getAuthorName(reactorId);
|
||||||
}
|
}
|
||||||
@@ -512,7 +512,7 @@ List<Event> readEventsFromFile(String filename) {
|
|||||||
events.add(e);
|
events.add(e);
|
||||||
}
|
}
|
||||||
} on Exception catch(err) {
|
} on Exception catch(err) {
|
||||||
print("Cannot open file $gEventsFilename");
|
print("cannot open file $gEventsFilename");
|
||||||
}
|
}
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
|
@@ -154,7 +154,7 @@ class Relays {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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); },
|
onError: (err) { print("\n${gWarningColor}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 {
|
||||||
|
@@ -2,10 +2,9 @@
|
|||||||
// for debugging
|
// for debugging
|
||||||
String gCheckEventId = "a4479de655094679cdfb10f347521aa58f24717cdc5ddba89fb346453a8a99ed";
|
String gCheckEventId = "a4479de655094679cdfb10f347521aa58f24717cdc5ddba89fb346453a8a99ed";
|
||||||
|
|
||||||
|
|
||||||
String gRemoteAdminPubkey = "";
|
String gRemoteAdminPubkey = "";
|
||||||
|
|
||||||
const int numWaitSeconds = 3000;
|
const int numWaitSeconds = 3000;
|
||||||
|
|
||||||
// global counters of total events read or processed
|
// global counters of total events read or processed
|
||||||
int numFileEvents = 0, numUserEvents = 0, numFeedEvents = 0, numOtherEvents = 0;
|
int numFileEvents = 0, numUserEvents = 0, numFeedEvents = 0, numOtherEvents = 0;
|
||||||
@@ -16,10 +15,9 @@ List<String> gListRelayUrls = [defaultServerUrl,
|
|||||||
"wss://nostr-pub.wellorder.net",
|
"wss://nostr-pub.wellorder.net",
|
||||||
"wss://relay.damus.io"];
|
"wss://relay.damus.io"];
|
||||||
|
|
||||||
|
|
||||||
// name of executable
|
// name of executable
|
||||||
const String exename = "nostr_console";
|
const String exename = "nostr_console";
|
||||||
const String version = "0.0.6";
|
const String version = "0.0.7";
|
||||||
|
|
||||||
// well known disposable test private key
|
// well known disposable test private key
|
||||||
const String gDefaultPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
|
const String gDefaultPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
|
||||||
@@ -42,12 +40,31 @@ const int gDefaultMaxDepth = 4;
|
|||||||
int maxDepthAllowed = gDefaultMaxDepth;
|
int maxDepthAllowed = gDefaultMaxDepth;
|
||||||
const int leftShiftThreadsBy = 2;
|
const int leftShiftThreadsBy = 2;
|
||||||
|
|
||||||
|
|
||||||
|
// text color
|
||||||
|
const String defaultTextColor = "green";
|
||||||
|
|
||||||
|
const String greenColor = "\x1B[32m"; // green
|
||||||
|
const String cyanColor = "\x1b[36m"; // cyan
|
||||||
|
const String whiteColor = "\x1b[37m"; // white
|
||||||
|
const String blackColor = "\x1b[30m"; // black
|
||||||
|
const String redColor = "\x1B[31m"; // red
|
||||||
|
const String blueColor = "\x1b[34m"; // blue
|
||||||
|
|
||||||
|
Map<String, String> gColorMap = { "green": greenColor,
|
||||||
|
"cyan" : cyanColor,
|
||||||
|
"white": whiteColor,
|
||||||
|
"black": blackColor,
|
||||||
|
"red" : redColor,
|
||||||
|
"blue" : blueColor};
|
||||||
|
|
||||||
// 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
|
String gCommentColor = greenColor;
|
||||||
const String notificationColor = "\x1b[36m"; // cyan
|
String gNotificationColor = cyanColor; // cyan
|
||||||
const String warningColor = "\x1B[31m"; // red
|
String gWarningColor = redColor; // red
|
||||||
const String colorEndMarker = "\x1B[0m";
|
const String colorEndMarker = "\x1B[0m";
|
||||||
|
|
||||||
|
|
||||||
//String defaultServerUrl = 'wss://relay.damus.io';
|
//String defaultServerUrl = 'wss://relay.damus.io';
|
||||||
const String nostrRelayUnther = 'wss://nostr-relay.untethr.me';
|
const String nostrRelayUnther = 'wss://nostr-relay.untethr.me';
|
||||||
String defaultServerUrl = nostrRelayUnther;
|
String defaultServerUrl = nostrRelayUnther;
|
||||||
@@ -57,7 +74,8 @@ const String gDummyAccountPubkey = "Non";
|
|||||||
|
|
||||||
// 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
|
||||||
int gNumLastDays = 1;
|
const int gDefaultNumLastDays = 1;
|
||||||
|
int gNumLastDays = gDefaultNumLastDays;
|
||||||
|
|
||||||
// global user names from kind 0 events, mapped from public key to user name
|
// global user names from kind 0 events, mapped from public key to user name
|
||||||
Map<String, String> gKindONames = {};
|
Map<String, String> gKindONames = {};
|
||||||
@@ -75,7 +93,7 @@ List<String> gBots = [ "3b57518d02e6acfd5eb7198530b2e351e5a52278fb2499d14b66db2
|
|||||||
"6a9eb714c2889aa32e449cfbb7854bc9780feed4ff3d887e03910dcb22aa560a" // "bible bot"
|
"6a9eb714c2889aa32e449cfbb7854bc9780feed4ff3d887e03910dcb22aa560a" // "bible bot"
|
||||||
];
|
];
|
||||||
|
|
||||||
//const String gDefaultEventsFilename = "events_store_nostr.txt";
|
const String gDefaultEventsFilename = "all_nostr_events.txt";
|
||||||
String gEventsFilename = ""; // is set in arguments, and if set, then file is read from and written to
|
String gEventsFilename = ""; // is set in arguments, and if set, then file is read from and written to
|
||||||
|
|
||||||
const String gUsage = """$exename version $version
|
const String gUsage = """$exename version $version
|
||||||
@@ -85,27 +103,32 @@ 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
|
-p, --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
|
well known private key. When given, posts/replies can't be sent.
|
||||||
--prikey <private key> The hex private key of user whose events and feed are shown. Also used to sign events
|
-k, --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 -k
|
sent. Default is a hard-coded well known private key.
|
||||||
--relay <relay wss url> The relay url that is used as main relay. Default is $nostrRelayUnther . Same as -r
|
-r, --relay <relay wss url> The relay url that is used as main relay. Default is $nostrRelayUnther.
|
||||||
--days <N as num> The latest number of days for which events are shown. Default is 1. Same as -d
|
-d, --days <N as num> The latest number of days for which events are shown. Default is $gDefaultNumLastDays.
|
||||||
--request <REQ string> This request is sent verbatim to the default relay. It can be used to recieve all events
|
-q, --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.
|
||||||
--file <filename> Read from given file, if it is present, and at the end of the program execution, write
|
-f, --file <filename> Read from given file, if it is present, and at the end of the program execution, write
|
||||||
to it all the events (including the ones read, and any new received). Same as -f
|
to it all the events (including the ones read, and any new received). Even if not given,
|
||||||
--translate This flag, if present, will make the application translate some of the recent posts using
|
the default is to read from and write to $gDefaultEventsFilename . Can be turned off by
|
||||||
google translate. Save as -t
|
the --disable-file flag
|
||||||
|
-n, --disable-file When turned on, even the default filename is not read from.
|
||||||
|
-t, --translate This flag, if present, will make the application translate some of the recent posts using
|
||||||
|
google translate.
|
||||||
|
|
||||||
UI Options
|
UI Options
|
||||||
--align <left> When "left" is given as option to this argument, then the text is aligned to left. By default
|
-a, --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.
|
||||||
--width <width as num> This specifies how wide you want the text to be, in number of columns. Default is $gDefaultTextWidth.
|
-w, --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 -w
|
Cant be less than $gMinValidTextWidth.
|
||||||
--maxdepth <depth as num> The maximum depth to which the threads can be displayed. Minimum is $gMinimumDepthAllowed and
|
-m, --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
|
maximum allowed is $gMaximumDepthAllowed.
|
||||||
--help Print this usage message and exit. Same as -h
|
-c, --color <color> Color option can be green, cyan, white, black, red and blue.
|
||||||
|
-h, --help Print this usage message and exit.
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
const String helpAndAbout =
|
const String helpAndAbout =
|
||||||
|
Reference in New Issue
Block a user