Minor refactoring, no functional changes

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

View File

@ -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 <qt-application> 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, lets 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 windows forms with its contents.