Skip to content

Commit

Permalink
Merge pull request #14 from revathskumar/upgrade-gren-node
Browse files Browse the repository at this point in the history
cat: upgrade gren-lang/node to 3.0.1
  • Loading branch information
robinheghan authored Mar 4, 2024
2 parents 7bb41ed + 28d8a67 commit a600e28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
8 changes: 5 additions & 3 deletions cat/gren.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"gren-version": "0.3.0",
"dependencies": {
"direct": {
"gren-lang/core": "4.0.0",
"gren-lang/node": "2.0.0"
"gren-lang/core": "4.0.1",
"gren-lang/node": "3.0.1"
},
"indirect": {}
"indirect": {
"gren-lang/url": "3.0.0"
}
}
}
42 changes: 20 additions & 22 deletions cat/src/Main.gren
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module Main exposing (main)
import Node
import Bytes exposing (Bytes)
import Stream exposing (Stream)
import Node.Program as Program exposing (Program)
import Node exposing (Program, Environment)
import FileSystem
import Init
import Task


main : Program Model Msg
main =
Program.define
Node.defineProgram
{ init = init
, update = update
, subscriptions = \_ -> Sub.none
Expand All @@ -27,27 +28,24 @@ type Msg
= OpenResult (Result FileSystem.AccessError (FileSystem.ReadableFileHandle Never))
| ReadResult (Result FileSystem.UnknownFileSystemError Bytes)


init : Program.AppInitTask { model : Model, command : Cmd Msg }
init =
Program.await Node.initialize <| \nodeConfig ->
Program.await FileSystem.initialize <| \fsPermission ->
Program.startProgram
{ model =
{ stdout = nodeConfig.stdout
, stderr = nodeConfig.stderr
}
, command =
case nodeConfig.args of
[ _, _, file ] ->
FileSystem.openForRead fsPermission file
|> Task.attempt OpenResult

_ ->
Stream.sendLine nodeConfig.stderr <|
"Exactly one argument is required: the file name to read"
init : Environment -> Init.Task { model : Model, command : Cmd Msg }
init env =
Init.await FileSystem.initialize <| \fsPermission ->
Node.startProgram
{ model =
{ stdout = env.stdout
, stderr = env.stderr
}

, command =
case env.args of
[ _, _, file ] ->
FileSystem.openForRead fsPermission file
|> Task.attempt OpenResult

_ ->
Stream.sendLine env.stderr <|
"Exactly one argument is required: the file name to read"
}

update : Msg -> Model -> { model : Model, command : Cmd Msg }
update msg model =
Expand Down

0 comments on commit a600e28

Please sign in to comment.