1///|
2type Tty
3
4///|
5pub impl 
trait ToHandle {
  to_handle(Self) -> Handle
  of_handle(Handle) -> Self
  close(Self, (Self) -> Unit) -> Unit
  is_closing(Self) -> Bool
}
ToHandle
for
type Tty
Tty
with to_handle(tty :
type Tty
Tty
) ->
type Handle
Handle
= "%identity"
6 7///| 8pub impl
trait ToHandle {
  to_handle(Self) -> Handle
  of_handle(Handle) -> Self
  close(Self, (Self) -> Unit) -> Unit
  is_closing(Self) -> Bool
}
ToHandle
for
type Tty
Tty
with of_handle(handle :
type Handle
Handle
) ->
type Tty
Tty
= "%identity"
9 10///| 11pub impl
trait ToStream {
  to_stream(Self) -> Stream
  of_stream(Stream) -> Self
  read_start(Self, (Self, Int) -> @bytes.View, (Self, Int, @bytes.View) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
  read_stop(Self) -> Unit!Errno
  write(Self, Array[@bytes.View], (Write) -> Unit, (Write, Errno) -> Unit) -> Unit!Errno
  listen(Self, Int, (Self) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
  is_readable(Self) -> Bool
  is_writable(Self) -> Bool
  shutdown(Self, (Shutdown) -> Unit, (Shutdown, Errno) -> Unit) -> Unit!Errno
}
ToStream
for
type Tty
Tty
with to_stream(tty :
type Tty
Tty
) ->
type Stream
Stream
= "%identity"
12 13///| 14pub impl
trait ToStream {
  to_stream(Self) -> Stream
  of_stream(Stream) -> Self
  read_start(Self, (Self, Int) -> @bytes.View, (Self, Int, @bytes.View) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
  read_stop(Self) -> Unit!Errno
  write(Self, Array[@bytes.View], (Write) -> Unit, (Write, Errno) -> Unit) -> Unit!Errno
  listen(Self, Int, (Self) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
  is_readable(Self) -> Bool
  is_writable(Self) -> Bool
  shutdown(Self, (Shutdown) -> Unit, (Shutdown, Errno) -> Unit) -> Unit!Errno
}
ToStream
for
type Tty
Tty
with of_stream(stream :
type Stream
Stream
) ->
type Tty
Tty
= "%identity"
15 16///| 17extern "c" fn uv_tty_make() ->
type Tty
Tty
= "moonbit_uv_tty_make"
18 19///| 20extern "c" fn uv_tty_init(uv :
type Loop Bytes
Loop
, tty :
type Tty
Tty
, fd :
Int
Int
) ->
Int
Int
= "moonbit_uv_tty_init"
21 22///| 23pub fn
type Tty
Tty
::
(self : Loop, file : File) -> Tty!Errno
new
(
Loop
self
:
type Loop Bytes
Loop
,
File
file
:
type File Int
File
) ->
type Tty
Tty
!
type! Errno Status
Errno
{
24 let
Tty
tty
=
() -> Tty
uv_tty_make
()
25 let
Int
result
=
(uv : Loop, tty : Tty, fd : Int) -> Int
uv_tty_init
(
Loop
self
,
Tty
tty
,
File
file
.
Int
_
)
26 if
Int
result
(self_ : Int, other : Int) -> Bool
<
0 {
27 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
result
)
28 } 29
Tty
tty
30} 31 32///| 33enum TtyMode { 34
TtyMode
Normal
35
TtyMode
Raw
36
TtyMode
Io
37
TtyMode
RawVT
38} 39 40///| 41pub fn
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
::
() -> TtyMode
normal
() ->
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
{
42 TtyMode::
TtyMode
Normal
43} 44 45///| 46pub fn
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
::
() -> TtyMode
raw
() ->
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
{
47 TtyMode::
TtyMode
Raw
48} 49 50///| 51pub fn
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
::
() -> TtyMode
io
() ->
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
{
52 TtyMode::
TtyMode
Io
53} 54 55///| 56pub fn
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
::
() -> TtyMode
raw_vt
() ->
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
{
57 TtyMode::
TtyMode
RawVT
58} 59 60///| 61extern "c" fn uv_tty_set_mode(tty :
type Tty
Tty
, mode :
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
) ->
Int
Int
= "moonbit_uv_tty_set_mode"
62 63///| 64pub fn
type Tty
Tty
::
(self : Tty, mode : TtyMode) -> Unit!Errno
set_mode
(
Tty
self
:
type Tty
Tty
,
TtyMode
mode
:
enum TtyMode {
  Normal
  Raw
  Io
  RawVT
}
TtyMode
) ->
Unit
Unit
!
type! Errno Status
Errno
{
65 let
Int
result
=
(tty : Tty, mode : TtyMode) -> Int
uv_tty_set_mode
(
Tty
self
,
TtyMode
mode
)
66 if
Int
result
(self_ : Int, other : Int) -> Bool
<
0 {
67 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
result
)
68 } 69} 70 71///| 72extern "c" fn uv_tty_reset_mode() ->
Int
Int
= "moonbit_uv_tty_reset_mode"
73 74///| 75pub fn
type Tty
Tty
::
() -> Unit!Errno
reset_mode
() ->
Unit
Unit
!
type! Errno Status
Errno
{
76 let
Int
result
=
() -> Int
uv_tty_reset_mode
()
77 if
Int
result
(self_ : Int, other : Int) -> Bool
<
0 {
78 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
result
)
79 } 80} 81