Search results

There are no results.

std.stdio.Stdout

class pub Stdout

The standard output stream of the current OS process.

Buffering

This output stream does not use any form of buffering and instead writes its output directly. If buffering is desired, you can do so by wrapping a Stdout in a std.io.BufferedWriter.

Coming from other languages that apply buffering this may be surprising. The reason for this is simple: it's easy to apply buffering by combining Stdout with existing types, but opting out of buffering would require additional flags or types, resulting in a messy API.

Static methods

new

Show source code
Hide source code
fn pub static new -> Stdout {
  Stdout(sys.stdout)
}
fn pub static new -> Stdout

Returns a new Stdout.

Instance methods

flush

Show source code
Hide source code
fn pub mut flush -> Result[Nil, Never] {
  Result.Ok(nil)
}
fn pub mut flush -> Result[Nil, Never]

Flushes any pending writes.

Since this type doesn't use any buffering, this method is a no-op.

print

Show source code
Hide source code
fn pub mut print(string: String) -> Result[Nil, Error] {
  write_string(string).then(fn (_) { write_string('\n') })
}
fn pub mut print(string: String) -> Result[Nil, Error]

Writes the entirety of string to the underlying stream, followed by writing a Unix newline to the stream.

terminal?

Show source code
Hide source code
fn pub terminal? -> Bool {
  sys.terminal?(@fd)
}
fn pub terminal? -> Bool

Returns true if the output stream is connected to a terminal/TTY.

Examples

import std.stdio (Stdout)

Stdout.new.terminal? # => true

write_bytes

Show source code
Hide source code
fn pub mut write_bytes(bytes: ref ByteArray) -> Result[Nil, Error] {
  write_all_internal(bytes.to_pointer, bytes.size)
}
fn pub mut write_bytes(bytes: ref ByteArray) -> Result[Nil, Error]

Writes the entirety of bytes to the underlying stream.

Types implementing this method must guarantee that upon returning from this method, either all of the data is written and a Ok(Nil) is returned, or an Error(Error) is returned.

write_string

Show source code
Hide source code
fn pub mut write_string(string: String) -> Result[Nil, Error] {
  write_all_internal(string.to_pointer, string.size)
}
fn pub mut write_string(string: String) -> Result[Nil, Error]

Writes the entirety of string to the underlying stream.

See Write.write_bytes for more details.

Implemented traits

std.io.

Write

impl Write for Stdout