The chatbox panel (fl_chat_panel): a scrolling history of message panels above a text entry. While it is closed only recent messages are visible until they fade out. While it is open the whole history is shown and the text entry takes the input, with a history of earlier entries on the up and down keys. While a command is typed, the suggestions of Flux.Command:complete for the text up to the caret are listed above the entry along with the name, syntax and description of the command: Tab puts the selected suggestion in place of the word that is typed, and pressing it again replaces that with the next suggestion (Shift+Tab goes back); the up and down keys move the selection while there are suggestions. Enter sends the text as it is typed. The state of the suggestions is kept on the panel for themes that draw them through the ChatboxPaintOver hook: completion (the result of Flux.Command:complete, nil while no command is typed), completion_index (the selected suggestion), completion_offset (how many suggestions are scrolled past) and completion_prefix (the command prefix that was typed). Chatbox.create creates the panel and keeps it in Chatbox.panel.

Summary

Methods

Creates a panel for the message and adds it to the chatbox, unless the ChatboxShouldAddMessage hook returns false.
Appends a message panel to the history and to the scroll panel.
Compiles the message and creates a message panel for it, without adding it to the chatbox.
Draws the card about a command that PANEL:layout_command_info laid out.
Draws the suggestions above the text entry: the list of suggestions right above it, with the selected one highlighted and scrolled into view and the command a suggested alias stands for noted after it, and a card about a command above the list.
Init()client
Creates the scroll panel for the messages and the text entry with its input history, then lays the chatbox out.
Puts a suggestion in place of the word at the caret, with the caret moved behind it.
Lays out the card about a command for PANEL:draw_completion: its full name, its syntax after the name or on a line of its own if it does not fit there, its description wrapped to the width and its aliases.
Moves the selection through the suggestions, wrapping around at both ends.
Draws the background through the ChatboxPaintBackground theme hook while the chatbox is open.
Draws the suggestions for the command that is being typed above the text entry, see PANEL:draw_completion.
rebuild()client
Applies the size and position of the chatbox, lays out the text entry and the scroll panel, and repositions all messages.
Drops removed panels from the message history, updates the indexes of the remaining messages and rebuilds the layout.
Removes the message from the history and rebuilds the history indexes.
Forgets the suggestions, so that they are worked out again for the text entry.
Opens or closes the chatbox: toggles the focus and the text entry, and makes all messages visible while the chatbox is open.
Think()client
Closes the chatbox when escape is pressed and keeps the suggestions up to date with the text entry while it is open.
Checks whether the text entry contains a command.
Works out the suggestions for the command in the text entry with Flux.Command:complete, for the text between the command prefix and the caret.

Methods

PANEL:add_message(message_data)

client plugins/chatbox/plugin/views/cl_chatbox.lua:782

Creates a panel for the message and adds it to the chatbox, unless the ChatboxShouldAddMessage hook returns false.

Parameters

  • message_data Map message data received from the server

PANEL:add_panel(panel)

client plugins/chatbox/plugin/views/cl_chatbox.lua:828

Appends a message panel to the history and to the scroll panel. Ejects the oldest message first if the 'max_messages' limit has been reached.

Parameters

  • panel Panel a fl_chat_message panel

PANEL:create_message(message_data)

client plugins/chatbox/plugin/views/cl_chatbox.lua:762

Compiles the message and creates a message panel for it, without adding it to the chatbox.

Parameters

  • message_data Map message data received from the server

Returns

  • Panel the fl_chat_message panel, or nil if the message could not be compiled

PANEL:draw_command_info(info, y, width, padding)

client plugins/chatbox/plugin/views/cl_chatbox.lua:546

Draws the card about a command that PANEL:layout_command_info laid out.

Parameters

  • info Map the layout
  • y Number top edge of the card
  • width Number width of the card
  • padding Number space between the edges of the card and the text

PANEL:draw_completion(width, bottom)

client plugins/chatbox/plugin/views/cl_chatbox.lua:614

Draws the suggestions above the text entry: the list of suggestions right above it, with the selected one highlighted and scrolled into view and the command a suggested alias stands for noted after it, and a card about a command above the list. The card is about the selected suggestion if that is a command or subcommand, else about the command that has been typed, with the argument that is being typed emphasized in its syntax. Shows that no commands were found if nothing fits.

