you can cycle through your command history
This commit is contained in:
@@ -40,6 +40,12 @@ func _input(event: InputEvent) -> void:
|
||||
KEY_ENTER:
|
||||
terminal.EnterCommand()
|
||||
|
||||
KEY_UP:
|
||||
terminal.NavigateHistory(1)
|
||||
|
||||
KEY_DOWN:
|
||||
terminal.NavigateHistory(-1)
|
||||
|
||||
if event.unicode > 31:
|
||||
var character = char(event.unicode)
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ class_name TerminalControls
|
||||
@onready var scroll: ScrollContainer = $MarginContainer/ScrollContainer
|
||||
@export var terminalLine: RichTextLabel
|
||||
|
||||
var terminalHistory: Array[String] = []
|
||||
var historyIndex: int = -1
|
||||
|
||||
var command: String
|
||||
var directory: String = "~/"
|
||||
var fileSystem: Dictionary = {
|
||||
@@ -64,6 +67,10 @@ func EnterCommand() -> void:
|
||||
if historyContainer.get_child_count() <24:
|
||||
CreateHistoryEntry(fullText)
|
||||
|
||||
if userInput != "":
|
||||
terminalHistory.append(userInput)
|
||||
historyIndex = 0
|
||||
|
||||
match parts[0]:
|
||||
"ls", "list":
|
||||
var currentDirData
|
||||
@@ -117,6 +124,19 @@ func EnterCommand() -> void:
|
||||
GetBottomScroll()
|
||||
|
||||
# --- History and FileSystem Helpers ---
|
||||
|
||||
func NavigateHistory(direction: int):
|
||||
if terminalHistory.is_empty():
|
||||
return
|
||||
|
||||
historyIndex += direction
|
||||
historyIndex = clamp(historyIndex, 0, terminalHistory.size() - 1)
|
||||
|
||||
var historyCommand = terminalHistory[historyIndex]
|
||||
|
||||
terminalLine.text = "user@work "+ directory + " " + historyCommand
|
||||
UpdateCaretPos()
|
||||
|
||||
func CreateHistoryEntry(content: String) -> void:
|
||||
|
||||
var rtl = RichTextLabel.new()
|
||||
@@ -130,6 +150,9 @@ func CreateHistoryEntry(content: String) -> void:
|
||||
historyContainer.add_child(rtl)
|
||||
historyContainer.move_child(rtl, historyContainer.get_child_count() - 2)
|
||||
|
||||
|
||||
|
||||
|
||||
func ResolvePath(current: String, target: String) -> String:
|
||||
if target.begins_with("~/"):
|
||||
return target if target.ends_with("/") else target + "/"
|
||||
|
||||
Reference in New Issue
Block a user