Skip to content

Commit

Permalink
add window prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 7, 2024
1 parent f682bb8 commit 1e9d443
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "plinth"
version = "0.4.14"
version = "0.4.15"
description = "Bindings to Node.js and browser platform APIs"
target = "javascript"

Expand Down
3 changes: 3 additions & 0 deletions src/plinth/browser/window.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub fn self() -> Window
@external(javascript, "../../window_ffi.mjs", "alert")
pub fn alert(a: String) -> Nil

@external(javascript, "../../window_ffi.mjs", "prompt")
pub fn prompt(a: String) -> Result(String, Nil)

@external(javascript, "../../window_ffi.mjs", "addEventListener")
pub fn add_event_listener(type_: String, listener: fn(Event) -> Nil) -> Nil

Expand Down
9 changes: 9 additions & 0 deletions src/window_ffi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ export function alert(message) {
window.alert(message);
}

export function prompt(message, defaultValue) {
let text = window.prompt(message, defaultValue);
if (text !== null) {
return new Ok(text)
} else {
return new Error()
}
}

export function addEventListener(type, listener) {
return window.addEventListener(type, listener);
}
Expand Down

0 comments on commit 1e9d443

Please sign in to comment.