-- Compiled with roblox-ts v3.0.0 local TS = _G[script] local UserInputService = TS.import(script, TS.getModule(script, "@rbxts", "services")).UserInputService local _vide = TS.import(script, TS.getModule(script, "@rbxts", "vide").src) local Vide = _vide local effect = _vide.effect local source = _vide.source local useClient = TS.import(script, script.Parent.Parent.Parent.Parent, "hooks", "use-client").useClient local useEvent = TS.import(script, script.Parent.Parent.Parent.Parent, "hooks", "use-event").useEvent local px = TS.import(script, script.Parent.Parent.Parent.Parent, "hooks", "use-px").px local _store = TS.import(script, script.Parent.Parent.Parent.Parent, "store") local currentCommandPath = _store.currentCommandPath local currentSuggestion = _store.currentSuggestion local options = _store.options local terminalTextValid = _store.terminalTextValid local visible = _store.visible local Frame = TS.import(script, script.Parent.Parent.Parent, "ui", "frame").Frame local Padding = TS.import(script, script.Parent.Parent.Parent, "ui", "padding").Padding local Text = TS.import(script, script.Parent.Parent.Parent, "ui", "text").Text local TextField = TS.import(script, script.Parent.Parent.Parent, "ui", "text-field").TextField local _suggestion = TS.import(script, script.Parent, "suggestion") local completeArgument = _suggestion.completeArgument local completeCommand = _suggestion.completeCommand local getSuggestedText = _suggestion.getSuggestedText local TEXT_SIZE = 22 local function TerminalTextField(_param) local anchor = _param.anchor local size = _param.size local position = _param.position local backgroundTransparency = _param.backgroundTransparency local onTextChange = _param.onTextChange local onSubmit = _param.onSubmit local textParts = _param.textParts local atNextPart = _param.atNextPart local client = useClient() local ref = source() local commandHistory = source({}) local commandHistoryIndex = source(nil) local suggestionText = source("") local currentTextValue = "" local onScreenKeyboard = false -- Focus text field when terminal becomes visible effect(function() if visible() then local _result = ref() if _result ~= nil then _result:CaptureFocus() end else local _result = ref() if _result ~= nil then _result:ReleaseFocus() end end end) local setText = function(text) local textBox = ref() if textBox == nil then return nil end textBox.Text = text textBox.CursorPosition = #text + 1 end local traverseHistory = function(up) local history = commandHistory() if #history == 0 then return nil end local historyIndex = commandHistoryIndex() if not up and historyIndex == nil then return nil end local textBox = ref() if textBox == nil then return nil end local lastIndex = #history - 1 if not up and historyIndex == lastIndex then setText("") commandHistoryIndex(nil) return nil end local _condition = historyIndex if _condition == nil then _condition = #history end local newIndex = math.clamp(_condition + (if up then -1 else 1), 0, lastIndex) setText(history[newIndex + 1]) commandHistoryIndex(newIndex) end effect(function() local _exp = client.registry local _result = ref() if _result ~= nil then _result = _result.Text end local _condition = _result if _condition == nil then _condition = "" end suggestionText(getSuggestedText(_exp, _condition, textParts(), atNextPart(), currentSuggestion())) end) useEvent(UserInputService.InputBegan, function(input) local textBox = ref() local _condition = textBox == nil if not _condition then local _result = textBox if _result ~= nil then _result = _result:IsFocused() end _condition = not _result end if _condition then return nil end -- Handle history traversal if input.KeyCode == Enum.KeyCode.Up then traverseHistory(true) elseif input.KeyCode == Enum.KeyCode.Down then traverseHistory(false) end if input.KeyCode ~= Enum.KeyCode.Tab then return nil end -- Handle autocompletion local commandPath = currentCommandPath() local suggestion = currentSuggestion() if suggestion == nil then return nil end local currentText = textBox.Text if commandPath == nil then setText(completeCommand(client.registry, textBox.Text, textParts(), suggestion.title)) return nil end local _result = client.registry:getCommand(commandPath) if _result ~= nil then _result = _result.options.arguments if _result ~= nil then _result = #_result end end local _condition_1 = _result if _condition_1 == nil then _condition_1 = 0 end local argCount = _condition_1 if suggestion.type == "command" and argCount ~= 0 then setText(`{currentText} `) return nil end if #suggestion.others == 0 then setText(currentText) return nil end setText(completeArgument(currentText, suggestion.others[1], argCount)) end) return Vide.jsx(Frame, { anchor = anchor, size = size, position = position, backgroundColor = function() return options().palette.surface end, backgroundTransparency = backgroundTransparency, cornerRadius = function() return UDim.new(0, px(4)) end, }, Vide.jsx(Padding, { all = function() return UDim.new(0, px(8)) end, }), Vide.jsx(TextField, { action = ref, size = UDim2.fromScale(1, 1), textSize = function() return px(TEXT_SIZE) end, textColor = function() return if terminalTextValid() then options().palette.success else options().palette.error end, textXAlignment = "Left", placeholderText = "Enter command...", placeholderColor = function() return options().palette.subtext end, font = function() return options().font.medium end, clearTextOnFocus = false, native = { FocusLost = function(enterPressed) if not enterPressed then return nil end local textBox = ref() if textBox == nil then return nil end local currentText = textBox.Text local history = commandHistory() if currentText ~= "" and (#history == 0 or history[#history] ~= currentText) then local _array = {} local _length = #_array local _historyLength = #history table.move(history, 1, _historyLength, _length + 1, _array) _length += _historyLength _array[_length + 1] = textBox.Text commandHistory(_array) end commandHistoryIndex(nil) local _result = onSubmit if _result ~= nil then _result(currentText) end textBox.Text = "" if not onScreenKeyboard then textBox:CaptureFocus() end onScreenKeyboard = false end, TextChanged = function(currentText) local textBox = ref() if textBox == nil then return nil end local historyIndex = commandHistoryIndex() if historyIndex ~= nil and currentText ~= commandHistory()[historyIndex + 1] then commandHistoryIndex(nil) end -- Remove line breaks local value = currentText if (string.match(value, "[\n\r]")) ~= nil then value = (string.gsub(value, "[\n\r]", "")) end -- Remove all tabs from text input - we use these for autocompletion if (string.match(value, "\t")) ~= nil then value = (string.gsub(value, "\t", "")) end textBox.Text = value if currentTextValue == value then return nil end currentTextValue = value local _result = onTextChange if _result ~= nil then _result(value) end end, ReturnPressedFromOnScreenKeyboard = function() local textBox = ref() if textBox == nil then return nil end task.wait() onScreenKeyboard = true textBox:ReleaseFocus(true) end, }, zIndex = 2, }), Vide.jsx(Text, { size = UDim2.fromScale(1, 1), text = suggestionText, textColor = function() return options().palette.subtext end, textSize = function() return px(TEXT_SIZE) end, textXAlignment = "Left", font = function() return options().font.medium end, })) end return { TerminalTextField = TerminalTextField, }