Keypress
- Keys that can be returned by Term::read
.for Term
of Drop for Term
Keypress
Keys that can be returned by Term::read
.
KeyCharacter(char)
KeyBackspace
KeyReturn
KeyTab
KeyCtrl(char)
KeyF(int)
KeyUp
KeyDown
KeyLeft
KeyRight
KeyHome
KeyEnd
KeyInsert
KeyDelete
KeyEscape
Term
new
fn new() -> Term
Creates a new Term
instance.
This can be used to manipulate the terminal for full screen applications.
clear
fn clear(&mut self)
Clears the screen.
move
fn move(&mut self, col: uint, row: uint)
Moves the cursor to (col
, row
).
fg_color
fn fg_color(&mut self, color: info::Color)
Changes the currently active foreground color to color
.
bg_color
fn bg_color(&mut self, color: info::Color)
Changes the currently active background color to color
.
reset_color
fn reset_color(&mut self)
Resets the foreground and background colors to the default.
underline
fn underline(&mut self, enabled: bool)
Enables or disables underline mode.
standout
fn standout(&mut self, enabled: bool)
Enables or disables standout mode.
reverse
fn reverse(&mut self, enabled: bool)
Enables or disables reverse mode.
bold
fn bold(&mut self, enabled: bool)
Enables or disables bold mode.
blink
fn blink(&mut self, enabled: bool)
Enables or disables blink mode.
cursor
fn cursor(&mut self, enabled: bool)
Enables or disables visible cursor mode.
alternate_screen
fn alternate_screen(&mut self, enabled: bool)
Switches to or from the alternate screen.
This is used to provide a separate place to do all of the drawing for a full screen app, so that at the end of the application, the terminal will be restored to the original state.
write
fn write(&mut self, text: &str)
Write a string to the terminal.
Due to buffering, using io::print()
will not work properly. All text written to the terminal must go through the Term
object, or the state of the screen will likely end up incorrect.
flush
fn flush(&mut self)
Flush the data written so far to the terminal.
This is also done implicitly before every call to read
, so there's not usually a reason to do it manually, other than edge cases such as timed animations.
read
fn read(&mut self) -> Option<Keypress>
Read a keypress from the terminal.
Returns Some(Keypress)
if a key was read, and None
if stdin
reaches eof
.
Note that most special keys are actually sequences of multiple characters. This means that if a prefix of a special character key sequence was read, it has to wait to see if there are more characters coming, or if that character was the only key. Since most of these multi-character sequences start with escape, there will be a delay in reading a single KeyEscape
keypress.
Also, other special keys are represented as control keys, so for instance, ^J
will likely return KeyReturn
instead of KeyCtrl('j')
.
Drop
for Term
finalize
fn finalize(&self)