Add Stderr.line to cli-platform

This commit is contained in:
Richard Feldman 2022-09-06 10:47:35 -04:00
parent d0656bf793
commit 762fa75511
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
3 changed files with 12 additions and 6 deletions

View file

@ -3,8 +3,8 @@ hosted Effect
imports [InternalHttp.{ Request, Response }] imports [InternalHttp.{ Request, Response }]
generates Effect with [after, map, always, forever, loop] generates Effect with [after, map, always, forever, loop]
putLine : Str -> Effect {} stdoutLine : Str -> Effect {}
stderrLine : Str -> Effect {}
getLine : Effect Str stdinLine : Effect Str
sendRequest : Box Request -> Effect Response sendRequest : Box Request -> Effect Response

View file

@ -4,5 +4,5 @@ interface Stdout
line : Str -> Task {} * [Write [Stdout]*]* line : Str -> Task {} * [Write [Stdout]*]*
line = \str -> line = \str ->
Effect.map (Effect.putLine str) (\_ -> Ok {}) Effect.map (Effect.stdoutLine str) (\_ -> Ok {})
|> InternalTask.fromEffect |> InternalTask.fromEffect

View file

@ -113,7 +113,7 @@ unsafe fn call_the_closure(closure_data_ptr: *const u8) -> i64 {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn roc_fx_getLine() -> RocStr { pub extern "C" fn roc_fx_stdinLine() -> RocStr {
use std::io::{self, BufRead}; use std::io::{self, BufRead};
let stdin = io::stdin(); let stdin = io::stdin();
@ -123,11 +123,17 @@ pub extern "C" fn roc_fx_getLine() -> RocStr {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn roc_fx_putLine(line: &RocStr) { pub extern "C" fn roc_fx_stdoutLine(line: &RocStr) {
let string = line.as_str(); let string = line.as_str();
println!("{}", string); println!("{}", string);
} }
#[no_mangle]
pub extern "C" fn roc_fx_stderrLine(line: &RocStr) {
let string = line.as_str();
eprintln!("{}", string);
}
#[no_mangle] #[no_mangle]
pub extern "C" fn roc_fx_sendRequest(roc_request: &glue::Request) -> glue::Response { pub extern "C" fn roc_fx_sendRequest(roc_request: &glue::Request) -> glue::Response {
let mut builder = reqwest::blocking::ClientBuilder::new(); let mut builder = reqwest::blocking::ClientBuilder::new();