The core Effects for Tui.Programs.
Most notably, your TUI can resolve a BackendTask
within its init and update and get back the result
as a Msg.
update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
PressedStage file ->
( { model | staging = Just file }
, Script.exec "git" [ "add", file ]
|> Effect.perform (\() -> StagingComplete file)
)
StagingComplete file ->
( { model | staging = Nothing }
, Effect.none
)BackendTasksRun a BackendTask and get the resolved data back in a Msg. If the
BackendTask fails, the FatalError propogates and the TUI exits and prints
the FatalError's message.
Script.command "git" [ "status", "--porcelain" ]
|> BackendTask.map parseFiles
|> Effect.perform GotFilesLike perform, but surfaces errors as Result values for you to handle BackendTask errors gracefully.
Script.command "git" [ "diff", file ]
|> BackendTask.mapError (\_ -> "git diff failed")
|> Effect.attempt
(\result ->
case result of
Ok text ->
GotDiff text
Err reason ->
DiffFailed reason
)Useful in combination with BackendTask.mapError.
No effect.
Combine multiple effects sequentially.
Transform the message type of an effect.
Exit the TUI (exit code 0). Terminal state is restored.
Exit the TUI with a specific exit code. Terminal state is restored.
An
Effectcan be passed toupdateorinit. Like theCmdpart of a standard Elm TEA application.