Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Control
- @export var is_active = true # Set this to true if you want to show the terminal by default
- var command_history = []
- var current_input = ""
- var max_lines = 50 # Max number of lines to display
- @onready var output_box = $OutputText
- @onready var input_box = $InputText
- func _ready():
- hide() # Hide the terminal by default
- input_box.connect("text_entered", Callable(self, "_on_input_entered"))
- if is_active:
- show()
- func _process(_delta):
- # Toggle the console with the key `
- if Input.is_action_just_pressed("ui_debug_console"):
- if is_visible():
- hide()
- else:
- show()
- if Input.is_action_just_pressed("enter_key"):
- _on_input_entered(input_box.text)
- # Add a message to the debug output
- func log_message(message: String):
- command_history.append(message)
- if command_history.size() > max_lines:
- command_history.pop_front()
- _update_output()
- # Handle the input command and perform actions
- func _on_input_entered(new_command: String):
- log_message("> " + new_command) # Log the command
- input_box.text = "" # Clear input after enter
- _process_command(new_command) # Process the entered command
- # Update the output box with new log messages
- func _update_output():
- output_box.text = ""
- for line in command_history:
- output_box.text += line + "\n"
- # Example of how to process entered commands
- func _process_command(command: String):
- var args = command.split(" ")
- match args[0]:
- "print":
- if args.size() > 1:
- var message = ""
- for i in range(args.size()):
- if i > 0:
- message += " "
- message += args[i]
- log_message(message)
- "help":
- log_message("Available commands: print, help, quit")
- "quit":
- get_tree().quit()
- _:
- log_message("Unknown command: " + command)
- func _on_input_entered_pressed() -> void:
- _on_input_entered(input_box.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement