welcome.scm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu installer newt welcome)
  19. #:use-module (gnu installer steps)
  20. #:use-module (gnu installer utils)
  21. #:use-module (gnu installer newt page)
  22. #:use-module (gnu installer newt utils)
  23. #:use-module (guix build syscalls)
  24. #:use-module (guix i18n)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-34)
  27. #:use-module (srfi srfi-35)
  28. #:use-module (ice-9 match)
  29. #:use-module (ice-9 receive)
  30. #:use-module (newt)
  31. #:export (run-welcome-page))
  32. ;; Expected width and height for the logo.
  33. (define logo-width (make-parameter 43))
  34. (define logo-height (make-parameter 19))
  35. (define info-textbox-width (make-parameter 70))
  36. (define options-listbox-height (make-parameter 5))
  37. (define* (run-menu-page title info-text logo
  38. #:key
  39. listbox-items
  40. listbox-item->text)
  41. "Run a page with the given TITLE, to ask the user to choose between
  42. LISTBOX-ITEMS displayed in a listbox. The listbox items are converted to text
  43. using LISTBOX-ITEM->TEXT procedure. Display the textual LOGO in the center of
  44. the page. Contrary to other pages, we cannot resort to grid layouts, because
  45. we want this page to occupy all the screen space available."
  46. (define (fill-listbox listbox items)
  47. (map (lambda (item)
  48. (let* ((text (listbox-item->text item))
  49. (key (append-entry-to-listbox listbox text)))
  50. (cons key item)))
  51. items))
  52. (let* ((logo-textbox
  53. (make-textbox -1 -1 (logo-width) (logo-height) 0))
  54. (info-textbox
  55. (make-reflowed-textbox -1 -1
  56. info-text
  57. (info-textbox-width)))
  58. (options-listbox
  59. (make-listbox -1 -1
  60. (options-listbox-height)
  61. (logior FLAG-BORDER FLAG-RETURNEXIT)))
  62. (keys (fill-listbox options-listbox listbox-items))
  63. (grid (vertically-stacked-grid
  64. GRID-ELEMENT-COMPONENT logo-textbox
  65. GRID-ELEMENT-COMPONENT info-textbox
  66. GRID-ELEMENT-COMPONENT options-listbox))
  67. (form (make-form)))
  68. (define (choice->item str)
  69. ;; Return the item that corresponds to STR.
  70. (match (find (match-lambda
  71. ((key . item)
  72. (string=? str (listbox-item->text item))))
  73. keys)
  74. ((key . item) item)
  75. (#f (raise (condition (&installer-step-abort))))))
  76. (set-textbox-text logo-textbox (read-all logo))
  77. (add-form-to-grid grid form #t)
  78. (make-wrapped-grid-window grid title)
  79. (receive (exit-reason argument)
  80. (run-form-with-clients form
  81. `(menu (title ,title)
  82. (text ,info-text)
  83. (items
  84. ,(map listbox-item->text
  85. listbox-items))))
  86. (dynamic-wind
  87. (const #t)
  88. (lambda ()
  89. (match exit-reason
  90. ('exit-component
  91. (let* ((entry (current-listbox-entry options-listbox))
  92. (item (assoc-ref keys entry)))
  93. (match item
  94. ((text . proc)
  95. (proc)))))
  96. ('exit-fd-ready
  97. (let* ((choice argument)
  98. (item (choice->item choice)))
  99. (match item
  100. ((text . proc)
  101. (proc)))))))
  102. (lambda ()
  103. (destroy-form-and-pop form))))))
  104. (define (run-welcome-page logo)
  105. "Run a welcome page with the given textual LOGO displayed at the center of
  106. the page. Ask the user to choose between manual installation, graphical
  107. installation and reboot."
  108. (run-menu-page
  109. (G_ "GNU Guix install")
  110. (G_ "Welcome to GNU Guix system installer!
  111. You will be guided through a graphical installation program.
  112. If you are familiar with GNU/Linux and you want tight control over \
  113. the installation process, you can instead choose manual installation. \
  114. Documentation is accessible at any time by pressing Ctrl-Alt-F2.")
  115. logo
  116. #:listbox-items
  117. `((,(G_ "Graphical install using a terminal based interface")
  118. .
  119. ,(const #t))
  120. (,(G_ "Install using the shell based process")
  121. .
  122. ,(lambda ()
  123. ;; Switch to TTY3, where a root shell is available for shell based
  124. ;; install. The other root TTY's would have been ok too.
  125. (system* "chvt" "3")
  126. (run-welcome-page logo)))
  127. (,(G_ "Reboot")
  128. .
  129. ,(lambda ()
  130. (newt-finish)
  131. (reboot))))
  132. #:listbox-item->text car))