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>
impl<'a> Session<'a>
Sourcepub fn new(env: &'a Env, catalog: &'a Catalog) -> Self
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.
Sourcepub fn with_term(self, term: Term) -> Self
pub fn with_term(self, term: Term) -> Self
The same session writing through a different Term (a fixed width, for example).
Sourcepub fn show_current_level(&mut self) -> i32
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.
Sourcepub fn hint(&mut self, repeat: bool) -> i32
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.
Sourcepub fn submit(&mut self, answer: Option<&str>) -> i32
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.
Sourcepub fn reset(&mut self) -> i32
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.
Sourcepub fn repeat(&mut self, section: Option<u32>, level: Option<&str>) -> i32
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).
Sourcepub fn show(&mut self, section: bool, level: bool) -> i32
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.
Sourcepub fn remove(&mut self, confirmed: bool) -> i32
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.
Sourcepub fn dev_jump(&mut self, id: &str) -> i32
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.
Sourcepub fn dev_next(&mut self) -> i32
pub fn dev_next(&mut self) -> i32
shellgame dev next: jumps to the level after the current one.
Sourcepub fn dev_prev(&mut self) -> i32
pub fn dev_prev(&mut self) -> i32
shellgame dev prev: jumps to the level before the current one.
Sourcepub fn dev_reload(&mut self) -> i32
pub fn dev_reload(&mut self) -> i32
shellgame dev reload: rebuilds the current level and shows it again.
Sourcepub fn cd_pre(&self, pwd: &Path, prev: &Path, cd_args: &[OsString]) -> i32
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.
Sourcepub fn cd_post(&self, old: &Path, new: &Path, cd_args: &[OsString]) -> i32
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.
Sourcepub fn legacy_cd_pre(&self, target: Option<&OsStr>, pwd: Option<&OsStr>) -> i32
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”.
Sourcepub fn legacy_cd_post(&self, pwd: Option<&OsStr>) -> i32
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.