factor/library/io/stdio.facts

127 lines
7.0 KiB
Plaintext

USING: help io ;
HELP: stdio f
{ $description "Variable. Holds a stream, used for various implicit stream operations. Rebound using " { $link with-stream } " and " { $link with-stream* } "." } ;
HELP: close "( -- )"
{ $contract "Closes the " { $link stdio } " stream." }
$io-error ;
HELP: readln "( -- str/f )"
{ $values { "str/f" "a string or " { $link f } } }
{ $contract "Reads a line of input from the " { $link stdio } " stream. Outputs " { $link f } " on stream exhaustion." }
$io-error ;
HELP: read1 "( -- ch/f )"
{ $values { "ch/f" "a character or " { $link f } } }
{ $contract "Reads a character of input from the " { $link stdio } " stream. Outputs " { $link f } " on stream exhaustion." }
$io-error ;
HELP: read "( n -- str/f )"
{ $values { "str/f" "a string or " { $link f } } }
{ $contract "Reads " { $snippet "n" } " characters of input from the " { $link stdio } " stream. Outputs a truncated string or " { $link f } " on stream exhaustion." }
$io-error ;
HELP: write1 "( ch -- )"
{ $values { "ch" "a character" } }
{ $contract "Writes a character of output to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
HELP: write1 "( ch -- )"
{ $values { "ch" "a character" } }
{ $contract "Writes a character of output to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
HELP: write "( str -- )"
{ $values { "str" "a string" } }
{ $contract "Writes a string of output to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
HELP: flush "( -- )"
{ $contract "Waits for any pending output to the " { $link stdio } " stream to complete." }
$io-error ;
HELP: terpri "( -- )"
{ $contract "Writes a line terminator to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
HELP: format "( str style -- )"
{ $values { "str" "a string" } { "style" "a hashtable" } }
{ $contract "Writes formatted text to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
{ $notes "Details are in the documentation for " { $link stream-format } "." }
$io-error ;
HELP: with-nesting "( style quot -- )"
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
{ $contract "Calls the quotation in a new dynamic scope with the " { $link stdio } " stream rebound to a nested paragraph stream, with formatting information applied." }
{ $notes "Details are in the documentation for " { $link stream-format } "." }
$io-error ;
HELP: print "( style quot -- )"
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
{ $description "Writes a newline-terminated string to the " { $link stdio } " stream." }
$io-error ;
HELP: with-stream "( stream quot -- )"
{ $values { "stream" "an input or output stream" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." }
{ $see-also with-stream* } ;
HELP: with-stream* "( stream quot -- )"
{ $values { "stream" "an input or output stream" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to " { $snippet "stream" } "." }
{ $notes "This word differs from " { $link with-stream } " in that if an error is thrown while the quotation is executing, the stream is " { $emphasis "not" } " closed." }
{ $see-also with-stream } ;
HELP: style-stack f
{ $description "Variable. Holds a vector of hashtables." }
{ $see-also with-style format* } ;
HELP: with-style "( style quot -- )"
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
{ $description "Pushes a style on the style stack, and calls the quotation." }
{ $see-also format* with-nesting* } ;
HELP: current-style "( -- style )"
{ $values { "style" "a hashtable" } }
{ $description "Creates a new hashtable by concatenating all styles on the style stack, with keys in more recently pushed styles taking precedence." }
{ $see-also format* with-nesting* } ;
HELP: format* "( str -- )"
{ $values { "str" "a string" } }
{ $description "Writes formatted text to the " { $link stdio } " stream using the current style." }
{ $see-also current-style }
$io-error ;
HELP: bl "( -- )"
{ $description "Writes a word break to the " { $link stdio } " stream using the current style." }
{ $notes "This word is useful even when not doing formatting. If " { $link stdio } " is a plain text stream, it simply outputs a space." }
{ $see-also current-style }
$io-error ;
HELP: with-nesting* "( style quot -- )"
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope with the " { $link stdio } " stream rebound to a nested paragraph stream with the current style." }
$io-error
{ $see-also current-style } ;
HELP: write-object "( obj quot -- )"
{ $values { "obj" "an object" } { "quot" "a quotation" } }
{ $description "Pushes a style on the style stack associating all output with the object, and calls the quotation. If the " { $link stdio } " stream supports it, any text output by the quotation will become a clickable presentation of the object." }
$io-error ;
HELP: simple-object "( str obj -- )"
{ $values { "str" "a string" } { "obj" "an object" } }
{ $description "Writes a string to the " { $link stdio } " stream, associating it with the object. If formatted output is supported, the string will become a clickable presentation of the object, otherwise this word behaves like a call to " { $link write } "." }
$io-error ;
HELP: write-outliner "( content caption -- )"
{ $values { "content" "a quotation" } { "caption" "a quotation" } }
{ $description "Writes an outliner to the " { $link stdio } " stream. The " { $snippet "caption" } " quotation is called to produce a label for an outliner. Expanding the outliner calls " { $snippet "content" } " in a new dynamic scope with " { $link stdio } " rebound to the body of the outliner. If the stream does not support formatted output, this simply calls " { $snippet "caption" } " and ignores " { $snippet "content" } "." }
$io-error ;
HELP: simple-outliner "( str obj content -- )"
{ $values { "str" "a string" } { "obj" "an object" } { "content" "a quotation" } }
{ $description "Writes an outliner to the " { $link stdio } " stream. The outliner's caption is a the string " { $snippet "str" } " with an associated presentation of " { $snippet "obj" } ". Expanding the outliner calls " { $snippet "content" } " in a new dynamic scope with " { $link stdio } " rebound to the body of the outliner. If the stream does not support formatted output, this simply writes " { $snippet "str" } " and ignores everything else." }
$io-error ;