anchor.diff:  ;;;; SPDX-License-Identifier: BSD-3-Clause
   
   (uiop:define-package :nyxt/os-package-manager-mode
  -  (:use :common-lisp :trivia :nyxt)
  +    (:use :common-lisp :trivia :nyxt)
     (:import-from #:keymap #:define-key #:define-scheme)
     (:documentation "Universal interface to various operating system package managers."))
   (in-package :nyxt/os-package-manager-mode)
  
positive.code:   "Install select packages."
    (assert-package-manager)
    ;; TODO: Allow profile creation.  Need multi-source support for that?
    (let* ((profile (prompt-minibuffer
                     :suggestion-function (os-profile-suggestion-filter)
                     :input-prompt "Target profile"))
           (packages (prompt-minibuffer
                      :suggestion-function (os-package-output-suggestion-filter)
                      :input-prompt "Install OS package(s)"
                      :multi-selection-p t)))
      (operate-os-package "Installing packages..." #'ospm:install profile packages)))
  
  (define-command uninstall-os-package ()
    "Uninstall select packages."
    (assert-package-manager)
    (let* ((profile (prompt-minibuffer
                     :suggestion-function (os-profile-suggestion-filter)
                     :input-prompt "Target profile"))
           (packages (prompt-minibuffer
                      :suggestion-function (os-installed-package-suggestion-filter profile)
                      :input-prompt "Uninstall OS package(s)"
                      :multi-selection-p t)))
      (operate-os-package "Uninstalling packages..." #'ospm:uninstall profile packages)))
  
  (define-command install-package-manifest ()
    "Install select manifest to a profile."
    (assert-package-manager)
    (let* ((profile (prompt-minibuffer
                     :suggestion-function (os-profile-suggestion-filter)
                     :input-prompt "Target profile"))
           (manifest (prompt-minibuffer
                      :suggestion-function (os-manifest-suggestion-filter)
                      :input-prompt "Manifest")))
      (operate-os-package "Installing package manifest..." #'ospm:install-manifest profile manifest)))
  
  (define-command edit-package-manifest ()
    "Edit select manifest."
    (assert-package-manager)
    (let ((manifest (prompt-minibuffer
                     :suggestion-function (os-manifest-suggestion-filter)
                     :input-prompt "Manifest")))
      (echo "Opening ~s with ~a" manifest (external-editor-program *browser*))
      (uiop:launch-program (list (external-editor-program *browser*) manifest))))
  
  (define-command describe-os-generation ()
    "Show the packages of a given profile generation."
    (assert-package-manager)
    (let* ((profile (prompt-minibuffer
                     :suggestion-function (os-profile-suggestion-filter
                                           :include-manager-p t)
                     :input-prompt "Profile"))
           (generation (prompt-minibuffer
                        :suggestion-function (os-generation-suggestion-filter profile)
                        :input-prompt "Generation"))
           (buffer (or (find-buffer 'os-package-manager-mode)
                       (nyxt/os-package-manager-mode:os-package-manager-mode
                        :activate t
  
negative.code:         (echo "An package operation is already running.  You can cancel it with `cancel-package-operation'.")
          (progn
            (pexec ()
                   (let ((process-info (funcall command objects profile))
                         (mode (find-submode buffer 'os-package-manager-mode)))
                     (setf (nyxt/os-package-manager-mode:current-process-info mode) process-info)
                     (html-set "" buffer)      ; Reset content between operations.
                     (html-write
                      (markup:markup
                       (:style (style buffer))
                       (:h1 title)
                       (:p
                        (:a :class "button"
                            :href (lisp-url '(nyxt/os-package-manager-mode:cancel-package-operation))
                            "Cancel")))
                      buffer)
                     (format-command-stream
                      process-info
                      (lambda (s)
                        ;; TODO: Make shell formating function and add support for
                        ;; special characters, e.g. progress bars.
                        (html-write
                         (markup:markup
                          (:code (str:replace-all " " " " s))
                          (:br))
                         buffer)))
                     (html-write
                      (markup:markup (:p "Done."))
                      buffer)))
            (set-current-buffer buffer)
            buffer))))
  
  