# Differences

This shows you the differences between two versions of the page.

 lib:repl [2019/01/03 07:28]sprowell User data section. lib:repl [2019/01/03 07:30] (current)sprowell Both sides previous revision Previous revision 2019/01/03 07:30 sprowell 2019/01/03 07:28 sprowell User data section.2019/01/03 07:20 sprowell [Adding a New Command] 2019/01/03 07:14 sprowell old revision restored (2018/12/31 23:35)2019/01/03 06:30 sprowell [Adding Line Evaluation] 2019/01/03 06:28 sprowell [Simplest Use] 2018/12/31 23:35 reladm [Adding Line Evaluation] 2018/12/31 23:35 reladm [Simplest Use] 2018/12/31 23:31 reladm [Simplest Use] 2018/12/31 23:21 reladm [Adding Line Evaluation] 2018/12/31 22:58 reladm 2018/12/31 22:42 reladm 2018/12/31 22:04 reladm created 2019/01/03 07:30 sprowell 2019/01/03 07:28 sprowell User data section.2019/01/03 07:20 sprowell [Adding a New Command] 2019/01/03 07:14 sprowell old revision restored (2018/12/31 23:35)2019/01/03 06:30 sprowell [Adding Line Evaluation] 2019/01/03 06:28 sprowell [Simplest Use] 2018/12/31 23:35 reladm [Adding Line Evaluation] 2018/12/31 23:35 reladm [Simplest Use] 2018/12/31 23:31 reladm [Simplest Use] 2018/12/31 23:21 reladm [Adding Line Evaluation] 2018/12/31 22:58 reladm 2018/12/31 22:42 reladm 2018/12/31 22:04 reladm created Line 94: Line 94: ===== Adding a New Command ===== ===== Adding a New Command ===== - We can add a new command to the REPL using the add_command method.  We need to provide the command name, the help text, and a callback for the command.  The callback has the same form as for the evaluation method. + We can add a new command to the REPL using the ''add_command'' method.  We need to provide the command name, the help text, and a callback for the command.  The callback has the same form as for the evaluation method. - We will use our echo function for this, but we don't want to quit when the user enters quit, so we just modify the returned Boolean to always be true.  Again, we need to install this command after creating the REPL instance and before invoking run.  While we are at it, let's also install a "no-op" command that does nothing.  We could do this with a closure, as before: |_,_| (None, true), but let's use a function pointer, instead. + We will use our ''echo'' function for this, but we don't want to quit when the user enters ''quit'', so we just modify the returned Boolean to always be ''true''.  Again, we need to install this command after creating the REPL instance and before invoking ''run''.  While we are at it, let's also install a "no-op" command that does nothing.  We could do this with a closure, as before: ''|_,_| (None, true)'', but let's use a function pointer, instead. - We will also change the prompt, using set_prompt. + We will also change the prompt, using ''set_prompt''. Line 160: Line 160: ===== User Data ===== ===== User Data ===== - Our functions will probably want to do something a little more sophisticated, so let's take a look at ReplContext. We get some important things packaged in this struct. + Our functions will probably want to do something a little more sophisticated, so let's take a look at ''ReplContext''. We get some important things packaged in this struct. * The line editor (provided by the [[https://crates.io/crates/rustyline|rustyline]] crate) being used by the REPL, which gives us access to line history as well as the ability to read lines ourselves and have those lines be part of the same history. * The line editor (provided by the [[https://crates.io/crates/rustyline|rustyline]] crate) being used by the REPL, which gives us access to line history as well as the ability to read lines ourselves and have those lines be part of the same history. - * The terminal (provided by the [[https://crates.io/crates/console|console]] crate) that lets us provide consistent output, though this is not essential. + * The terminal (provided by the [[https://crates.io/crates/console|console]] crate) that lets us provide a consistent output, though this is not essential. * The current value of the "quiet" flag, that lets us decide whether we //should// provide output.  If we simply return some string, that string is always printed. * The current value of the "quiet" flag, that lets us decide whether we //should// provide output.  If we simply return some string, that string is always printed. * Some user data, which can hold anything we want. * Some user data, which can hold anything we want.