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
- io.SEEK_SET
- Set I/O position from the beginning
- io.SEEK_CUR
- Set I/O position from the current position
- io.SEEK_END
- Set I/O position from the end
- io.stdin
- stdin is a file handle to the standard input file of the system
- io.stdout
- stdout is a file handle to the standard output file of the system
- io.stderr
- stderr is a file handle to the standard error file of the system
Functions
- io.flush(file: file)
- flushes the content of the given file handle
- io.putc(c: char)
- writes character c to the screen return nil
- io.getc()
- reads character(s) from standard input
when length is given, gets
length
number of characters else, gets a single characterreturns char | string
- io.readline([message: string])
- 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.
- newlines will not be added automatically for messages.
returns string
Classes
class TTY
class TTY is an interface to TTY terminals this class contains definitions to control TTY terminals
class TTY properties
- TTY.TTY_IFLAG
- TTY attribute for input flags static
- TTY.TTY_OFLAG
- TTY attribute for output flags static
- TTY.TTY_CFLAG
- TTY attribute for control flags static
- TTY.TTY_LFLAG
- TTY attribute for local flags static
- TTY.TTY_ISPEED
- TTY attribute for input speed static
- TTY.TTY_OSPEED
- TTY attribute for output speed static
- TTY.IGNBRK
- ignore BREAK condition static
- TTY.BRKINT
- map BREAK to SIGINTR static
- TTY.IGNPAR
- ignore (discard) parity errors static
- TTY.PARMRK
- mark parity and framing errors static
- TTY.INPCK
- enable checking of parity errors static
- TTY.ISTRIP
- strip 8th bit off chars static
- TTY.INLCR
- map NL into CR static
- TTY.IGNCR
- ignore CR static
- TTY.ICRNL
- map CR to NL (ala CRMOD) static
- TTY.IXON
- enable output flow control static
- TTY.IXOFF
- enable input flow control static
- TTY.IXANY
- any char will restart after stop static
- TTY.IUTF8
- maintain state for UTF-8 VERASE static
- TTY.OPOST
- enable following output processing static
- TTY.ONLCR
- map NL to CR-NL (ala CRMOD) static
- TTY.CSIZE
- character size mask static
- TTY.CS5
- 5 bits (pseudo) static
- TTY.CS6
- 6 bits static
- TTY.CS7
- 7 bits static
- TTY.CS8
- 8 bits static
- TTY.CSTOPB
- send 2 stop bits static
- TTY.CREAD
- enable receiver static
- TTY.PARENB
- parity enable static
- TTY.PARODD
- odd parity, else even static
- TTY.HUPCL
- hang up on last close static
- TTY.CLOCAL
- ignore modem status lines static
- TTY.ECHOE
- visually erase chars static
- TTY.ECHOK
- echo NL after line kill static
- TTY.ECHO
- enable echoing static
- TTY.ECHONL
- echo NL even if ECHO is off static
- TTY.ISIG
- enable signals INTR, QUIT, [D]SUSP static
- TTY.ICANON
- canonicalize input lines static
- TTY.IEXTEN
- enable DISCARD and LNEXT static
- TTY.TOSTOP
- stop background jobs from output static
- TTY.NOFLSH
- don’t flush after interrupt static
- TTY.TCSANOW
- make change immediate static
- TTY.TCSADRAIN
- drain output, then change static
- TTY.TCSAFLUSH
- drain output, flush input static
- TTY.VEOF
- ICANON static
- TTY.VEOL
- ICANON static
- TTY.VERASE
- ICANON static
- TTY.VKILL
- ICANON static
- TTY.VINTR
- ISIG static
- TTY.VQUIT
- ISIG static
- TTY.VSUSP
- ISIG static
- TTY.VSTART
- IXON, IXOFF static
- TTY.VSTOP
- IXON, IXOFF static
- TTY.VMIN
- !ICANON static
- TTY.VTIME
- !ICANON static
class TTY methods
- TTY(std: file)
- constructor
- file must be one of stdout and stderr
- get_attr()
- Returns the attribute of the current tty session The returned a attributes is a dict containing the TTY_ flags
- 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.
- this flags will be merged and not overwritten
- set_raw()
- sets the current tty to raw mode return bool
- exit_raw()
- disables the raw mode flags on the current tty return bool
- flush()
- flushes the standard output and standard error interface