Input & Ask
:input reads a line from stdin and returns it as a string. :ask is an alias — they are identical1.
Overview
:input takes an optional prompt string. It prints the prompt without a newline, waits for the user to type a line, and returns the input with the trailing newline stripped.
Try this in the REPL:
gbln(1): name | :input("What is your name? ") What is your name? Daniel gbln(2): name Daniel gbln(3): :say "Hello, {name}!" Hello, Daniel!
gbln(1): name | :input("What is your name? ") What is your name? Daniel gbln(2): name Daniel gbln(3): :say "Hello, {name}!" Hello, Daniel!
Basic Usage
With a prompt
name | :input("What is your name? ") :say "Hello, {name}!"
name | :input("What is your name? ") :say "Hello, {name}!"
Without a prompt
line | :input()
line | :input()
Using the ask alias
name | :ask("What is your name? ")
name | :ask("What is your name? ")
Return Value
:input always returns a string. The trailing newline is stripped automatically. If the user presses Enter without typing anything, it returns an empty string "".
answer | :input("Continue? (y/n) ") if answer == "y" :say "Continuing..." xx
answer | :input("Continue? (y/n) ") if answer == "y" :say "Continuing..." xx
Non-Interactive Mode
:input and :ask raise a runtime error when called in non-interactive mode (when GOBLIN_NONINTERACTIVE=1 is set). This is always the case when a Goblin script is invoked by the Sheriff host.
error: R0505: non-interactive: interactive input is disabled in non-interactive mode
error: R0505: non-interactive: interactive input is disabled in non-interactive mode
Do not use :input or :ask in Sheriff build scripts or API handlers. Use :env to read data passed by the host instead.
Errors
Passing a non-string prompt raises a type error:
:input(42) /// error: T0205 type-mismatch: input/ask expects the prompt to be a string
:input(42) /// error: T0205 type-mismatch: input/ask expects the prompt to be a string
If stdin is unavailable or closed, a runtime I/O error is raised:
error: R0501: io-error: failed to read from stdin
error: R0501: io-error: failed to read from stdin
-
:askand:inputare registered to the same handler in the Goblin runtime. There is no behavioral difference. Use whichever reads more naturally in context. ↩