Skip to content

Commit

Permalink
Show current state of settings in common-settings.
Browse files Browse the repository at this point in the history
Show current state of settings in `common-settings` with default states
for radio inputs, checkboxes and default input in `configure-slot`.
  • Loading branch information
hgluka authored and jmercouris committed Oct 4, 2023
1 parent b495dac commit 789192d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
27 changes: 22 additions & 5 deletions source/help.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
(type (getf (mopu:slot-properties (find-class class) slot)
:type))
(sources 'prompter:raw-source)
(input "")
(postprocess #'read-from-string))
"Set value of CLASS' SLOT in `*auto-config-file*'.
Prompt for a new value with prompt SOURCES and type-check
it against the SLOT's TYPE, if any. CLASS is a class symbol."
(sera:nlet lp ()
(let* ((input (prompt
:prompt (format nil "Configure slot value ~a" slot)
:input input
:sources sources))
(input (if (serapeum:single input)
(funcall postprocess (first input))
Expand Down Expand Up @@ -83,7 +85,7 @@ to the next."
`(.left
:flex "35%")
`(.right
:color ,theme:secondary
:color ,theme:primary
:flex "65%")))
(:div
:class "title-div"
Expand All @@ -106,21 +108,27 @@ to the next."
(:nradio
:name "keyscheme"
:vertical t
:checked (cond
((find 'nyxt/mode/emacs:emacs-mode (default-modes (current-buffer))) 'emacs)
((find 'nyxt/mode/vi:vi-normal-mode (default-modes (current-buffer))) 'vi)
((find 'nyxt/mode/vi:vi-insert-mode (default-modes (current-buffer))) 'vi)
(t 'cua))
:buffer buffer
'(cua "CUA (default)"
(nyxt::auto-configure
:form '(define-configuration (web-buffer prompt-buffer
panel-buffer nyxt/mode/editor:editor-buffer)
((default-modes (remove-if (lambda (m)
(find (symbol-name m)
'("EMACS-MODE" "VI-NORMAL-MODE" "VI-INSERT-MODE")))
'("EMACS-MODE" "VI-NORMAL-MODE" "VI-INSERT-MODE")
:test #'string=))
%slot-value%))))))
'(emacs "Emacs"
(nyxt::auto-configure
:form '(define-configuration (web-buffer prompt-buffer
panel-buffer nyxt/mode/editor:editor-buffer)
((default-modes (pushnew 'nyxt/mode/emacs:emacs-mode %slot-value%))))))
'(vi "VI"
'(vi "vi"
(nyxt::auto-configure
:form '(define-configuration (web-buffer prompt-buffer
panel-buffer nyxt/mode/editor:editor-buffer)
Expand All @@ -141,12 +149,16 @@ to the next."
:class "column left"
(:nradio
:name "theme"
:checked (if (equal (theme:background-color (theme *browser*))
(theme:background-color theme::+light-theme+))
'theme::+light-theme+
'theme::+dark-theme+)
:vertical t
:buffer buffer
'(theme::+light-theme+ "Light theme"
(nyxt::auto-configure :form '(define-configuration browser
((theme theme::+light-theme+)))))
'(theme::+light-theme+ "Dark theme"
'(theme::+dark-theme+ "Dark theme"
(nyxt::auto-configure :form '(define-configuration browser
((theme theme::+dark-theme+)))))))
(:div
Expand All @@ -161,6 +173,9 @@ to the next."
:class "column left"
(:nradio
:name "darken"
:checked (if (find 'nyxt/mode/style:dark-mode (default-modes (current-buffer)))
'dark
'auto)
:vertical t
:buffer buffer
'(auto "Default Web"
Expand All @@ -186,7 +201,7 @@ to the next."
:class "column left"
(:nselect
:id "default-zoom-ratio"
:default "100%"
:default (format nil "~a%" (* 100 (zoom-ratio-default (current-buffer))))
(loop for number in '(30 50 67 80 90 100
110 120 133 150 170
200 240 300 400 500)
Expand Down Expand Up @@ -218,6 +233,7 @@ to the next."
'global-history-source
:enable-marks-p nil
:actions-on-return #'identity))
:input (render-url (default-new-buffer-url *browser*))
:postprocess (lambda (url-or-history-entry)
(render-url (url url-or-history-entry))))))
(:div
Expand All @@ -232,6 +248,7 @@ to the next."
:class "column left"
(:ncheckbox
:name "restore-session"
:checked (restore-session-on-startup-p *browser*)
:buffer buffer
'((restore-session-on-startup-p "Restore session on startup")
(nyxt::auto-configure
Expand Down
26 changes: 14 additions & 12 deletions source/spinneret-tags.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ Example:
(list :buffer buffer)))
,onchange))))

(serapeum:-> %nradio-inputs (string (nyxt:maybe nyxt:buffer) boolean (nyxt:list-of list)) t)
(defun %nradio-inputs (name buffer vertical clauses)
(serapeum:-> %nradio-inputs (string (nyxt:maybe nyxt:buffer) symbol boolean (nyxt:list-of list)) t)
(defun %nradio-inputs (name buffer checked vertical clauses)
(spinneret:with-html-string
(loop for (id label body) in (mapcar #'uiop:ensure-list clauses)
collect (:label
Expand All @@ -148,10 +148,11 @@ Example:
:type "radio"
:id (nyxt:prini-to-string id)
:onchange (%nradio-onchange body buffer)
:name name)
:name name
:checked (equal id checked))
label (when vertical (:br))))))

(deftag :nradio (body attrs &rest keys &key (name (alexandria:required-argument 'name)) vertical buffer &allow-other-keys)
(deftag :nradio (body attrs &rest keys &key (name (alexandria:required-argument 'name)) checked vertical buffer &allow-other-keys)
"Generate radio buttons corresponding to clauses in BODY.
Clauses should be of the form (ID LABEL . FORM), where FORM is evaluated
when a radio button is selected."
Expand All @@ -164,7 +165,7 @@ when a radio button is selected."
`(list ,@body))))
(:div
:class "radio-div"
(:raw (%nradio-inputs ,name ,buffer ,vertical ,body-var)))))))
(:raw (%nradio-inputs ,name ,buffer ,checked ,vertical ,body-var)))))))

(serapeum:-> %ncheckbox-onchange (list list (nyxt:maybe nyxt:buffer)) t)
(defun %ncheckbox-onchange (checked-body unchecked-body buffer)
Expand All @@ -183,23 +184,24 @@ when a radio button is selected."
(list :buffer buffer)))
,unchecked-body)))))

(serapeum:-> %ncheckbox-inputs (string (nyxt:maybe nyxt:buffer) list) t)
(defun %ncheckbox-inputs (name buffer body)
(destructuring-bind ((id label) checked unchecked)
(serapeum:-> %ncheckbox-inputs (string (nyxt:maybe nyxt:buffer) boolean list) t)
(defun %ncheckbox-inputs (name buffer checked body)
(destructuring-bind ((id label) checked-body unchecked-body)
(mapcar #'uiop:ensure-list body)
(spinneret:with-html-string
(:input
:class "checkbox-input"
:type "checkbox"
:id (nyxt:prini-to-string id)
:onchange (%ncheckbox-onchange checked unchecked buffer)
:name name)
:onchange (%ncheckbox-onchange checked-body unchecked-body buffer)
:name name
:checked checked)
(:label
:class "checkbox-label"
:for name
label))))

(deftag :ncheckbox (body attrs &rest keys &key (name (alexandria:required-argument 'name)) buffer &allow-other-keys)
(deftag :ncheckbox (body attrs &rest keys &key (name (alexandria:required-argument 'name)) checked buffer &allow-other-keys)
"Generate a checkbox corresponding to BODY.
BODY should be of the form (ID LABEL FORM-CHECKED . FORM-UNCHECKED), where FORM-CHECKED is evaluated
when the checkbox is checked and FORM-UNCHECKED when it is unchecked."
Expand All @@ -212,7 +214,7 @@ when the checkbox is checked and FORM-UNCHECKED when it is unchecked."
`(list ,@body))))
(:div
:class "checkbox-div"
(:raw (%ncheckbox-inputs ,name ,buffer ,body-var)))))))
(:raw (%ncheckbox-inputs ,name ,buffer ,checked ,body-var)))))))

(defun %nxref-doc (type symbol &optional (class-name (when (eq type :slot)
(alexandria:required-argument 'class-name))))
Expand Down

0 comments on commit 789192d

Please sign in to comment.