Minor refactoring, no functional changes

This commit is contained in:
Jaidyn Ann 2024-02-09 16:26:34 -06:00
parent 670b9b86d6
commit f944882cc6

View File

@ -23,13 +23,13 @@
(chicken process-context) (chicken process-context)
(chicken string) (chicken string)
(chicken time) (chicken time)
srfi-1 (srfi 1)
srfi-18 (srfi 18)
(prefix getopt-long getopt:) (prefix getopt-long getopt:)
nrepl (prefix nrepl nrepl:)
qt-light
(prefix uri-common uri:) (prefix uri-common uri:)
(prefix vcarded vcard:)) (prefix vcarded vcard:)
qt-light)
(define qt-app #f) ;; The <qt-application> object. (define qt-app #f) ;; The <qt-application> object.
@ -39,30 +39,39 @@
;; Start & run the application. ;; Start & run the application.
(define (init) (define (init)
(let [(cli-args (parse-cli-args (command-line-arguments)))] (let [(cli-args (parse-cli-args (command-line-arguments)))]
;; If --help, then print a usage message and quit.
(if (alist-ref 'help cli-args) (if (alist-ref 'help cli-args)
(cli-usage)) (cli-usage))
;; Set up some global state, prepare the QT app. ;; Otherwise, lets get our threads started!
(set! qt-app (qt:init)) (let [(qt-thread (init-qt cli-args))
(set! qt-win (create-window)) (nrepl-thread (init-nrepl cli-args))
(init-window qt-win) (repl-thread (thread-start! repl))]
(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)
;; Wait for the QT program, even after stdin is closed off. ;; Wait for the QT program, even after stdin is closed off.
(thread-join! qt-thread)))) (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. ;; Print a “usage” help message, telling the user how to run the program.
(define (cli-usage) (define (cli-usage)
(print "usage: " (pathname-file (program-name)) " [-h] [--repl PORT] [VCF_FILE]") (print "usage: " (pathname-file (program-name)) " [-h] [--repl PORT] [VCF_FILE]")