@@ -3,14 +3,15 @@ module Main exposing (main)
3
3
import Node
4
4
import Bytes exposing (Bytes)
5
5
import Stream exposing (Stream)
6
- import Node.Program as Program exposing (Program)
6
+ import Node exposing (Program, Environment )
7
7
import FileSystem
8
+ import Init
8
9
import Task
9
10
10
11
11
12
main : Program Model Msg
12
13
main =
13
- Program.define
14
+ Node.defineProgram
14
15
{ init = init
15
16
, update = update
16
17
, subscriptions = \_ -> Sub.none
@@ -27,27 +28,24 @@ type Msg
27
28
= OpenResult (Result FileSystem.AccessError (FileSystem.ReadableFileHandle Never))
28
29
| ReadResult (Result FileSystem.UnknownFileSystemError Bytes)
29
30
30
-
31
- init : Program.AppInitTask { model : Model, command : Cmd Msg }
32
- init =
33
- Program.await Node.initialize <| \nodeConfig ->
34
- Program.await FileSystem.initialize <| \fsPermission ->
35
- Program.startProgram
36
- { model =
37
- { stdout = nodeConfig.stdout
38
- , stderr = nodeConfig.stderr
39
- }
40
- , command =
41
- case nodeConfig.args of
42
- [ _, _, file ] ->
43
- FileSystem.openForRead fsPermission file
44
- |> Task.attempt OpenResult
45
-
46
- _ ->
47
- Stream.sendLine nodeConfig.stderr <|
48
- "Exactly one argument is required: the file name to read"
31
+ init : Environment -> Init.Task { model : Model, command : Cmd Msg }
32
+ init env =
33
+ Init.await FileSystem.initialize <| \fsPermission ->
34
+ Node.startProgram
35
+ { model =
36
+ { stdout = env.stdout
37
+ , stderr = env.stderr
49
38
}
50
-
39
+ , command =
40
+ case env.args of
41
+ [ _, _, file ] ->
42
+ FileSystem.openForRead fsPermission file
43
+ |> Task.attempt OpenResult
44
+
45
+ _ ->
46
+ Stream.sendLine env.stderr <|
47
+ "Exactly one argument is required: the file name to read"
48
+ }
51
49
52
50
update : Msg -> Model -> { model : Model, command : Cmd Msg }
53
51
update msg model =
0 commit comments