Skip to main content

Session

Struct Session 

Source
pub struct Session<'a> { /* private fields */ }
Expand description

One run of the game: the environment, the catalog, the state store and the output.

Build it with Session::new and call the method of the command. Methods print their screens to standard output and their directives to standard error (inside the game shell only) and return the exit status.

Implementations§

Source§

impl<'a> Session<'a>

Source

pub fn new(env: &'a Env, catalog: &'a Catalog) -> Self

A session for this environment. Directives are emitted only inside the game shell (Env::wrapped); the state lives in Env::state_dir.

Source

pub fn with_term(self, term: Term) -> Self

The same session writing through a different Term (a fixed width, for example).

Source

pub fn show_current_level(&mut self) -> i32

shellgame: shows the current level, creating the game on the first run. An intro is shown page by page and then submitted automatically.

Source

pub fn init(&mut self) -> i32

shellgame init: the legacy explicit initialization.

Source

pub fn status(&mut self) -> i32

shellgame status: progress and statistics.

Source

pub fn hint(&mut self, repeat: bool) -> i32

shellgame hint [--repeat]: reveals the next hint, or lists the revealed ones. Only newly revealed hints are counted.

Source

pub fn submit(&mut self, answer: Option<&str>) -> i32

shellgame submit [ANSWER]: judges the answer. A wrong one is counted and explained; a right one is recorded and the game moves on.

Source

pub fn skip(&mut self) -> i32

shellgame skip: skips a bonus level. No completion is recorded.

Source

pub fn reset(&mut self) -> i32

shellgame reset: rebuilds the current level and puts the player back at its start, wherever they wandered off to.

Source

pub fn repeat(&mut self, section: Option<u32>, level: Option<&str>) -> i32

shellgame repeat [--section N] [--level ID]: shows an assignment again (an explicit level wins over a section, and the current level is the default).

Source

pub fn show(&mut self, section: bool, level: bool) -> i32

shellgame show --section | --level: shows the intro of the current section or the current level again. Exactly one flag is required.

Source

pub fn remove(&mut self, confirmed: bool) -> i32

shellgame remove: deletes the workspace and the state, after asking unless confirmed. Inside the game shell the shell is closed afterwards. A declined confirmation exits with FAILURE, because the old wrapper closes the shell whenever remove returns 0.

Source

pub fn exit(&self) -> i32

shellgame exit: closes the game shell.

Source

pub fn dev_jump(&mut self, id: &str) -> i32

shellgame dev jump ID: prepares and shows any level. Its progress is cleared, so a level can be replayed from scratch.

Source

pub fn dev_next(&mut self) -> i32

shellgame dev next: jumps to the level after the current one.

Source

pub fn dev_prev(&mut self) -> i32

shellgame dev prev: jumps to the level before the current one.

Source

pub fn dev_reload(&mut self) -> i32

shellgame dev reload: rebuilds the current level and shows it again.

Source

pub fn dev_start(&mut self) -> i32

shellgame dev start: jumps to the first level.

Source

pub fn cd_pre(&self, pwd: &Path, prev: &Path, cd_args: &[OsString]) -> i32

cd-hook pre <pwd> <prev> -- <cd args...>: may the player cd? BLOCKED if not.

pwd is the shell’s directory before the move and prev the directory cd - would go to (empty when unknown); a relative or empty value counts as unknown.

Source

pub fn cd_post(&self, old: &Path, new: &Path, cd_args: &[OsString]) -> i32

cd-hook post <old pwd> <new pwd> -- <cd args...>: the move happened; records evidence. Silent, and ignored when the new directory is not an absolute path.

Source

pub fn legacy_cd_pre(&self, target: Option<&OsStr>, pwd: Option<&OsStr>) -> i32

Legacy cd-hook [TARGET] [PWD] of a game shell started by the Python version: the move is reported only before it happens. A block exits with FAILURE, because the old wrapper treats every non-zero status as “blocked”.

Source

pub fn legacy_cd_post(&self, pwd: Option<&OsStr>) -> i32

Legacy cd-hook --post-move [PWD]: the move happened and pwd is where the shell is now.

Source

pub fn fd_hook(&self) -> i32

fd-hook: runs inside a redirected command and looks at where its own stdout and stderr point. Silent.

Source

pub fn update(&self) -> i32

shellgame update: replaces this binary with the latest release (see update).

Trait Implementations§

Source§

impl<'a> Debug for Session<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Session<'a>

§

impl<'a> RefUnwindSafe for Session<'a>

§

impl<'a> Send for Session<'a>

§

impl<'a> Sync for Session<'a>

§

impl<'a> Unpin for Session<'a>

§

impl<'a> UnsafeUnpin for Session<'a>

§

impl<'a> UnwindSafe for Session<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.