Skip to main content

BufferHost

Struct BufferHost 

Source
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

Source

pub fn new() -> Self

A host with an empty buffer.

Source

pub fn output(&self) -> String

Everything displayed so far.

Source

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.

Source

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.

Source

pub fn file(&self, name: &str) -> Option<Vec<u8>>

The contents of a file the program wrote.

Source

pub fn enable_panes(&self, rows: usize, columns: usize)

Show panes, on a screen of the given size.

Source

pub fn screen(&self) -> Ref<'_, Option<Screen>>

The panes, if they are shown.

Source

pub fn set_file(&self, name: &str, data: &[u8])

Supply a file for the program to read.

Trait Implementations§

Source§

impl Clone for BufferHost

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BufferHost

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferHost

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Host for BufferHost

Source§

fn print(&mut self, text: &str)

Display text on the main console.
Source§

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>

Create a file with the given contents, replacing any there was.
Source§

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>

What a name refers to, or None if nothing. With follow_links, a symbolic link is described by what it leads to. Read more
Source§

fn delete_file(&mut self, name: &str) -> Result<(), FileError>

Delete a file.
Source§

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>

A name for a new temporary file, which does not exist yet.
Source§

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

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

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>

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)

Remove a pane.
Source§

fn pane_clear(&mut self, id: u32)

Remove the text in a pane.
Source§

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)

Change the size of a pane. See pane::Screen::set_size.
Source§

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)

Move where text goes next in a text grid, counting from zero.
Source§

fn pane_info(&mut self, id: u32) -> Option<PaneInfo>

What a program can learn about a pane.
Source§

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>

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)

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)

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])

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>

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>

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>>

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>

The full name of a file, from a root.
Source§

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

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>

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>

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)

Clear the main console.
Source§

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)

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

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)

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)

Show text at the right of the status line, usually the score.
Source§

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>

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

A name for the system the host runs on.
Source§

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)

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 BufferHost
where *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 BufferHost

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.