diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index a3b724c..254b1ee 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -144,8 +144,8 @@ Future main(List arguments) async { if( argResults[colorArg] != null) { String colorGiven = argResults[colorArg].toString().toLowerCase(); - if( gColorMap.containsKey(colorGiven)) { - String color = gColorMap[colorGiven]??""; + if( gColorMapForArguments.containsKey(colorGiven)) { + String color = gColorMapForArguments[colorGiven]??""; if( color == "") { print("Invalid color."); } else diff --git a/lib/event_ds.dart b/lib/event_ds.dart index f631180..9a878c5 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -307,8 +307,26 @@ class EventData { } else { commentColor = gCommentColor; } - - int extraLen = name.length + 4; + + //name = "$name"; + //name = name.padLeft(gNameLengthInPost); + int nameEffectiveLen = name.length < gNameLengthInPost? name.length: gNameLengthInPost; + name = name.substring(0,nameEffectiveLen); + + String nameInside = " "; + if( name.length %2 == 1 ) // odd len names need an extra dash + name = name + nameInside; + + + + String nameColor = getNameColor(name); + name = getNumDashes((gNameLengthInPost - name.length)~/2, nameInside ) + getStrInColor(name, nameColor) + getNumDashes((gNameLengthInPost - name.length)~/2 , nameInside); + + int extraLen = name.length + 3; // get this before name is mangled by color + //name = getStrInColor(name, nameColor); + // colorify the name + + String strToPrint = ""; //strToPrint += getDepthSpaces(depth); @@ -316,7 +334,7 @@ class EventData { strToPrint += "\n"; } strToPrint += getDepthSpaces(depth); - strToPrint += "└ ${name}: "; + strToPrint += " ${name}: "; const int typicalxLen = "|id: 82b5 , 12:04 AM Sep 19".length + 5; // not sure where 5 comes from @@ -706,22 +724,29 @@ String getAuthorName(String pubkey, [int len = 3]) { } // returns full public key(s) for the given username( which can be first few letters of pubkey, or the user name) -Set getPublicKeyFromName(String userName) { +Set getPublicKeyFromName(String inquiredName) { + if( inquiredName.length < 2) { + return {}; + } Set pubkeys = {}; //if(gDebug > 0) print("In getPublicKeyFromName: doing lookup for $userName len of gKindONames= ${gKindONames.length}"); - gKindONames.forEach((pk, userInfo) { + gKindONames.forEach((pubkey, userInfo) { // check both the user name, and the pubkey to search for the user - //print(userInfo.name); - if( userName == userInfo.name) { - pubkeys.add(pk); + + // check username + if( userInfo.name != null) { + int minNameLen = min( inquiredName.length, (userInfo.name?.length)??0); + if( inquiredName.toLowerCase() == userInfo.name?.substring(0, minNameLen).toLowerCase()) { + pubkeys.add(pubkey); + } } - if( userName.length <= pk.length) { - //print("$pk $userName" ); - if( pk.substring(0, userName.length) == userName) { - pubkeys.add(pk); + // check public key + if( inquiredName.length <= pubkey.length) { + if( pubkey.substring(0, inquiredName.length) == inquiredName) { + pubkeys.add(pubkey); } } }); diff --git a/lib/settings.dart b/lib/settings.dart index aa2c926..0db7ec9 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -86,7 +86,7 @@ List gDefaultFollows = [ // dummy account pubkey const String gDummyAccountPubkey = "Non"; -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// UI and Color related settings +//////////////////////////////////////////////////////////////////////////////////////////////////////////////// UI and Color const int gMinValidTextWidth = 60; // minimum text width acceptable const int gDefaultTextWidth = 100; // default text width int gTextWidth = gDefaultTextWidth; // is changed by --width option @@ -94,6 +94,7 @@ const int gSpacesPerDepth = 4; // constant int gNumLeftMarginSpaces = 0;// this number is modified in main String gAlignment = "center"; // is modified in main if --align argument is given const int gapBetweenTopTrees = 1; +const int gNameLengthInPost = 12; // after depth of maxDepthAllowed the thread is re-aligned to left by leftShiftThreadBy const int gMinimumDepthAllowed = 2; @@ -102,29 +103,50 @@ const int gDefaultMaxDepth = 4; int maxDepthAllowed = gDefaultMaxDepth; const int leftShiftThreadsBy = 2; +// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors // Color related settings const String defaultTextColor = "green"; const String greenColor = "\x1B[32m"; // green +const String yelloColor = "\x1B[33m"; // yellow +const String magentaColor = "\x1B[35m"; // magenta const String cyanColor = "\x1b[36m"; // cyan const String whiteColor = "\x1b[97m"; // white const String blackColor = "\x1b[30m"; // black const String redColor = "\x1B[31m"; // red const String blueColor = "\x1b[34m"; // blue -Map gColorMap = { "green": greenColor, +Map gColorMapForArguments = { "green": greenColor, "cyan" : cyanColor, "white": whiteColor, "black": blackColor, "red" : redColor, "blue" : blueColor}; +const String brightRedColor = "\x1B[91m"; // bright red const String brightGreenColor = "\x1B[92m"; // bright green +const String brightYellowColor = "\x1B[93m"; // bright yellow +const String brightBlueColor = "\x1B[94m"; // bright blue +const String brightCyanColor = "\x1B[96m"; // bright cyan +const String brightMagentaColor = "\x1B[95m"; // bright magenta + + // 33 yellow, 31 red, 34 blue, 35 magenta. Add 60 for bright versions. String gCommentColor = greenColor; String gNotificationColor = cyanColor; // cyan String gWarningColor = redColor; // red const String gColorEndMarker = "\x1B[0m"; +List nameColorPalette = [brightGreenColor, brightCyanColor, brightYellowColor, brightMagentaColor, brightBlueColor, brightRedColor, + yelloColor, magentaColor, redColor ]; + + +String getNameColor( String name) { + if( name.length == 0) + return nameColorPalette[0]; + + int offset = name.substring(0, 1).codeUnits[0] % nameColorPalette.length; + return nameColorPalette[offset]; +} // By default the threads that were started in last one day are shown // this can be changed with 'days' command line argument