welcome.scm 4.3 KB

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