aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-05 14:26:43 +0200
committerDanilo M. <danix@danix.xyz>2026-10-05 14:26:43 +0200
commit5ecfc3540437625d12cefac18a941acde63bc72e (patch)
tree6b56499eb8138331d28b5a540a4e00e95f24ee58
parented4c217786ccb6f3c106f42209bcf31ac8871753 (diff)
downloadfanfictioner-5ecfc3540437625d12cefac18a941acde63bc72e.tar.gz
fanfictioner-5ecfc3540437625d12cefac18a941acde63bc72e.zip
Notify with notify-send, preview outside kitty with xdg-open
kitty's OSC 99 notifications only worked inside kitty. Use notify-send instead, passing the id of the previous notification with -r so each one replaces the last rather than stacking. Outside kitty, where icat cannot draw, open the candidate montage with xdg-open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--README.md3
-rwxr-xr-xfanfictioner24
2 files changed, 18 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0de61a3..3e57d6d 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,8 @@ image stage. Pages land in the book-reader library as `NNN.png`.
- Python 3, stdlib only
- llama-server in router mode on `localhost:8181` serving `Gemma4-12B-qat-mtp`
- `sd-cli` with Vulkan, models under `/data/LLM-models/SD`
-- ImageMagick 7 (`magick`), kitty (`kitty +kitten icat`), `$EDITOR`
+- ImageMagick 7 (`magick`), `$EDITOR`, `notify-send` (libnotify), and kitty for
+ inline previews (elsewhere candidates open with `xdg-open`)
- `~/.config/book-reader.conf` with a `LIBRARY="..."` line
## Usage
diff --git a/fanfictioner b/fanfictioner
index 72c2e85..89a3fec 100755
--- a/fanfictioner
+++ b/fanfictioner
@@ -416,13 +416,18 @@ def log(msg):
f.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} {msg}\n")
+NOTIFY_ID = None # notify-send id of the last notification, replaced by the next one
+
+
def notify(body):
- """Desktop notification via kitty (OSC 99). One fixed id, so each replaces the last instead of
- stacking; shown only while the terminal is unfocused."""
- if sys.stdout.isatty():
- body = re.sub(r"[\x00-\x1f\x7f]", " ", body)
- print(f"\x1b]99;i=fanfictioner:d=0:o=unfocused;fanfictioner\x1b\\"
- f"\x1b]99;i=fanfictioner:d=1:p=body;{body}\x1b\\", end="", flush=True)
+ """Desktop notification that replaces the previous one instead of stacking."""
+ global NOTIFY_ID
+ try:
+ out = subprocess.run(["notify-send", "-a", "fanfictioner", "-p", *(["-r", NOTIFY_ID] if NOTIFY_ID else []),
+ "fanfictioner", body], capture_output=True, text=True, timeout=5).stdout.strip()
+ except (OSError, subprocess.TimeoutExpired):
+ return
+ NOTIFY_ID = out if out.isdigit() else None
def editor(path):
@@ -470,8 +475,11 @@ def show(files, seed, d):
print("montage failed, candidates:", *files, sep="\n")
return
print(m)
- try:
- subprocess.run(["kitty", "+kitten", "icat", str(fit(m))])
+ try: # inline in kitty, else in the desktop's image viewer
+ if os.environ.get("KITTY_WINDOW_ID"):
+ subprocess.run(["kitty", "+kitten", "icat", str(fit(m))])
+ else:
+ subprocess.Popen(["xdg-open", str(m)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except OSError as e:
print(f"cannot show image: {e}")