mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-03-27 02:01:51 +01: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:
parent
94ef7d5ed1
commit
a09c046787
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,3 +19,5 @@ doc/api/
|
||||
*.js_
|
||||
*.js.deps
|
||||
*.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 maxDepthArg = "maxdepth";
|
||||
const String eventFileArg = "file";
|
||||
const String disableFileArg = "disable-file";
|
||||
|
||||
const String translateArg = "translate";
|
||||
const String colorArg = "color";
|
||||
|
||||
void printUsage() {
|
||||
print(gUsage);
|
||||
@ -30,7 +33,9 @@ Future<void> main(List<String> arguments) async {
|
||||
..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
|
||||
..addFlag(helpArg, abbr:"h", defaultsTo: false)..addOption(alignArg, abbr:"a")
|
||||
..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 {
|
||||
ArgResults argResults = parser.parse(arguments);
|
||||
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");
|
||||
}
|
||||
}
|
||||
if( argResults[eventFileArg] != null) {
|
||||
gEventsFilename = argResults[eventFileArg];
|
||||
if( gEventsFilename != "") {
|
||||
print("Going to use file to read from and store events: $gEventsFilename");
|
||||
|
||||
if( argResults[colorArg] != null) {
|
||||
String colorGiven = argResults[colorArg].toString().toLowerCase();
|
||||
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 != "") {
|
||||
print("\n");
|
||||
stdout.write('Reading events from the given file.......');
|
||||
stdout.write('Reading events from ${whetherDefault}file.......');
|
||||
List<Event> eventsFromFile = readEventsFromFile(gEventsFilename);
|
||||
setRelaysIntialEvents(eventsFromFile);
|
||||
eventsFromFile.forEach((element) { element.eventData.kind == 1? numFileEvents++: numFileEvents;});
|
||||
print("read $numFileEvents posts from file \"$gEventsFilename\"");
|
||||
}
|
||||
if( argResults[requestArg] != null) {
|
||||
//stdout.write("Got argument request: ${argResults[requestArg]}");
|
||||
stdout.write('Sending request and waiting for events...');
|
||||
sendRequest(gListRelayUrls, argResults[requestArg]);
|
||||
Future.delayed(const Duration(milliseconds: 6000), () {
|
||||
Future.delayed(const Duration(milliseconds: numWaitSeconds * 2), () {
|
||||
List<Event> receivedEvents = getRecievedEvents();
|
||||
stdout.write("received ${receivedEvents.length - numFileEvents} events\n");
|
||||
|
||||
|
@ -13,8 +13,8 @@ Future<void> processNotifications(Tree node) async {
|
||||
|
||||
List<String> newEventsId = node.insertEvents(getRecievedEvents());
|
||||
String nameToDisplay = userPrivateKey.length == 64?
|
||||
"$commentColor${getAuthorName(userPublicKey)}$colorEndMarker":
|
||||
"${warningColor}You are not signed in$colorEndMarker but are using public key $userPublicKey";
|
||||
"$gCommentColor${getAuthorName(userPublicKey)}$colorEndMarker":
|
||||
"${gWarningColor}You are not signed in$colorEndMarker but are using public key $userPublicKey";
|
||||
node.printNotifications(newEventsId, nameToDisplay);
|
||||
clearEvents();
|
||||
});
|
||||
|
@ -317,10 +317,10 @@ class EventData {
|
||||
printDepth(depth);
|
||||
stdout.write("|Message: ");
|
||||
if( isNotification) {
|
||||
printInColor(contentShifted, notificationColor);
|
||||
printInColor(contentShifted, gNotificationColor);
|
||||
isNotification = false;
|
||||
} else {
|
||||
printInColor(contentShifted, commentColor);
|
||||
printInColor(contentShifted, gCommentColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ class EventData {
|
||||
String reactorId = reactors[i][0];
|
||||
if( newLikes.contains(reactorId)) {
|
||||
// colorify
|
||||
reactorNames += notificationColor + getAuthorName(reactorId) + colorEndMarker;
|
||||
reactorNames += gNotificationColor + getAuthorName(reactorId) + colorEndMarker;
|
||||
} else {
|
||||
reactorNames += getAuthorName(reactorId);
|
||||
}
|
||||
@ -512,7 +512,7 @@ List<Event> readEventsFromFile(String filename) {
|
||||
events.add(e);
|
||||
}
|
||||
} on Exception catch(err) {
|
||||
print("Cannot open file $gEventsFilename");
|
||||
print("cannot open file $gEventsFilename");
|
||||
}
|
||||
|
||||
return events;
|
||||
|
@ -154,7 +154,7 @@ class Relays {
|
||||
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'); }
|
||||
);
|
||||
} on WebSocketException {
|
||||
|
@ -2,10 +2,9 @@
|
||||
// for debugging
|
||||
String gCheckEventId = "a4479de655094679cdfb10f347521aa58f24717cdc5ddba89fb346453a8a99ed";
|
||||
|
||||
|
||||
String gRemoteAdminPubkey = "";
|
||||
|
||||
const int numWaitSeconds = 3000;
|
||||
const int numWaitSeconds = 3000;
|
||||
|
||||
// global counters of total events read or processed
|
||||
int numFileEvents = 0, numUserEvents = 0, numFeedEvents = 0, numOtherEvents = 0;
|
||||
@ -16,10 +15,9 @@ List<String> gListRelayUrls = [defaultServerUrl,
|
||||
"wss://nostr-pub.wellorder.net",
|
||||
"wss://relay.damus.io"];
|
||||
|
||||
|
||||
// name of executable
|
||||
const String exename = "nostr_console";
|
||||
const String version = "0.0.6";
|
||||
const String version = "0.0.7";
|
||||
|
||||
// well known disposable test private key
|
||||
const String gDefaultPrivateKey = "9d00d99c8dfad84534d3b395280ca3b3e81be5361d69dc0abf8e0fdf5a9d52f9";
|
||||
@ -42,12 +40,31 @@ const int gDefaultMaxDepth = 4;
|
||||
int maxDepthAllowed = gDefaultMaxDepth;
|
||||
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.
|
||||
const String commentColor = "\x1B[32m"; // green
|
||||
const String notificationColor = "\x1b[36m"; // cyan
|
||||
const String warningColor = "\x1B[31m"; // red
|
||||
String gCommentColor = greenColor;
|
||||
String gNotificationColor = cyanColor; // cyan
|
||||
String gWarningColor = redColor; // red
|
||||
const String colorEndMarker = "\x1B[0m";
|
||||
|
||||
|
||||
//String defaultServerUrl = 'wss://relay.damus.io';
|
||||
const String nostrRelayUnther = 'wss://nostr-relay.untethr.me';
|
||||
String defaultServerUrl = nostrRelayUnther;
|
||||
@ -57,7 +74,8 @@ const String gDummyAccountPubkey = "Non";
|
||||
|
||||
// By default the threads that were started in last one day are shown
|
||||
// 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
|
||||
Map<String, String> gKindONames = {};
|
||||
@ -75,7 +93,7 @@ List<String> gBots = [ "3b57518d02e6acfd5eb7198530b2e351e5a52278fb2499d14b66db2
|
||||
"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
|
||||
|
||||
const String gUsage = """$exename version $version
|
||||
@ -85,27 +103,32 @@ usage: $exename [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
|
||||
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 $nostrRelayUnther . Same as -r
|
||||
--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
|
||||
from a relay. If not provided, then events for default or given user are shown. Same as -q
|
||||
--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
|
||||
--translate This flag, if present, will make the application translate some of the recent posts using
|
||||
google translate. Save as -t
|
||||
-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.
|
||||
-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.
|
||||
-r, --relay <relay wss url> The relay url that is used as main relay. Default is $nostrRelayUnther.
|
||||
-d, --days <N as num> The latest number of days for which events are shown. Default is $gDefaultNumLastDays.
|
||||
-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.
|
||||
-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). Even if not given,
|
||||
the default is to read from and write to $gDefaultEventsFilename . Can be turned off by
|
||||
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
|
||||
--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
|
||||
--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
|
||||
--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
|
||||
|
||||
-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.
|
||||
-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.
|
||||
-m, --maxdepth <depth as num> The maximum depth to which the threads can be displayed. Minimum is $gMinimumDepthAllowed and
|
||||
maximum allowed is $gMaximumDepthAllowed.
|
||||
-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 =
|
||||
|
Loading…
x
Reference in New Issue
Block a user