What is Nostr?
CodeWarrior /
npub1yxn…y9wl
2023-05-02 20:01:51
in reply to nevent1q…gdzr

CodeWarrior on Nostr: From 63e06c5c8040f9907b054f3b6471dcfdd813645f Mon Sep 17 00:00:00 2001 From: anon <> ...

From 63e06c5c8040f9907b054f3b6471dcfdd813645f Mon Sep 17 00:00:00 2001
From: anon <>
Date: Tue, 2 May 2023 15:31:59 -0400
Subject: [PATCH] added pretty colours

---
hellostr.py | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/hellostr.py b/hellostr.py
index 33e9d01..e8f84fe 100644
--- a/hellostr.py
+++ b/hellostr.py
@@ -12,8 +12,20 @@ NOSTR_IN_A_NUTSHELL = [
"H0DL",
"ST4CK3M",
"G0551P",
- "1R15"
+ "1R15",
+ "G00DM0RN1NG"
]
+
+COLORCS = [
+ '\033[96m', # cyan
+ '\033[95m', # magenta
+ '\033[94m', # blue
+ '\033[93m', # yellow
+ '\033[92m', # green
+ '\033[91m', # red
+ '\033[90m' # grey
+]
+
PLACEHODLERS = [character for character in "0123456789abcdef"]
PRINT_WIDTH = 60
DURATION = 10
@@ -51,25 +63,38 @@ if __name__ == "__main__":
# currently not speaking?
if selected_statement == -1:

+ # set a marker to signal if we started speaking
+ started_speaking = False
+
# small chance to start saying something...
if random.randint(0, 19) > 18:

# randomly choose a selected_statement from the provided array
selected_statement = random.randint(0, len(NOSTR_IN_A_NUTSHELL) - 1 )

+
+ # signal that we started speaking
+ started_speaking = True
+
# reset next char position... this is incremented at start of while loop
# so the first one printed will be char 0
next_char_from_string = -1

# print placeholder whether we're selected something to say or not...
print(chosen_placeholder, end="", flush=True)
+
+ # change colour AFTER placeholder iff we started speaking anew
+ if started_speaking:
+ print(random.choice(COLORCS), end="")
+
continue

# finished speaking?
if next_char_from_string > len(NOSTR_IN_A_NUTSHELL[selected_statement]) - 1:
# reset statement id
selected_statement = -1
- # print placeholder
+ # endc and print next placeholder
+ print('\033[0m', end="")
print(chosen_placeholder, end="", flush=True)
continue

@@ -77,4 +102,7 @@ if __name__ == "__main__":
next_char_to_print = NOSTR_IN_A_NUTSHELL[selected_statement][next_char_from_string]
print(next_char_to_print, end="", flush=True)

+ # endc to avoid messing up your terminal
+ print('\033[0m', end="")
+ # goodbye
print("\nEnjoy your stay!")
--
2.37.2
Author Public Key
npub1yxnszndjhgt6ej9mh9ykv3ggfpntgmsm5qrz4qz38t76gp29qxpsmky9wl