Minor refactoring, no functional changes
This commit is contained in:
parent
670b9b86d6
commit
f944882cc6
45
contact.scm
45
contact.scm
|
@ -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,28 +39,37 @@
|
||||||
;; 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, 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-app (qt:init))
|
||||||
(set! qt-win (create-window))
|
(set! qt-win (create-window))
|
||||||
(init-window qt-win)
|
(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))
|
||||||
|
|
||||||
(let ;; Start QT loop.
|
|
||||||
[(qt-thread (thread-start! qt-loop))
|
;; Kick off our remote TCP-accessible REPL, if the user enabled it at cli.
|
||||||
;; Kick off the remote-REPL…
|
(define (init-nrepl cli-args)
|
||||||
(nrepl-thread
|
|
||||||
(if (alist-ref 'repl cli-args)
|
(if (alist-ref 'repl cli-args)
|
||||||
(thread-start!
|
(thread-start!
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(nrepl (string->number (alist-ref 'repl cli-args)))))))]
|
(nrepl: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.
|
|
||||||
(thread-join! qt-thread))))
|
|
||||||
|
|
||||||
|
|
||||||
;; 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.
|
||||||
|
|
Ŝarĝante…
Reference in New Issue