welcome.scm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 (display-logo?)
  38. (> (screen-rows) 35))
  39. (define* (run-menu-page title info-text logo
  40. #:key
  41. listbox-items
  42. listbox-item->text)
  43. "Run a page with the given TITLE, to ask the user to choose between
  44. LISTBOX-ITEMS displayed in a listbox. The listbox items are converted to text
  45. using LISTBOX-ITEM->TEXT procedure. Display the textual LOGO in the center of
  46. the page. Contrary to other pages, we cannot resort to grid layouts, because
  47. we want this page to occupy all the screen space available."
  48. (define (fill-listbox listbox items)
  49. (map (lambda (item)
  50. (let* ((text (listbox-item->text item))
  51. (key (append-entry-to-listbox listbox text)))
  52. (cons key item)))
  53. items))
  54. (let* ((logo-textbox
  55. (make-textbox -1 -1
  56. (if (display-logo?) (logo-width) 0)
  57. (if (display-logo?) (logo-height) 0)
  58. 0))
  59. (info-textbox
  60. (make-reflowed-textbox -1 -1
  61. info-text
  62. (info-textbox-width)))
  63. (options-listbox
  64. (make-listbox -1 -1
  65. (options-listbox-height)
  66. (logior FLAG-BORDER FLAG-RETURNEXIT)))
  67. (keys (fill-listbox options-listbox listbox-items))
  68. (grid (vertically-stacked-grid
  69. GRID-ELEMENT-COMPONENT logo-textbox
  70. GRID-ELEMENT-COMPONENT info-textbox
  71. GRID-ELEMENT-COMPONENT options-listbox))
  72. (form (make-form)))
  73. (define (choice->item str)
  74. ;; Return the item that corresponds to STR.
  75. (match (find (match-lambda
  76. ((key . item)
  77. (string=? str (listbox-item->text item))))
  78. keys)
  79. ((key . item) item)
  80. (#f (raise (condition (&installer-step-abort))))))
  81. (set-textbox-text logo-textbox (read-all logo))
  82. (add-form-to-grid grid form #t)
  83. (make-wrapped-grid-window grid title)
  84. (receive (exit-reason argument)
  85. (run-form-with-clients form
  86. `(menu (title ,title)
  87. (text ,info-text)
  88. (items
  89. ,(map listbox-item->text
  90. listbox-items))))
  91. (dynamic-wind
  92. (const #t)
  93. (lambda ()
  94. (match exit-reason
  95. ('exit-component
  96. (let* ((entry (current-listbox-entry options-listbox))
  97. (item (assoc-ref keys entry)))
  98. (match item
  99. ((text . proc)
  100. (proc)))))
  101. ('exit-fd-ready
  102. (let* ((choice argument)
  103. (item (choice->item choice)))
  104. (match item
  105. ((text . proc)
  106. (proc)))))))
  107. (lambda ()
  108. (destroy-form-and-pop form))))))
  109. (define (run-welcome-page logo)
  110. "Run a welcome page with the given textual LOGO displayed at the center of
  111. the page. Ask the user to choose between manual installation, graphical
  112. installation and reboot."
  113. (run-menu-page
  114. (G_ "GNU Guix install")
  115. (G_ "Welcome to GNU Guix system installer!
  116. You will be guided through a graphical installation program.
  117. If you are familiar with GNU/Linux and you want tight control over \
  118. the installation process, you can instead choose manual installation. \
  119. Documentation is accessible at any time by pressing Ctrl-Alt-F2.")
  120. logo
  121. #:listbox-items
  122. `((,(G_ "Graphical install using a terminal based interface")
  123. .
  124. ,(const #t))
  125. (,(G_ "Install using the shell based process")
  126. .
  127. ,(lambda ()
  128. ;; Switch to TTY3, where a root shell is available for shell based
  129. ;; install. The other root TTY's would have been ok too.
  130. (system* "chvt" "3")
  131. (run-welcome-page logo)))
  132. (,(G_ "Reboot")
  133. .
  134. ,(lambda ()
  135. (newt-finish)
  136. (reboot))))
  137. #:listbox-item->text car))