Next | Previous

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_SETint:

    Set I/O position from the beginning.

  • SEEK_CURint:

    Set I/O position from the current position.

  • SEEK_ENDint:

    Set I/O position from the end.

  • stdinfile:

    Stdin is a file handle to the standard input file of the system.

  • stdoutfile:

    Stdout is a file handle to the standard output file of the system.

  • stderrfile:

    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_IFLAGstatic int:

    TTY attribute for input flags.

  • TTY_OFLAGstatic int:

    TTY attribute for output flags.

  • TTY_CFLAGstatic int:

    TTY attribute for control flags.

  • TTY_LFLAGstatic int:

    TTY attribute for local flags.

  • TTY_ISPEEDstatic int:

    TTY attribute for input speed.

  • TTY_OSPEEDstatic int:

    TTY attribute for output speed.

  • IGNBRKstatic int:

    Ignore BREAK condition.

  • BRKINTstatic int:

    Map BREAK to SIGINTR.

  • IGNPARstatic int:

    Ignore (discard) parity errors.

  • PARMRKstatic int:

    Mark parity and framing errors.

  • INPCKstatic int:

    Enable checking of parity errors.

  • ISTRIPstatic int:

    Strip 8th bit off chars.

  • INLCRstatic int:

    Map NL into CR.

  • IGNCRstatic int:

    Ignore CR.

  • ICRNLstatic int:

    Map CR to NL (ala CRMOD).

  • IXONstatic int:

    Enable output flow control.

  • IXOFFstatic int:

    Enable input flow control.

  • IXANYstatic int:

    Any char will restart after stop.

  • IUTF8static int:

    Maintain state for UTF-8 VERASE.

  • OPOSTstatic int:

    Enable following output processing.

  • ONLCRstatic int:

    Map NL to CR-NL (ala CRMOD).

  • CSIZEstatic int:

    Character size mask .

  • CS5static int:

    5 bits (pseudo).

  • CS6static int:

    6 bits.

  • CS7static int:

    7 bits.

  • CS8static int:

    8 bits.

  • CSTOPBstatic int:

    Send 2 stop bits.

  • CREADstatic int:

    Enable receiver.

  • PARENBstatic int:

    Parity enable.

  • PARODDstatic int:

    Odd parity, else even.

  • HUPCLstatic int:

    Hang up on last close.

  • CLOCALstatic int:

    Ignore modem status lines.

  • ECHOEstatic int:

    Visually erase chars.

  • ECHOKstatic:

    Echo NL after line kill

  • ECHOstatic int:

    Enable echoing.

  • ECHONLstatic int:

    Echo NL even if ECHO is off.

  • ISIGstatic int:

    Enable signals INTR, QUIT, [D]SUSP.

  • ICANONstatic int:

    Canonicalize input lines.

  • IEXTENstatic int:

    Enable DISCARD and LNEXT.

  • TOSTOPstatic int:

    Stop background jobs from output.

  • NOFLSHstatic int:

    Don't flush after interrupt.

  • TCSANOWstatic int:

    Make change immediate.

  • TCSADRAINstatic int:

    Drain output, then change.

  • TCSAFLUSHstatic int:

    Drain output, flush input.

  • VEOFstatic int:

    ICANON.

  • VEOLstatic int:

    ICANON.

  • VERASEstatic int:

    ICANON.

  • VKILLstatic int:

    ICANON.

  • VINTRstatic int:

    ISIG.

  • VQUITstatic int:

    ISIG.

  • VSUSPstatic int:

    ISIG.

  • VSTARTstatic int:

    IXON, IXOFF.

  • VSTOPstatic int:

    IXON, IXOFF.

  • VMINstatic int:

    !ICANON.

  • VTIMEstatic 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