Skip to content

Commit

Permalink
remove Debug.todos #12
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Oct 17, 2024
1 parent 726be33 commit 6e9b4b6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ const io = {
fs.close(fd);
this.send({ index, value: null });
},
hFileSize: function (index, fd) {
const stats = fs.fstatSync(fd);
this.send({ index, value: stats.size });
},
withFile: function (index, filename, mode) {
var fd = fs.openSync(filename, mode);
this.send({ index, value: fd });
},
};

const app = Elm.Terminal.Main.init();
Expand Down
10 changes: 6 additions & 4 deletions src/Data/IO.elm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ type Effect
| ReplGetInputLine String
| ReplGetInputLineWithInitial String ( String, String )
| HClose Handle
| HFileSize Handle
| WithFile String IOMode
| StateGet
| ProcWithCreateProcess CreateProcess
| NoOp
Expand Down Expand Up @@ -545,7 +547,7 @@ hFlush handle =

hFileSize : Handle -> IO Int
hFileSize handle =
todo "hFileSize"
make Decode.int (HFileSize handle)


hClose : Handle -> IO ()
Expand Down Expand Up @@ -643,6 +645,6 @@ hSetEncoding _ _ =


withFile : String -> IOMode -> (Handle -> IO a) -> IO a
withFile _ _ callback =
-- TODO review this
callback stdout
withFile path mode callback =
make (Decode.map Handle Decode.int) (WithFile path mode)
|> bind callback
36 changes: 36 additions & 0 deletions src/Terminal/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,42 @@ effectToCmd index portOut effect =
]
}

IO.HFileSize (IO.Handle fd) ->
portOut
{ index = index
, value =
Encode.object
[ ( "fn", Encode.string "hFileSize" )
, ( "args", Encode.list Encode.int [ fd ] )
]
}

IO.WithFile filename mode ->
portOut
{ index = index
, value =
Encode.object
[ ( "fn", Encode.string "withFile" )
, ( "args"
, Encode.list Encode.string
[ filename
, case mode of
IO.ReadMode ->
"r"

IO.WriteMode ->
"w"

IO.AppendMode ->
"a"

IO.ReadWriteMode ->
"w+"
]
)
]
}

IO.DirFindExecutable name ->
portOut
{ index = index
Expand Down

0 comments on commit 6e9b4b6

Please sign in to comment.