🪧Kernel Placeholders

Do you want to <placeholder>?

Kernel placeholders are text variables for any piece of text that are replaced by different elements found within the kernel. They are parsed in several different areas of the kernel, the most famous example being the MOTD and the MAL messages.

The probing takes place in the PlaceParse.ProbePlaces() function found within the KS.Misc.Probers.Placeholder namespace. The following types of text use this function to parse the placeholders:

  • MOTD and MAL messages

  • Username prompt and their derivatives for each shell

  • Password prompt and their derivatives for each shell

  • Mail progress style

  • Mail progress style (single)

  • echo command

  • Manual page information style

  • GPG prompt style

  • Custom welcome banner

  • Remote debugger message format

  • RSS feed URL prompt style

  • Manual page contents

  • Download and upload progress for network transfers

  • Progress Clock screensaver's informational text variables

These are the placeholders and what possible values are going to replace them when being parsed:

Custom placeholders

You can make your own placeholders, too, with a simple one-line function that allows you to create your custom placeholders for commands and text that use the placeholders feature, with the dynamic content represented in text that you want.

However, you need to register a placeholder before you can use it. Luckily, the registration is easy, unlike all the other components:

Somewhere in your mod code
PlaceParse.RegisterCustomPlaceholder("placeholder", (_) => "MyDynamicText");

Additionally, you can pass the first argument to the function that takes a string argument so that your placeholder behaves according to the argument provided. For example, colors are defined like this:

PlaceParse.RegisterCustomPlaceholder("colorfgtrue", (c) => new Color(c).VTSequenceForegroundTrueColor);

You can verify that your placeholder is registered by calling the below function:

Verification
bool regged = PlaceParse.IsPlaceholderRegistered("<placeholder>");
// regged should be true

If you no longer want a custom placeholder, you can remove it using the UnregisterCustomPlaceholder() function using the same placeholder name.

Please note that you need to surround your placeholder name with the < and the > marks, except for RegisterCustomPlaceholder(), so that the prober can recognize your placeholder. It throws an exception if it's not surrounded.

Last updated