mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Added support for Console auto-complete
This commit is contained in:
@@ -86,6 +86,24 @@ class IMICFPS
|
||||
@text_input.text = @command_history[@command_history_index]
|
||||
end
|
||||
|
||||
when Gosu::KbTab
|
||||
split = @text_input.text.split(" ")
|
||||
|
||||
if !@text_input.text.end_with?(" ") && split.size == 1
|
||||
list = command_search(@text_input.text)
|
||||
|
||||
if list.size == 1
|
||||
@text_input.text = "#{list.first} "
|
||||
else
|
||||
@history.text += "\n#{list.map { |cmd| Commands::Style.highlight(cmd)}.join(", ")}"
|
||||
update_history
|
||||
end
|
||||
else
|
||||
if split.size > 0 && cmd = Commands::Command.find(split.first)
|
||||
cmd.autocomplete(self)
|
||||
end
|
||||
end
|
||||
|
||||
when Gosu::KbBacktick
|
||||
# Removed backtick character from input
|
||||
if @text_input.text.size > 1
|
||||
@@ -112,6 +130,21 @@ class IMICFPS
|
||||
IMICFPS::Commands::Command.use(command, arguments, self)
|
||||
end
|
||||
|
||||
def command_search(text)
|
||||
return [] unless text.length > 0
|
||||
|
||||
@command_search ||= Abbrev.abbrev(Commands::Command.list_commands.map { |cmd| cmd.command.to_s})
|
||||
|
||||
list = []
|
||||
@command_search.each do |abbrev, value|
|
||||
next unless abbrev && abbrev.start_with?(text)
|
||||
|
||||
list << value
|
||||
end
|
||||
|
||||
return list.uniq
|
||||
end
|
||||
|
||||
def stdin(string)
|
||||
@history.text += "\n#{string}"
|
||||
update_history
|
||||
|
||||
Reference in New Issue
Block a user