pub struct BufferHost { /* private fields */ }Expand description
A host that collects console output in memory.
Clones share one buffer, so a caller can keep a clone, hand the other to a VM, and read the output afterward.
Implementations§
Source§impl BufferHost
impl BufferHost
Sourcepub fn push_input(&self, line: &str)
pub fn push_input(&self, line: &str)
Queue a line for the program to read. A read of one key takes a whole line too, as the name of the key.
Sourcepub fn set_interactive(&self, interactive: bool)
pub fn set_interactive(&self, interactive: bool)
Say that more input may be queued later, so that running out is not the end of input: the program is to stop and wait.
Sourcepub fn enable_panes(&self, rows: usize, columns: usize)
pub fn enable_panes(&self, rows: usize, columns: usize)
Show panes, on a screen of the given size.
Trait Implementations§
Source§impl Clone for BufferHost
impl Clone for BufferHost
Source§impl Debug for BufferHost
impl Debug for BufferHost
Source§impl Default for BufferHost
impl Default for BufferHost
Source§impl Host for BufferHost
impl Host for BufferHost
Source§fn read_file(&mut self, name: &str) -> Result<Vec<u8>, FileError>
fn read_file(&mut self, name: &str) -> Result<Vec<u8>, FileError>
The whole contents of a file. Names are the host’s to interpret:
a path on a system with a file system, a key in a browser’s
storage.
Source§fn write_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>
fn write_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>
Create a file with the given contents, replacing any there was.
Source§fn append_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>
fn append_file(&mut self, name: &str, data: &[u8]) -> Result<(), FileError>
Add to the end of a file, creating it if it is not there.
Source§fn file_info(&mut self, name: &str, _follow_links: bool) -> Option<FileInfo>
fn file_info(&mut self, name: &str, _follow_links: bool) -> Option<FileInfo>
What a name refers to, or
None if nothing. With follow_links,
a symbolic link is described by what it leads to. Read moreSource§fn rename_file(&mut self, from: &str, to: &str) -> Result<(), FileError>
fn rename_file(&mut self, from: &str, to: &str) -> Result<(), FileError>
Give a file a new name, which must not be in use.
Source§fn temp_file_name(&mut self) -> Option<String>
fn temp_file_name(&mut self) -> Option<String>
A name for a new temporary file, which does not exist yet.
Source§fn read_line(&mut self) -> Input
fn read_line(&mut self) -> Input
Read a line of input from the player, without the line ending.
Source§fn read_key(&mut self) -> Input
fn read_key(&mut self) -> Input
Read one keystroke. A key that types a character is that character;
Enter is a newline; any other key goes by its name in square
brackets, such as
[up] or [f1].Source§fn has_panes(&self) -> bool
fn has_panes(&self) -> bool
Whether the host can show panes. Without them, a program
that asks for one is told it cannot have it, as on a plain
console.
Source§fn pane_create(
&mut self,
parent: Option<u32>,
placement: Placement,
spec: PaneSpec,
) -> Option<u32>
fn pane_create( &mut self, parent: Option<u32>, placement: Placement, spec: PaneSpec, ) -> Option<u32>
Create a pane inside another, or inside the main window
if
parent is None: its handle, or None if the host cannot.Source§fn pane_delete(&mut self, id: u32)
fn pane_delete(&mut self, id: u32)
Remove a pane.
Source§fn pane_clear(&mut self, id: u32)
fn pane_clear(&mut self, id: u32)
Remove the text in a pane.
Source§fn pane_write(&mut self, id: u32, text: &str)
fn pane_write(&mut self, id: u32, text: &str)
Add text to a pane. The text is already broken into lines
that fit.
Source§fn pane_set_size(&mut self, id: u32, size: i32, units: i32, advisory: bool)
fn pane_set_size(&mut self, id: u32, size: i32, units: i32, advisory: bool)
Change the size of a pane. See
pane::Screen::set_size.Source§fn pane_size_to_contents(&mut self, id: u32)
fn pane_size_to_contents(&mut self, id: u32)
Make a pane as big as what it holds.
Source§fn pane_go_to(&mut self, id: u32, row: usize, column: usize)
fn pane_go_to(&mut self, id: u32, row: usize, column: usize)
Move where text goes next in a text grid, counting from zero.
Source§fn pane_set_screen_color(&mut self, id: u32, color: u32)
fn pane_set_screen_color(&mut self, id: u32, color: u32)
Give a pane a background color: one of the colors the
host chooses, such as
pane::color::STATUS_BG, or an RGB value.Source§fn rich_display(&self) -> Option<RichDisplay>
fn rich_display(&self) -> Option<RichDisplay>
What the display can do beyond plain text, if it is a rich
display;
None for a display of text, which gets its text through
Host::print, broken into lines that fit.Source§fn print_markup(&mut self, markup: &str)
fn print_markup(&mut self, markup: &str)
On a rich display: what the program wrote, as it wrote it, markup
and all, in order. The host checks it with a
rich::Checker.Source§fn print_input(&mut self, text: &str)
fn print_input(&mut self, text: &str)
On a rich display: a line the player typed, from a script, shown
as the player’s own words.
Source§fn random_bytes(&mut self, buffer: &mut [u8])
fn random_bytes(&mut self, buffer: &mut [u8])
Fill a buffer with unpredictable bytes, for seeding the random
number generator. A host that leaves the buffer alone gives every
run the same seed, which is what tests want.
Source§fn create_dir(&mut self, name: &str, parents: bool) -> Result<(), FileError>
fn create_dir(&mut self, name: &str, parents: bool) -> Result<(), FileError>
Create a directory, and with
parents any directories above it
that are missing.Source§fn remove_dir(&mut self, name: &str, contents: bool) -> Result<(), FileError>
fn remove_dir(&mut self, name: &str, contents: bool) -> Result<(), FileError>
Remove a directory, which has to be empty unless
contents says
to delete what is in it too.Source§fn list_dir(&mut self, name: &str) -> Option<Vec<String>>
fn list_dir(&mut self, name: &str) -> Option<Vec<String>>
The names in a directory, without the path to it. A host whose
directories have entries for themselves and their parents includes
. and ...Source§fn absolute_path(&mut self, name: &str) -> Option<String>
fn absolute_path(&mut self, name: &str) -> Option<String>
The full name of a file, from a root.
Source§fn root_dirs(&mut self) -> Vec<String>
fn root_dirs(&mut self) -> Vec<String>
The roots of the file system:
/ on some systems, a list of
drives on others.Source§fn sandbox(&mut self, name: &str) -> Sandbox
fn sandbox(&mut self, name: &str) -> Sandbox
Where a file is in relation to the folder the program’s file
access is confined to. The default confines nothing.
Source§fn special_file(&mut self, id: i32) -> Option<String>
fn special_file(&mut self, id: i32) -> Option<String>
The name of one of the files that programs ask for by number
because where they are kept is up to the system: 1 is the file of
settings shared by every game that uses the standard library, and
2 the same for the web interface.
Source§fn choose_file(
&mut self,
prompt: &str,
dialog: FileDialog,
kind: FileKind,
) -> Option<FileChoice>
fn choose_file( &mut self, prompt: &str, dialog: FileDialog, kind: FileKind, ) -> Option<FileChoice>
Ask the player for a file in a dialog of the system’s own, with
the program’s prompt as its title, or
None for a host that has
no such dialog: the VM then asks for the file’s name as a line of
input, after the prompt, as a console of text does.Source§fn clear_screen(&mut self)
fn clear_screen(&mut self)
Clear the main console.
Source§fn console_width(&mut self) -> Option<usize>
fn console_width(&mut self) -> Option<usize>
The width of the main console in columns, if the host has one of
its own, such as a terminal window’s. Text is broken into lines
that fit. Without one the width is 80 columns.
Source§fn script_input(&mut self)
fn script_input(&mut self)
Input has just come from a script instead of from the player. A
host that pauses when a screenful of text has gone by since the
player last typed starts counting again from here.
Source§fn sleep(&mut self, milliseconds: u32) -> bool
fn sleep(&mut self, milliseconds: u32) -> bool
Pause for a number of milliseconds. A host that can wait does,
and returns true. One that cannot returns false, which stops the
VM where it is; when the time has passed, the host resumes the VM,
which asks again, and this time the answer is true.
Source§fn status_line(&mut self, text: &str)
fn status_line(&mut self, text: &str)
Show text in the status line: the left part, which is usually the
name of the player’s location.
Source§fn status_right(&mut self, text: &str)
fn status_right(&mut self, text: &str)
Show text at the right of the status line, usually the score.
Source§fn time(&mut self) -> Time
fn time(&mut self) -> Time
The time now. A host without a clock reports the start of 1970,
which also keeps tests reproducible.
Source§fn local_time_zone(&mut self) -> Option<String>
fn local_time_zone(&mut self) -> Option<String>
The name of the host’s time zone in the zoneinfo database, such as
America/Chicago, if the host knows it. Without one, local time
is UTC shifted by the offset that Host::time reports.Source§fn system_name(&self) -> String
fn system_name(&self) -> String
A name for the system the host runs on.
Source§fn pane_write_markup(&mut self, id: u32, markup: &str)
fn pane_write_markup(&mut self, id: u32, markup: &str)
On a rich display: add what the program wrote to a text pane, as
it wrote it, markup and all, as
Host::print_markup does for the
main window. A text grid’s text still comes through
Host::pane_write.Source§fn pane_flush(&mut self, id: u32)
fn pane_flush(&mut self, id: u32)
Show what has been written to a pane.
Auto Trait Implementations§
impl !RefUnwindSafe for BufferHost
impl !Send for BufferHost
impl !Sync for BufferHost
impl !UnwindSafe for BufferHost
impl Forget for BufferHost
impl Freeze for BufferHostwhere
*const RcInner<RefCell<String>> is !null: Freeze,
PhantomData<RcInner<RefCell<String>>>: Freeze,
*const RcInner<RefCell<HashMap<String, Vec<u8>>>> is !null: Freeze,
PhantomData<RcInner<RefCell<HashMap<String, Vec<u8>>>>>: Freeze,
*const RcInner<RefCell<VecDeque<String>>> is !null: Freeze,
PhantomData<RcInner<RefCell<VecDeque<String>>>>: Freeze,
*const RcInner<RefCell<u32>> is !null: Freeze,
PhantomData<RcInner<RefCell<u32>>>: Freeze,
*const RcInner<RefCell<bool>> is !null: Freeze,
PhantomData<RcInner<RefCell<bool>>>: Freeze,
*const RcInner<RefCell<Option<Screen>>> is !null: Freeze,
PhantomData<RcInner<RefCell<Option<Screen>>>>: Freeze,
impl Move for BufferHost
impl Unpin for BufferHost
impl UnsafeUnpin for BufferHostwhere
*const RcInner<RefCell<String>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<String>>>: UnsafeUnpin,
*const RcInner<RefCell<HashMap<String, Vec<u8>>>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<HashMap<String, Vec<u8>>>>>: UnsafeUnpin,
*const RcInner<RefCell<VecDeque<String>>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<VecDeque<String>>>>: UnsafeUnpin,
*const RcInner<RefCell<u32>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<u32>>>: UnsafeUnpin,
*const RcInner<RefCell<bool>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<bool>>>: UnsafeUnpin,
*const RcInner<RefCell<Option<Screen>>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<Option<Screen>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more