Skip to content

Commit

Permalink
trilby-cli: update terminal-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ners committed Feb 21, 2024
1 parent cccc1d1 commit 8808276
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions trilby-cli/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions trilby-cli/src/Internal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Internal.Prelude
, parseChoiceWith
, parseChoice
, parseEnum
, runWidget
, askText
, askPassword
, askYesNo
Expand Down Expand Up @@ -200,12 +201,14 @@ askChoice prompt values defaultValue = do
runWidget
Select
{ prompt
, options = [(ishow v, False) | v <- values]
, multiselect = False
, options = [SelectOption{value, checked = False} | value <- values]
, optionText = ishow
, minSelect = 1
, maxSelect = 1
, cursorRow = defaultValue + 1
}
fromMaybeM (askChoice prompt values defaultValue) $ pure do
i <- List.findIndex snd select.options
i <- List.findIndex (.checked) select.options
values !? i

askEnum :: (Eq a, Bounded a, Enum a, Show a) => Text -> a -> App a
Expand Down
16 changes: 8 additions & 8 deletions trilby-cli/src/Trilby/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ install (askOpts -> opts) | Just FlakeOpts{..} <- opts.flake = do
let rootIsMounted = (ExitSuccess ==) . fst <$> cmd' ["mountpoint", "-q", fromString rootMount]
unlessM rootIsMounted do
$(logWarn) "Partitions are not mounted"
unlessM (askYesNo "Attempt to mount the partitions?" True) $
errorExit "Cannot install without mounted partitions"
unlessM (askYesNo "Attempt to mount the partitions?" True)
$ errorExit "Cannot install without mounted partitions"
runDisko $ Mount $ Disko.Flake flakeRef
nixosInstall flakeRef
whenM copyFlake do
Expand All @@ -88,8 +88,8 @@ install (askOpts -> opts) = do
let rootIsMounted = (ExitSuccess ==) . fst <$> cmd' ["mountpoint", "-q", fromString rootMount]
unlessM rootIsMounted do
$(logWarn) "Partitions are not mounted"
unlessM (askYesNo "Attempt to mount the partitions?" True) $
errorExit "Cannot install without mounted partitions"
unlessM (askYesNo "Attempt to mount the partitions?" True)
$ errorExit "Cannot install without mounted partitions"
runDisko $ Mount $ Disko.File diskoFile
inDir trilbyDir do
asRoot cmd_ ["chown", "-R", "1000:1000", fromString trilbyDir]
Expand Down Expand Up @@ -134,8 +134,8 @@ install (askOpts -> opts) = do
, fromString rootMount
]
writeNixFile "disko.nix" $ clearLuksFiles disko
cmd_ $
sconcat
cmd_
$ sconcat
[ ["nix", "flake", "lock"]
, ["--accept-flake-config"]
, ["--override-input", "trilby", "trilby"]
Expand All @@ -147,8 +147,8 @@ nixosInstall :: Text -> App ()
nixosInstall flakeRef = do
$(logWarn) "Performing installation ... "
-- TODO(vkleen): this shouldn't work and neither should it be necessary ...
(withTrace . asRoot) rawCmd_ $
sconcat
(withTrace . asRoot) rawCmd_
$ sconcat
[ ["nix", "build"]
, ["--store", "/mnt"]
, ["--impure"]
Expand Down
29 changes: 23 additions & 6 deletions trilby-cli/src/Trilby/Install/Options.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_GHC -Wno-partial-fields #-}

module Trilby.Install.Options where
Expand All @@ -7,6 +8,7 @@ import Data.Text qualified as Text
import Internal.Prelude hiding (error)
import Options.Applicative
import System.Posix (getFileStatus, isBlockDevice)
import System.Terminal.Widgets.SearchSelect (SearchSelect (..), SearchSelectOption (..))
import Trilby.Config.Channel
import Trilby.Config.Edition
import Trilby.Config.Host (Keyboard (..))
Expand Down Expand Up @@ -137,13 +139,28 @@ askLocale = do
askTimezone :: App Text
askTimezone = do
currentTz <- firstLine <$> shell "timedatectl show --property=Timezone --value" empty
tz <- askText "Choose time zone:" currentTz
allTimezones <- Text.lines <$> shell "timedatectl list-timezones" empty
if tz `elem` allTimezones
then pure tz
else do
$(logError) "Unknown timezone"
askTimezone
ss <-
runWidget
SearchSelect
{ prompt = "Choose time zone: "
, searchValue = ""
, options =
[ SearchSelectOption
{ value
, visible = False
}
| value <- allTimezones
]
, selections = [currentTz]
, optionText = id
, minSelect = 1
, maxSelect = 1
, maxVisible = 5
, minSearchLength = 3
, cursorRow = 0
}
maybe askTimezone pure $ listToMaybe ss.selections

askOpts :: InstallOpts Maybe -> InstallOpts App
askOpts opts = do
Expand Down

0 comments on commit 8808276

Please sign in to comment.