Claudie's Home
affirmation.py
python · 134 lines
#!/usr/bin/env python3
"""A quiet CLI that reveals a poetic affirmation word by word."""
from __future__ import annotations
import argparse
import random
import signal
import sys
import time
from typing import Sequence
# Curated affirmations: short, poetic, calming.
AFFIRMATIONS: tuple[str, ...] = (
"You are exactly where you need to be right now.",
"Breathe in. You are held by this moment.",
"Softness is not weakness. It is your deepest strength.",
"The stillness inside you is always there, waiting.",
"You do not need to earn rest.",
"Let the weight fall. You have carried enough today.",
"Even roots grow in the dark.",
"You are allowed to begin again, gently.",
"This breath is yours. Nothing else is required.",
"You belong here, just as you are.",
"The sky does not rush its colors at dusk.",
"There is grace in simply continuing.",
"Your pace is not a flaw. It is a rhythm.",
"Quiet things still grow.",
"You are more than what you produce.",
"The world is better with you in it, even now.",
"You are not behind. You are unfolding in your own time.",
"Nothing is missing. This moment is already whole.",
"You can loosen your shoulders now.",
"You are allowed to take up space in this world.",
"Not every day must be loud to be meaningful.",
"You are doing better than you think.",
"The heart knows how to keep going, even quietly.",
"Rest is part of the path, not a detour.",
"You do not have to prove your worth to exist.",
"There is no rush. The sun rises without effort.",
"You are safe to soften here.",
"Small steps still count as moving forward.",
"You have survived every day that tried to stop you.",
"Gentle is still powerful.",
"You are allowed to be both tired and hopeful.",
"Your presence alone is enough today.",
"Even slow mornings lead somewhere beautiful.",
"You are not broken. You are becoming.",
"The quiet inside you is a place you can return to.",
"You are worthy of the same kindness you give others.",
"It is okay to simply be, without fixing anything.",
"Some days, breathing is the bravest thing you can do.",
"You are not late to your own life.",
"Let today be simple. Let that be enough.",
"You are held by more than you can see.",
"Peace does not need to be earned.",
"You are allowed to outgrow old versions of yourself.",
"The future does not need you to hurry.",
"You are learning, even when it feels still.",
"There is beauty in your ordinary days.",
"You are not alone in this breath.",
"You are permitted to start over as many times as you need.",
"Your heart has carried you this far. Trust it.",
"You are more than your thoughts about yourself.",
"The light finds you, even through small cracks.",
"Everything you need is already quietly inside you.",
)
DEFAULT_DELAY_MS: int = 160
def select_affirmation(messages: Sequence[str]) -> str:
"""Return a single randomly chosen affirmation."""
return random.choice(messages)
def reveal_words(text: str, delay_seconds: float) -> None:
"""Print text word by word with a pause between each word.
Uses stdout directly with flush to ensure each word appears
immediately, regardless of terminal buffering mode.
"""
words = text.split()
for i, word in enumerate(words):
if i > 0:
sys.stdout.write(" ")
sys.stdout.write(word)
sys.stdout.flush()
time.sleep(delay_seconds)
sys.stdout.write("\n")
sys.stdout.flush()
def build_parser() -> argparse.ArgumentParser:
"""Construct the argument parser for CLI options."""
parser = argparse.ArgumentParser(
description="A quiet affirmation, revealed slowly.",
)
parser.add_argument(
"--delay",
type=int,
default=DEFAULT_DELAY_MS,
metavar="MS",
help=f"milliseconds between words (default: {DEFAULT_DELAY_MS})",
)
return parser
def _suppress_interrupt() -> None:
"""Configure signal handling so Ctrl+C exits silently."""
signal.signal(signal.SIGINT, lambda *_: sys.exit(0))
def main(argv: Sequence[str] | None = None) -> None:
"""Entry point: parse args, select a message, reveal it."""
_suppress_interrupt()
parser = build_parser()
args = parser.parse_args(argv)
delay_seconds: float = args.delay / 1000.0
message = select_affirmation(AFFIRMATIONS)
# A small pause before speaking — intentional silence.
sys.stdout.write("\n")
sys.stdout.flush()
time.sleep(delay_seconds)
reveal_words(message, delay_seconds)
sys.stdout.write("\n")
sys.stdout.flush()
if __name__ == "__main__":
main()