Parameters

  • width Number width of the area to draw in
  • bottom Number bottom edge of the area to draw in; its top edge is 0

Creates the scroll panel for the messages and the text entry with its input history, then lays the chatbox out.

PANEL:insert_completion(step)

client plugins/chatbox/plugin/views/cl_chatbox.lua:416

Puts a suggestion in place of the word at the caret, with the caret moved behind it. The first press puts the selected suggestion in. While the text and the caret stay as that left them, every further press replaces it with the next suggestion, or the previous one for a negative step, applied to the text from before the first press. After the only suggestion has been put in, the next press goes on to the word after it.

Parameters

  • step Number 1 for the next suggestion, -1 for the previous one

Returns

  • Boolean true if a suggestion was put in, nil if there is none

PANEL:layout_command_info(cmd, result, width)

client plugins/chatbox/plugin/views/cl_chatbox.lua:492

Lays out the card about a command for PANEL:draw_completion: its full name, its syntax after the name or on a line of its own if it does not fit there, its description wrapped to the width and its aliases. The layout is kept until the command, its syntax, the emphasized argument or the width change.

Parameters

  • cmd Command the command or subcommand
  • result Map the completion result whose typed argument is emphasized in the syntax, nil to emphasize none
  • width Number width the text may take

Returns

  • Map the layout: name, segments, emphasis, inline, lines, aliases and height

PANEL:move_completion(step)

client plugins/chatbox/plugin/views/cl_chatbox.lua:469

Moves the selection through the suggestions, wrapping around at both ends. While Tab cycles through the suggestions, the newly selected one is put in as Tab does.

Parameters

  • step Number 1 to move down the list, -1 to move up

Returns

  • Boolean true if there were suggestions to move through, nil otherwise

Draws the background through the ChatboxPaintBackground theme hook while the chatbox is open.

Parameters

  • w Number
  • h Number

PANEL:PaintOver(width, height)

client plugins/chatbox/plugin/views/cl_chatbox.lua:332

Draws the suggestions for the command that is being typed above the text entry, see PANEL:draw_completion. The ChatboxPaintOver theme hook can override this.

Parameters

  • width Number
  • height Number

Applies the size and position of the chatbox, lays out the text entry and the scroll panel, and repositions all messages.

PANEL:rebuild_history_indexes()

client plugins/chatbox/plugin/views/cl_chatbox.lua:809

Drops removed panels from the message history, updates the indexes of the remaining messages and rebuilds the layout.

PANEL:remove_message(idx)

client plugins/chatbox/plugin/views/cl_chatbox.lua:855

Removes the message from the history and rebuilds the history indexes. Does not remove the panel of the message.

Parameters

  • idx Number index of the message in the history

PANEL:reset_completion()

client plugins/chatbox/plugin/views/cl_chatbox.lua:340

Forgets the suggestions, so that they are worked out again for the text entry.

PANEL:set_open(is_open)

client plugins/chatbox/plugin/views/cl_chatbox.lua:717

Opens or closes the chatbox: toggles the focus and the text entry, and makes all messages visible while the chatbox is open.

Parameters

  • is_open Boolean

Closes the chatbox when escape is pressed and keeps the suggestions up to date with the text entry while it is open. Keeps the messages scrolled to the bottom while the chatbox is closed.

PANEL:typing_command()

client plugins/chatbox/plugin/views/cl_chatbox.lua:748

Checks whether the text entry contains a command.

Returns

  • Boolean whether a command is being typed; nil if the entry only contains '/' or is not valid
  • Number length of the command prefix if a command is being typed

PANEL:update_completion()

client plugins/chatbox/plugin/views/cl_chatbox.lua:354

Works out the suggestions for the command in the text entry with Flux.Command:complete, for the text between the command prefix and the caret. They are worked out again only once the text or the caret has moved, and stay the ones that are cycled through while Tab cycles through them. The first suggestion is selected whenever the suggestions change.

Returns

  • Map the completion result, or nil if no command is being typed

Defined in