From 52ab0cc45818bfe3d0c73fe21f2ef783be76b6cd Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:26:34 -0600 Subject: [PATCH] Minor refactoring, no functional changes --- contact.scm | 59 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/contact.scm b/contact.scm index 22bbc3f..1cff122 100644 --- a/contact.scm +++ b/contact.scm @@ -23,13 +23,13 @@ (chicken process-context) (chicken string) (chicken time) - srfi-1 - srfi-18 + (srfi 1) + (srfi 18) (prefix getopt-long getopt:) - nrepl - qt-light + (prefix nrepl nrepl:) (prefix uri-common uri:) - (prefix vcarded vcard:)) + (prefix vcarded vcard:) + qt-light) (define qt-app #f) ;; The object. @@ -39,30 +39,39 @@ ;; Start & run the application. (define (init) (let [(cli-args (parse-cli-args (command-line-arguments)))] + ;; If --help, then print a usage message and quit. (if (alist-ref 'help cli-args) (cli-usage)) - ;; Set up some global state, prepare the QT app. - (set! qt-app (qt:init)) - (set! qt-win (create-window)) - (init-window qt-win) - - (let ;; Start QT loop. - [(qt-thread (thread-start! qt-loop)) - ;; Kick off the remote-REPL… - (nrepl-thread - (if (alist-ref 'repl cli-args) - (thread-start! - (lambda () - (nrepl (string->number (alist-ref 'repl cli-args)))))))] - ;; Open the free-argument file. - (if (condition-case (not (null? (last (car cli-args)))) (var () #f)) - (open-vcard-file qt-win (last (car cli-args)))) - ;; … and also provide a local REPL. - (repl) + ;; Otherwise, let’s get our threads started! + (let [(qt-thread (init-qt cli-args)) + (nrepl-thread (init-nrepl cli-args)) + (repl-thread (thread-start! repl))] ;; Wait for the QT program, even after stdin is closed off. (thread-join! qt-thread)))) +;; Set up some global variables (for easier live REPL use), prepare the QT app. +(define (init-qt cli-args) + (set! qt-app (qt:init)) + (set! qt-win (create-window)) + (init-window qt-win) + ;; Kick off the QT thread, then open the cli free-arg vCard file, if provided. + ;; That is, like `$ contact freeArgFile.vcf`. + (let [(qt-thread (thread-start! qt-loop)) + (last-free-arg (condition-case (last (car cli-args)) (var () #f)))] + (if last-free-arg + (open-vcard-file qt-win last-free-arg)) + qt-thread)) + + +;; Kick off our remote TCP-accessible REPL, if the user enabled it at cli. +(define (init-nrepl cli-args) + (if (alist-ref 'repl cli-args) + (thread-start! + (lambda () + (nrepl:nrepl (string->number (alist-ref 'repl cli-args))))))) + + ;; Print a “usage” help message, telling the user how to run the program. (define (cli-usage) (print "usage: " (pathname-file (program-name)) " [-h] [--repl PORT] [VCF_FILE]") @@ -147,7 +156,9 @@ (lambda () (open-vcard-file window - (qt:get-open-filename "birdo" "/home/jaidyn/Contacts")))))))) + (qt:get-open-filename + "Select a contact file…" + (conc (get-environment-variable "HOME") "/Contacts"))))))))) ;; Parse a vCard file and populate the window’s forms with its contents.