Replicating Command Promt UI

Godot Version

4.6.2

Question

Hi! I am trying to replicate, with a TextEdit, the UI of The Windows PowerShell, or the command prompt. Here is the list of things It must do:

  • Block the moving of the caret
  • Block backspaces after a certain point in the line

I have been able to stop the moving of the caret, but it may be inefficient

var caret_actions = [
	"ui_text_caret_left",
	"ui_text_caret_right",
	"ui_text_caret_up",
	"ui_text_caret_down",
	"ui_text_caret_word_left",
	"ui_text_caret_word_right",
	"ui_text_caret_line_start",
	"ui_text_caret_line_end",
	"ui_text_caret_page_up",
	"ui_text_caret_page_down",
	"ui_text_caret_document_start",
	"ui_text_caret_document_end"
]

func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton or event is InputEventMouseMotion:
		get_viewport().set_input_as_handled()
	elif event is InputEventKey:
			for action in caret_actions:
				if event.is_action_pressed(action) or event.is_action_released(action):
					get_viewport().set_input_as_handled()
					break

How can I stop backspaces after a certain point, and if possible, how would I make the caret movement blocker, better.

Implement TextEdit’s _handle_unicode_input() and _backspace()