Skip to content

Commit 99e895d

Browse files
committed
Add Tty and Locale modules with Rust host implementation
1 parent 03e94ad commit 99e895d

6 files changed

Lines changed: 146 additions & 93 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ crate-type = ["staticlib"]
1313
# Note: we use "=version" for reproducability, cargo may silently use a more recent version if you do not use `=`.
1414
[dependencies]
1515
libc = "=0.2.180" # keep version in sync with libc workspace dep below
16+
sys-locale.workspace = true
17+
crossterm = "0.27"
1618
roc_std_new.workspace = true
1719
roc_io_error.workspace = true
1820
roc_random.workspace = true

platform/Locale.roc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Locale := [].{
2+
## Returns the most preferred locale for the system or application.
3+
##
4+
## The returned [Str] is a BCP 47 language tag, like `en-US` or `fr-CA`.
5+
get! : {} => Str
6+
7+
## Returns the preferred locales for the system or application.
8+
##
9+
## The returned [Str] are BCP 47 language tags, like `en-US` or `fr-CA`.
10+
all! : {} => List(Str)
11+
}

platform/Tty.roc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Provides functionality to change the behaviour of the terminal.
2+
## This is useful for running an app like vim or a game in the terminal.
3+
Tty := [].{
4+
## Enable terminal [raw mode](https://en.wikipedia.org/wiki/Terminal_mode) to disable some default terminal bevahiour.
5+
##
6+
## This leads to the following changes:
7+
## - Input will not be echoed to the terminal screen.
8+
## - Input will be sent straight to the program instead of being buffered (= collected) until the Enter key is pressed.
9+
## - Special keys like Backspace and CTRL+C will not be processed by the terminal driver but will be passed to the program.
10+
enable_raw_mode! : {} => {}
11+
12+
## Revert terminal to default behaviour
13+
disable_raw_mode! : {} => {}
14+
}

platform/main.roc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
platform ""
22
requires {} { main! : List(Str) => Try({}, [Exit(I32), ..]) }
3-
exposes [Cmd, Dir, Env, File, Path, Random, Sleep, Stdin, Stdout, Stderr, Utc]
3+
exposes [Cmd, Dir, Env, File, Locale, Path, Random, Sleep, Stdin, Stdout, Stderr, Tty, Utc]
44
packages {}
55
provides { main_for_host! : "main_for_host" }
66
targets: {
@@ -17,12 +17,14 @@ import Cmd
1717
import Dir
1818
import Env
1919
import File
20+
import Locale
2021
import Path
2122
import Random
2223
import Sleep
2324
import Stdin
2425
import Stdout
2526
import Stderr
27+
import Tty
2628
import Utc
2729

2830
main_for_host! : List(Str) => I32

0 commit comments

Comments
 (0)