diff --git a/Assets/Scripts/Player Controls/interact.gd b/Assets/Scripts/Player Controls/interact.gd index 695d622..0a69c1a 100644 --- a/Assets/Scripts/Player Controls/interact.gd +++ b/Assets/Scripts/Player Controls/interact.gd @@ -39,6 +39,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) diff --git a/Assets/Scripts/UI/terminal/terminal_controls.gd b/Assets/Scripts/UI/terminal/terminal_controls.gd index b5209ad..7d6d01d 100644 --- a/Assets/Scripts/UI/terminal/terminal_controls.gd +++ b/Assets/Scripts/UI/terminal/terminal_controls.gd @@ -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 = { @@ -63,6 +66,10 @@ func EnterCommand() -> void: if historyContainer.get_child_count() <24: CreateHistoryEntry(fullText) + + if userInput != "": + terminalHistory.append(userInput) + historyIndex = 0 match parts[0]: "ls", "list": @@ -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 + "/"