|
|
@@ -1,4 +1,5 @@
|
|
|
#include "lumacs/keybinding.hpp"
|
|
|
+#include "lumacs/command_system.hpp" // Include for CommandSystem
|
|
|
#include <sstream>
|
|
|
#include <algorithm>
|
|
|
#include <cctype>
|
|
|
@@ -150,32 +151,32 @@ bool KeySequence::operator<(const KeySequence& other) const {
|
|
|
// KeyBinding Implementation
|
|
|
// ============================================================================
|
|
|
|
|
|
-KeyBinding::KeyBinding(const KeySequence& seq, KeyBindingFunction func, std::string desc)
|
|
|
- : sequence(seq), function(std::move(func)), description(std::move(desc)) {
|
|
|
+KeyBinding::KeyBinding(const KeySequence& seq, std::string cmd_name, std::string desc)
|
|
|
+ : sequence(seq), command_name(std::move(cmd_name)), description(std::move(desc)) {
|
|
|
}
|
|
|
|
|
|
-KeyBinding::KeyBinding(const std::string& key_str, KeyBindingFunction func, std::string desc)
|
|
|
- : sequence(key_str), function(std::move(func)), description(std::move(desc)) {
|
|
|
+KeyBinding::KeyBinding(const std::string& key_str, std::string cmd_name, std::string desc)
|
|
|
+ : sequence(key_str), command_name(std::move(cmd_name)), description(std::move(desc)) {
|
|
|
}
|
|
|
|
|
|
// ============================================================================
|
|
|
// KeyBindingManager Implementation
|
|
|
// ============================================================================
|
|
|
|
|
|
-KeyBindingManager::KeyBindingManager()
|
|
|
- : sequence_timeout_(std::chrono::milliseconds(1000)) {
|
|
|
+KeyBindingManager::KeyBindingManager(CommandSystem* command_system)
|
|
|
+ : sequence_timeout_(std::chrono::milliseconds(1000)), command_system_(command_system) {
|
|
|
}
|
|
|
|
|
|
-void KeyBindingManager::bind(const KeySequence& sequence, KeyBindingFunction function, const std::string& description) {
|
|
|
- if (sequence.empty() || !function) {
|
|
|
+void KeyBindingManager::bind(const KeySequence& sequence, std::string cmd_name, const std::string& description) {
|
|
|
+ if (sequence.empty() || cmd_name.empty()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- bindings_[sequence] = KeyBinding(sequence, std::move(function), description);
|
|
|
+ bindings_[sequence] = KeyBinding(sequence, std::move(cmd_name), description);
|
|
|
}
|
|
|
|
|
|
-void KeyBindingManager::bind(const std::string& key_str, KeyBindingFunction function, const std::string& description) {
|
|
|
- bind(KeySequence(key_str), std::move(function), description);
|
|
|
+void KeyBindingManager::bind(const std::string& key_str, std::string cmd_name, const std::string& description) {
|
|
|
+ bind(KeySequence(key_str), std::move(cmd_name), description);
|
|
|
}
|
|
|
|
|
|
void KeyBindingManager::unbind(const KeySequence& sequence) {
|
|
|
@@ -206,8 +207,13 @@ KeyResult KeyBindingManager::process_key(const Key& key) {
|
|
|
clear_partial_sequence();
|
|
|
|
|
|
try {
|
|
|
- bool success = exact_binding->function();
|
|
|
- return success ? KeyResult::Executed : KeyResult::Failed;
|
|
|
+ // Execute the command via the CommandSystem
|
|
|
+ if (command_system_) {
|
|
|
+ CommandResult result = command_system_->execute(exact_binding->command_name, {}); // No args for now
|
|
|
+ // Optionally handle result.success or result.message
|
|
|
+ return result.success ? KeyResult::Executed : KeyResult::Failed;
|
|
|
+ }
|
|
|
+ return KeyResult::Failed; // No command system
|
|
|
} catch (...) {
|
|
|
return KeyResult::Failed;
|
|
|
}
|