10 The Prompt

10.1 The default prompt

By default the poke prompt shows the following information:

(flags:endianness:ios)

Where flags is a set of letters denoting certain settings are switched on:

p

Pretty printing is switched on.

0
x
o
2

Output base is decimal, hexadecimal octal or binary respectively.

endianness denotes the currently enabled byte endianness, big for big-endian and little for little-endian.

ios is either the handler of the currently selected IO space, or poke if no IO space is opened.

This is an example of a typical prompt:

(p0:big:/bin/ls) _

Which tells us that pretty-printing is switched on (the p flag), that the output mode is base 10 (the 0 flag), that the current endianness is big endian, and that we are currently editing /bin/ls.

Note that if poke has been set to be in “quiet” mode (like when using the --quiet command line option, or by setting pk_u then a very simple prompt will be used:

(poke) _

10.2 Simple customization of the prompt

The information shown by the prompt can be changed at any time by simply setting the values of a few variables, all of which are booleans:

pk_prompt_show_ios

Whether the currently selected IO space should be shown in the prompt. Defaults to 1.

pk_prompt_show_endian

Whether the current endianness should be shown in the prompt. Defaults to 1.

pk_prompt_show_pp

Whether a p flag should be shown in the prompt when pretty printing is enabled. Defaults to 1.

pk_prompt_show_obase

Whether a flag should be shown in the prompt indicating the currently selected output numeration base. Defaults to 1.

pk_prompt_comment

Whether the prompt shall use #! and !# delimiters instead of ( and ). This makes the prompt a comment in Poke and therefore makes it easier to copy code from interactive sessions and evaluate it as code. Defaults to 0.

You can customize your poke by setting these variables in your .pokerc file, or at any time by setting the values of the variables in the prompt:

(poke) pk_prompt_comment = 1
#!poke!# _

10.3 Advanced customization of the prompt

Is possible to further customize the prompt by defining a function called pk_prompt, that gets no arguments and returns a string. poke invokes that function every time it needs to print the prompt; the default version of the function implements what has been described in the previous section.

This is an example of customization of a simple prompt that included the current IO space but little else:

fun pk_prompt = string:
{
  var prompt = pk_prompt_comment ? "#!" : "(";

  try
    prompt += iohandler (get_ios);
  catch if E_no_ios
    {
      prompt += "poke";
    };

  return prompt + (pk_prompt_comment ? "#!" : ") ");
}

Once the function above gets defined, the prompt will reflect both the current endianness and the currently selected IO space, if there is any:

(big:poke) .file /bin/ls
(big:/bin/ls)

If you write your own pk_prompt and share it with other people, it is a good practice to acknowledge pk_prompt_comment.