commit 24314f1526dfe7aa9fb3af8ea7f99d18472654b9
parent 43d6e36d79a7f4a6ef44e28d92bc14e9461b0e57
Author: lou woell <lou@repetitions.de>
Date: Mon, 30 Mar 2026 17:44:18 +0200
handle aborted selection
also implements more generic display string.
Diffstat:
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/linkhut-dmenu.scm b/linkhut-dmenu.scm
@@ -12,10 +12,13 @@
(define prompt "Bookmark: ")
-;; (post ...) -> ((title . post) ...)
+;; (post ...) -> ((format-string . post) ...)
(define (show posts)
- (map (lambda (post) (cons (get-post-value 'title post)
- (car post)))
+ (map (lambda (post)
+ (cons (format #f "~A, ~A"
+ (get-post-value 'title post)
+ (get-post-value 'tags post))
+ post))
posts))
;; Spawn a menu let the user select a post.
@@ -35,27 +38,19 @@
(map (lambda (entry) (write-line (car entry) (cdr in-pipe)))
entries)
+
(close-port (cdr in-pipe))
- (let ((result (read-line (car out-pipe))))
+ (let* ((return-code (/ (cdr (waitpid pid)) 256))
+ (result (read-line (car out-pipe)))
+ (selected-post (assoc result entries))
+ (selection (if selected-post
+ (cdr selected-post)
+ (format #f "No post selected.~%Result: ~A." result))))
(close-port (car out-pipe))
+ (values return-code selection))))
- ;; return (exit code . post entry)
- (values (/ (cdr (waitpid pid)) 256)
- (assoc (cdr (assoc result entries))
- posts)))))
-
-(define* (mark-read post #:key (shared #t))
- (post-add (get-post-value 'link post)
- (get-post-value 'title post)
- #:extended (get-post-value 'note post)
- #:tags (filter (lambda (x) (not (string= x "unread")))
- (get-post-value 'tags post))
- #:shared shared
- #:replace #t
- #:toread #f))
-
-(define* (mark-unread post #:key (shared #t))
+(define* (mark-read post #:optional (read #t) #:key (shared #t))
(post-add (get-post-value 'link post)
(get-post-value 'title post)
#:extended (get-post-value 'note post)
@@ -63,15 +58,19 @@
(get-post-value 'tags post))
#:shared shared
#:replace #t
- #:toread #t))
+ #:toread read))
(define (open-link post)
(waitpid (spawn "xdg-open" `("xdg-open" ,(get-post-value 'link post)))))
(define (main args)
- (let-values (((code post) (menu (post-get #:tag "unread"))))
+ (let-values
+ (((code post) (menu (post-get #:tag "unread"))))
(case code
- ((00) (open-link post))
- ((10) (mark-read post))
+ ((01) (format #t "menu aborted.~%~A" post))
+ ((00) (open-link post)) ;; RET.
+ ((10) (mark-read post)) ;; bemenu: selecting with M-1.
+ ((11) (mark-read post #:shared #f)) ;; bemenu: selecting with M-2.
+ ;; ...
(else (display post)))
(newline)))
diff --git a/linkhut.scm b/linkhut.scm
@@ -120,7 +120,7 @@
(others ,others)
(time ,time)
(meta ,meta)))
- (list (string->number hash 16)
+ (list (cons 'id (string->number hash 16))
(cons 'title desc)
(cons 'note ext)
(cons 'link link)
@@ -150,7 +150,7 @@
;; Gets value of property PROP of POST.
(define (get-post-value prop post)
- (cdr (assoc prop (cdr post))))
+ (cdr (assoc prop post)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;