Link Search Menu Expand Document

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 | number)
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 character

returns char | string
io.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
io.readline([message: string [, secure: bool = false [, 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.
  • 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


static TTY.TTY_IFLAG
TTY attribute for input flags
static
static TTY.TTY_OFLAG
TTY attribute for output flags
static
static TTY.TTY_CFLAG
TTY attribute for control flags
static
static TTY.TTY_LFLAG
TTY attribute for local flags
static
static TTY.TTY_ISPEED
TTY attribute for input speed
static
static TTY.TTY_OSPEED
TTY attribute for output speed
static
static TTY.IGNBRK
ignore BREAK condition
static
static TTY.BRKINT
map BREAK to SIGINTR
static
static TTY.IGNPAR
ignore (discard) parity errors
static
static TTY.PARMRK
mark parity and framing errors
static
static TTY.INPCK
enable checking of parity errors
static
static TTY.ISTRIP
strip 8th bit off chars
static
static TTY.INLCR
map NL into CR
static
static TTY.IGNCR
ignore CR
static
static TTY.ICRNL
map CR to NL (ala CRMOD)
static
static TTY.IXON
enable output flow control
static
static TTY.IXOFF
enable input flow control
static
static TTY.IXANY
any char will restart after stop
static
static TTY.IUTF8
maintain state for UTF-8 VERASE
static
static TTY.OPOST
enable following output processing
static
static TTY.ONLCR
map NL to CR-NL (ala CRMOD)
static
static TTY.CSIZE
character size mask
static
static TTY.CS5
5 bits (pseudo)
static
static TTY.CS6
6 bits
static
static TTY.CS7
7 bits
static
static TTY.CS8
8 bits
static
static TTY.CSTOPB
send 2 stop bits
static
static TTY.CREAD
enable receiver
static
static TTY.PARENB
parity enable
static
static TTY.PARODD
odd parity, else even
static
static TTY.HUPCL
hang up on last close
static
static TTY.CLOCAL
ignore modem status lines
static
static TTY.ECHOE
visually erase chars
static
static TTY.ECHOK
echo NL after line kill
static
static TTY.ECHO
enable echoing
static
static TTY.ECHONL
echo NL even if ECHO is off
static
static TTY.ISIG
enable signals INTR, QUIT, [D]SUSP
static
static TTY.ICANON
canonicalize input lines
static
static TTY.IEXTEN
enable DISCARD and LNEXT
static
static TTY.TOSTOP
stop background jobs from output
static
static TTY.NOFLSH
don’t flush after interrupt
static
static TTY.TCSANOW
make change immediate
static
static TTY.TCSADRAIN
drain output, then change
static
static TTY.TCSAFLUSH
drain output, flush input
static
static TTY.VEOF
ICANON
static
static TTY.VEOL
ICANON
static
static TTY.VERASE
ICANON
static
static TTY.VKILL
ICANON
static
static TTY.VINTR
ISIG
static
static TTY.VQUIT
ISIG
static
static TTY.VSUSP
ISIG
static
static TTY.VSTART
IXON, IXOFF
static
static TTY.VSTOP
IXON, IXOFF
static
static TTY.VMIN
!ICANON
static
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

Back to top

Copyright © 2021 Ore Richard Muyiwa. Distributed under the MIT license.