Interactive REPL

Interactive REPL sessions

Nift vaporwave artwork

There are two modes in which you can run an interactive REPL session with Nift, interpreter mode interp and shell mode sh. The only difference between the two modes is that interpreter mode just has the language in the prompt, whereas shell mode has both the language and the present working directory in the prompt.

[contents]

Contents

Interpreter mode

An interpreter REPL session can be started with either of:

nsm interp -lang
nift interp -lang

Note: f++ is the default language used when no language option is specified.

In the interpreter mode the prompt will just tell you which language you are using. If you would like the prompt to also display the present working directory (up to using half the width of the console) you can switch to shell mode using nsm_mode("sh"). You can switch back again with nsm_mode("interp").

Shell mode

A shell REPL session can be started with either of:

nsm sh -lang
nift sh -lang

Note: f++ is the default language used when no language option is specified.

The f++ shell attempts to work as an extension of the shell it is running from, ie. attempts to work almost identically to the shell it is running from while having a number of additional features (and can often do many things faster than the shell it is running from).

In the shell mode the prompt will tell you which language you are using and the present working directory (up to using half the width of the console). If you would like the prompt to just display the language you can switch to interpreter mode using nsm_mode("interp"). You can switch back again with nsm_mode("sh").

Languages

The following language options are available:

  • exprtk
  • f++ (default)
  • lua
  • n++

You can switch to one of the other languages available during an interactive REPL session using nsm_lang(langStr) where langStr is one of f++, n++, lua or exprtk.

Multi-line input

The are various ways to achieve multi-line input during an interactive REPL session, when reading additional lines of input before parsing the end of the prompt changes to > instead of its normal $. The following table lists the shortcuts on different platforms to input another line before parsing (including ending a line with \):

FreeBSD Linux OSX Windows
alt enter
ctrl r
\ enter
alt enter
ctrl r
\ enter
ctrl r
\ enter
ctrl enter
ctrl r
\ enter
FreeBSD Linux OSX Windows

Note: An interactive REPL session will continue to input lines before parsing until the input to be parsed has an equal number of open and close brackets. To override this put an = at the end of an input line with no whitespace following. A couple of f++ examples follow:

int x=10
if(x == 10) {
	console("code-blocks in interactive REPL sessions")
}

console("example with ( and { not closed") =

Shortcuts

The following shortcuts are available during interactive REPL sessions:

Description FreeBSD Linux OSX Windows
go to start of line ctrl a ctrl a ctrl a ctrl a
go to end of line ctrl e ctrl e ctrl e ctrl e
move cursor forwards one position
ctrl f

ctrl f

ctrl f

ctrl f
move cursor backwards one position
ctrl b

ctrl b

ctrl b

ctrl b
move cursor forwards to next space alt f alt →
alt f
ctrl →
alt → ctrl →
move cursor backwards to previous space alt b alt ←
alt b
ctrl ←
alt ← ctrl ←
delete from cursor to end of line ctrl d ctrl d ctrl d ctrl d
delete from cursor to start of previous word ctrl delete
ctrl shift -
ctrl -
ctrl delete
ctrl shift -
ctrl shift -
ctrl -
ctrl delete
ctrl [
delete from cursor to start of next word ctrl ] ctrl ] ctrl ] ctrl ]
line break (input another line before parsing) alt enter
ctrl r
\ enter
alt enter
ctrl r
\ enter
ctrl r
\ enter
ctrl enter
ctrl r
\ enter
Description FreeBSD Linux OSX Windows

Sponsors