io
This module provides interfaces for working with to I/O stream and TTYs as well as expose the operating system standard I/O for easy access.
Some I/O operations that should belong to this module have been merged as
core features and offered as built-in functions for Blade. Specifically
file I/O features that can be accessed via the built-in file()
function.
The standard I/O streams are also files and you can call almost all file methods on them. Whenever a file method is not supported, you'll get an error message telling you that such operation is not supported for standard streams.
Example
The following example shows how to use the io
module for accepting user name
and printing the result.
import io
var name = io.readline('What is your name?')
echo name
Properties
-
SEEK_SET ⇢ int:
Set I/O position from the beginning.
-
SEEK_CUR ⇢ int:
Set I/O position from the current position.
-
SEEK_END ⇢ int:
Set I/O position from the end.
-
stdin ⇢ file:
Stdin is a file handle to the standard input file of the system.
-
stdout ⇢ file:
Stdout is a file handle to the standard output file of the system.
-
stderr ⇢ file:
Stderr is a file handle to the standard error file of the system.
Functions
flush(file)
Flushes the content of the given file handle
putc(c)
Writes character c to the screen.
Parameters
- char|number c
getc()
Reads character(s) from standard input
When length is given, gets length
number of characters
else, gets a single character
Returns
- char|string
getch()
Reads character(s) from standard input without printing to standard output
When length is given, gets length
number of characters
else, gets a single character.
Returns
- char|string
readline(message, secure, obscure_text)
Reads an entire line from standard input. If a messagge is given, the
message will be printed before it begins to wait for a user input. If
secure is true
, the user's input will not be printing and obscure_text
will be printed instead.
Parameters
- string? message
- bool? secure
- string? obscure_text: : Default value is
*
.
Returns
- string
Notes
- Newlines will not be added automatically for messages.
Classes
class TTY
class TTY is an interface to TTY terminals this class contains definitions to control TTY terminals
Fields
-
TTY_IFLAG ⇢ static int:
TTY attribute for input flags.
-
TTY_OFLAG ⇢ static int:
TTY attribute for output flags.
-
TTY_CFLAG ⇢ static int:
TTY attribute for control flags.
-
TTY_LFLAG ⇢ static int:
TTY attribute for local flags.
-
TTY_ISPEED ⇢ static int:
TTY attribute for input speed.
-
TTY_OSPEED ⇢ static int:
TTY attribute for output speed.
-
IGNBRK ⇢ static int:
Ignore BREAK condition.
-
BRKINT ⇢ static int:
Map BREAK to SIGINTR.
-
IGNPAR ⇢ static int:
Ignore (discard) parity errors.
-
PARMRK ⇢ static int:
Mark parity and framing errors.
-
INPCK ⇢ static int:
Enable checking of parity errors.
-
ISTRIP ⇢ static int:
Strip 8th bit off chars.
-
INLCR ⇢ static int:
Map NL into CR.
-
IGNCR ⇢ static int:
Ignore CR.
-
ICRNL ⇢ static int:
Map CR to NL (ala CRMOD).
-
IXON ⇢ static int:
Enable output flow control.
-
IXOFF ⇢ static int:
Enable input flow control.
-
IXANY ⇢ static int:
Any char will restart after stop.
-
IUTF8 ⇢ static int:
Maintain state for UTF-8 VERASE.
-
OPOST ⇢ static int:
Enable following output processing.
-
ONLCR ⇢ static int:
Map NL to CR-NL (ala CRMOD).
-
CSIZE ⇢ static int:
Character size mask .
-
CS5 ⇢ static int:
5 bits (pseudo).
-
CS6 ⇢ static int:
6 bits.
-
CS7 ⇢ static int:
7 bits.
-
CS8 ⇢ static int:
8 bits.
-
CSTOPB ⇢ static int:
Send 2 stop bits.
-
CREAD ⇢ static int:
Enable receiver.
-
PARENB ⇢ static int:
Parity enable.
-
PARODD ⇢ static int:
Odd parity, else even.
-
HUPCL ⇢ static int:
Hang up on last close.
-
CLOCAL ⇢ static int:
Ignore modem status lines.
-
ECHOE ⇢ static int:
Visually erase chars.
-
ECHOK ⇢ static:
Echo NL after line kill
-
ECHO ⇢ static int:
Enable echoing.
-
ECHONL ⇢ static int:
Echo NL even if ECHO is off.
-
ISIG ⇢ static int:
Enable signals INTR, QUIT, [D]SUSP.
-
ICANON ⇢ static int:
Canonicalize input lines.
-
IEXTEN ⇢ static int:
Enable DISCARD and LNEXT.
-
TOSTOP ⇢ static int:
Stop background jobs from output.
-
NOFLSH ⇢ static int:
Don't flush after interrupt.
-
TCSANOW ⇢ static int:
Make change immediate.
-
TCSADRAIN ⇢ static int:
Drain output, then change.
-
TCSAFLUSH ⇢ static int:
Drain output, flush input.
-
VEOF ⇢ static int:
ICANON.
-
VEOL ⇢ static int:
ICANON.
-
VERASE ⇢ static int:
ICANON.
-
VKILL ⇢ static int:
ICANON.
-
VINTR ⇢ static int:
ISIG.
-
VQUIT ⇢ static int:
ISIG.
-
VSUSP ⇢ static int:
ISIG.
-
VSTART ⇢ static int:
IXON, IXOFF.
-
VSTOP ⇢ static int:
IXON, IXOFF.
-
VMIN ⇢ static int:
!ICANON.
-
VTIME ⇢ static int:
!ICANON.
Methods
TTY(std) ⇢ Constructor
TTY(std: file)
Parameters
- file std
Notes
- file must be one of stdout and stderr
get_attr()
Returns the attribute of the current tty session The returned attributes is a dict containing the TTY_ flags
Returns
- dict
set_attr(option, attrs)
set_attr(option: number, attrs: dict)
sets the attributes of the current tty session
- option: one ot the TCSA options above (see their description above)
- attrs a dictionary of the TTY_ flags listed above
- one can safely omit any of the TTY_ flags listed above and Blade will fill in the default values as it exists.
Parameters
- number option
- dict attr
Returns
- bool
Notes
- This flags will be merged and not overwritten
set_raw()
Sets the current tty to raw mode.
Returns
- bool
exit_raw()
Disables the raw mode flags on the current tty.
Returns
- bool
flush()
Flushes the standard output and standard error interface