Skip to content

Allow server to control chat input prompt #16788

@yl-whosit

Description

@yl-whosit

Problem

When player types a message into chat/console window, server is free to handle it in any way using callbacks registered with core.register_on_chat_message(). Some mods implement additional features, like chat channels (see Smart Chat, Beerchat, etc). You can also imagine a mod temporary switching player into a "REPL-mode" of some sort, where all typed messages are interpreted as commands, instead of being sent to chat. This means that in general, when user types a message, it can be interpreted differently depending on some "state" or "mode" the player is currently in (current channel, current repl, etc).

To display the current state of chat, luanti could allow mods to change the chat input prompt. Currently, it's just displaying ] always. But for servers using chat mods, it would be nice if it displayed current channel, like #main] or whatever is needed for user to understand better what will happen when they press enter and send the message.

Solutions

The simplest way is to just provide a couple of API functions, like:

  • core.set_player_chat_prompt(player, prompt_string) - changes the prompt to prompt_string for specific player.
  • core.get_player_chat_prompt(player) - returns previously set string (technically not required to function, assuming only one mod changes prompt). Server would store current prompt only until player leaves, setting a default prompt on join.

Additional stuff:

  • core.set_default_chat_prompt(prompt_string) - (also optional, depends on implementation, can simplify doing core.register_on_joinplayer() in some cases?)

Based on these functions, some mod could provide an API for multiple mods to combine prompts into something sensible, if needed.

Alternatives

Alternative is to make this part of client-side API, and changeable with client-side (server-sent) mods.
This is more sensible, but server-side implementation is simpler? :p

Additional context

How a mod for modular prompt could work? I'm not sure if there's a good pattern to use to prevent multiple mods from clobbering each others prompts, so I guess it's on mod developers to come up with some sensible way for multiple mods to interact here (hopefully anyway :p).

There's no official way to dynamically control registered_on_chat_messages callbacks either, so engine can't really do much here?

Just as an example of a mod that can manage modular prompts, I came up with a way that copies how some /etc configurations work: prompt can be concatenated from a table of string values sorted in lexicographical order:

local prompt = {
  ['00_prefix'] = "|",
  ['01_some_mod_stuff'] = "+",
  ['50_middle'] = "#main",
  ['99_suffix'] = "> ",
} -- gives "|+#main>", just as example...

In a simple case, this would allow multiple mods to manage their own parts without clobbering each other. Still, if one mod completely grabs the input (like REPL example) this won't help much...

Such mod could also implement some kind of special characters that get replaced with other info, (similar to how shell prompt can display current user/directory etc. Not sure engine could provide anything useful here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    @ Script APIFeature requestIssues that request the addition or enhancement of a feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions