Import std.term.terminal
Terminal
class
Public Abstract Class Terminal
Where text goes, as it is, escape codes and all, and where keys come from. What's written is sent on at a Flush. Reading keys is in raw mode, where they come as they're typed, without showing them; StartRawMode keeps it on for a while, as a full-screen app does.
Examples
Function Greet(terminal: Terminal)
terminal.WriteLine("hello, {terminal.Columns} columns")
End Function
Local fake = FakeTerminal(40, 10)
Greet(fake)
Expect(fake.Output == "hello, 40 columns\n")-
A Terminal with input of its own.
-
How many columns it has.
-
How many rows it has.
-
How many colors it shows.
-
Whether what's written goes to a terminal, where a line can be drawn again in place and the cursor moved, rather than to a pipe or a file, which only gets lines as they're done.
-
Whether keys come as they're typed, rather than from a pipe or a file, which has them a line at a time.
-
Writes
textas it is, escape codes and all. -
Sends on what's been written.
-
Reads what's come into the start of
into, waiting fortimeoutnanoseconds at most, or as long as it takes when that's negative, and gives how many bytes it read: 0 when none came in time, once the time has passed, -1 at the end of the input, and -2, before any more, once its size has changed. What a program reads goes through ReadEvent and the rest. -
Sets how input comes: 0 as it was, or else 1 for each key as it's typed, without showing it, plus 2 for Ctrl+C as a key, and 4 for the mouse's reports.
-
What changes the screen, and what puts it back, which the console writes as the program ends meanwhile, however it ends; "" and "" once it's back.
-
Writes
textand a line break. -
Writes
textinstyle, as many colors as it shows, or alone where it shows none. -
textinstyle, as it shows colors. -
Whether it's in raw mode.
-
Starts raw mode, until a matching EndRawMode: keys come as they're typed, without showing them. Ctrl+C still ends the program, unless
ctrlCIsKeysays it's a key; withmouse, themouse's reports come too, once the terminal is asked for them. Each StartRawMode needs its EndRawMode; those inside another add what they ask for. -
Ends a StartRawMode, and raw mode with the last of them. Panics without one.
-
The next event, in raw mode for as long as it waits, if it isn't already, or Null at the end of the input. A RESIZE gives the size it has now.
-
The next event, in raw mode for as long as it waits, which is
timeoutat most, or Null when none came by then, or at the end of the input. -
The next key, in raw mode for as long as it waits, if it isn't already, or Null at the end of the input. What isn't a key is skipped.
-
The next key, which waits for
timeoutat most, or Null when none came by then. -
Writes the
prompt, then reads a line in raw mode without showing it, up to ENTER, as for a password. BACKSPACE takes back the last character, and Ctrl+U the whole line, and what's pasted is typed. Null at the end of the input, or for Ctrl+D on an empty line. -
The program's console: stdout, and stdin for keys. Its state is the main thread's.
-
The console for writing to
stream, stdout or stderr, as a progress bar does so what the program prints to stdout stays as it is. Both read keys from stdin, which they share.
Report an issue with this page or with FutureBlitz on GitHub.