-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
196 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { useApp } from "ink"; | ||
|
||
export const exit = (app) => app.exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const enableFocus = (manager) => manager.enableFocus() | ||
|
||
export const disableFocus = (manager) => manager.disableFocus() | ||
|
||
export const focusNext = (manager) => manager.focusNext() | ||
|
||
export const focusPrevious = (manager) => manager.focusPrevious() | ||
|
||
export const focus = (manager, id) => manager.focus(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub type App | ||
|
||
/// Get the current app instance | ||
@external(javascript, "../app_ffi.mjs", "useApp") | ||
pub fn get() -> App | ||
|
||
/// Exit the app (unmount) | ||
@external(javascript, "../app_ffi.mjs", "exit") | ||
pub fn exit(app: App) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pub type FocusManager | ||
|
||
/// Get the Focus Manager that is able to enable or disable focus management for all components or manually switch focus to next or previous components. | ||
@external(javascript, "../ink_ffi.mjs", "useFocusManager") | ||
pub fn get() -> FocusManager | ||
|
||
/// Enable focus management for all components | ||
/// | ||
/// Note: You don't need to call this method manually, unless you've disabled focus management. Focus management is enabled by default | ||
@external(javascript, "../focus_manager_ffi.mjs", "enableFocus") | ||
pub fn enable_focus(manager: FocusManager) -> Nil | ||
|
||
/// Disable focus management for all components. Currently active component (if there's one) will lose its focus. | ||
@external(javascript, "../focus_manager_ffi.mjs", "disableFocus") | ||
pub fn disable_focus(manager: FocusManager) -> Nil | ||
|
||
/// Switch focus to the next focusable component. | ||
/// | ||
/// If there's no active component right now, focus will be given to the first focusable component. If active component is the last in the list of focusable components, focus will be switched to the first active component. | ||
/// | ||
/// Note: Ink calls this method when user presses Tab. | ||
@external(javascript, "../focus_manager_ffi.mjs", "focusNext") | ||
pub fn focus_next(manager: FocusManager) -> Nil | ||
|
||
/// Switch focus to the previous focusable component. | ||
/// | ||
/// If there's no active component right now, focus will be given to the last focusable component. If active component is the first in the list of focusable components, focus will be switched to the last active component. | ||
/// | ||
/// Note: Ink calls this method when user presses Shift+Tab. | ||
@external(javascript, "../focus_manager_ffi.mjs", "focusPrevious") | ||
pub fn focus_previous(manager: FocusManager) -> Nil | ||
|
||
/// Switch focus to the component with the specified id. If there's no component with that ID, focus will be given to the next focusable component. | ||
@external(javascript, "../focus_manager_ffi.mjs", "focus") | ||
pub fn focus(manager: FocusManager, id: String) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// A reference to a state value in a React component. | ||
pub type State(a) | ||
|
||
/// Initialize a stateful value. | ||
/// | ||
/// This is a React hook. | ||
/// Read more about it on [react.dev docs](https://react.dev/reference/react/useState) | ||
/// | ||
/// Note: This hook is here for convenience, so you don't have to create the bindings yourself | ||
@external(javascript, "../react_ffi.mjs", "useState") | ||
pub fn init(value value: a) -> State(a) | ||
|
||
/// Get the current value of a state. | ||
@external(javascript, "../react_ffi.mjs", "getState") | ||
pub fn get(state: State(a)) -> a | ||
|
||
/// Set the value of a state. | ||
@external(javascript, "../react_ffi.mjs", "setState") | ||
pub fn set(on state: State(a), value value: a) -> Nil | ||
|
||
/// Update the value of a state using a function. | ||
@external(javascript, "../react_ffi.mjs", "setState") | ||
pub fn set_with(on state: State(a), with setter: fn(a) -> a) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import gleam/dynamic.{type Dynamic} | ||
|
||
pub type Stderr | ||
|
||
/// Get the stderr stream. | ||
@external(javascript, "../stderr_ffi.mjs", "useStderr") | ||
pub fn get() -> Stderr | ||
|
||
/// process.stderr | ||
@external(javascript, "../stderr_ffi.mjs", "stderr_") | ||
pub fn stderr(stderr: Stderr) -> Dynamic | ||
|
||
/// Write any string to stderr, while preserving Ink's output. | ||
/// | ||
/// It's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two. It's similar to `static`, except it can't accept components, it only works with strings | ||
@external(javascript, "../stderr_ffi.mjs", "write") | ||
pub fn write(on stderr: Stderr, chunk chunk: String) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gleam/dynamic.{type Dynamic} | ||
|
||
pub type Stdin | ||
|
||
/// Get the stdin stream | ||
@external(javascript, "../stdin_ffi.mjs", "useStdin") | ||
pub fn get() -> Stdin | ||
|
||
/// Get the process.stdin. Useful if your app needs to handle user input | ||
@external(javascript, "../stdin_ffi.mjs", "stdin_") | ||
pub fn stdin(stdin: Stdin) -> Dynamic | ||
|
||
/// A boolean flag determining if the current stdin supports `set_raw_mode`. | ||
/// | ||
/// A component using `set_raw_mode` might want to use `is_raw_mode_supported` to nicely fall back in environments where raw mode is not supported | ||
@external(javascript, "../stdin_ffi.mjs", "isRawModeSupported") | ||
pub fn is_raw_mode_supported(stdin: Stdin) -> Bool | ||
|
||
/// See [setRawMode](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode). | ||
/// | ||
/// Ink exposes this function to be able to handle Ctrl+C, that's why you should use Ink's `set_raw_mode` instead of `process.stdin.setRawMode` | ||
@external(javascript, "../stdin_ffi.mjs", "setRawMode") | ||
pub fn set_raw_mode(stdin: Stdin, raw_mode: Bool) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import gleam/dynamic.{type Dynamic} | ||
|
||
pub type Stdout | ||
|
||
/// Get the stdout stream, where Ink renders your app. | ||
@external(javascript, "../stdout_ffi.mjs", "useStdout") | ||
pub fn get() -> Stdout | ||
|
||
/// process.stdout | ||
@external(javascript, "../stdout_ffi.mjs", "stdout_") | ||
pub fn stdout(stdout: Stdout) -> Dynamic | ||
|
||
/// Write any string to stdout, while preserving Ink's output. | ||
/// | ||
/// It's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two. It's similar to `static`, except it can't accept components, it only works with strings | ||
@external(javascript, "../stdout_ffi.mjs", "write") | ||
pub fn write(on stdout: Stdout, chunk chunk: String) -> Nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { useStderr } from "ink"; | ||
|
||
export const stderr_ = (stderr) => stderr.stderr | ||
|
||
export const write = (stderr, chunk) => stderr.write(chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { useStdin } from "ink"; | ||
|
||
export const stdin_ = (stdin) => stdin.stdin | ||
|
||
export const isRawModeSupported = (stdin) => stdin.isRawModeSupported | ||
|
||
export const setRawMode = (stdin, value) => stdin.setRawMode(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { useStdout } from "ink"; | ||
|
||
export const stdout_ = (stdout) => stdout.stdout | ||
|
||
export const write = (stdout, chunk) => stdout.write(chunk) |
Oops, something went wrong.