history.h
1 #pragma once 2 3 #include <stddef.h> 4 5 namespace console { 6 7 //------------------------------------------ 8 // History — command history with navigation 9 //------------------------------------------ 10 class History { 11 public: 12 History(size_t max_entries = 16, bool is_deduplicating = true); 13 14 void add(const char *command); 15 const char *previous(); 16 const char *next(); 17 void reset_position(); 18 void clear(); 19 size_t length() const; 20 bool is_empty() const; 21 22 void load(const char *path); 23 void save(const char *path) const; 24 25 private: 26 static constexpr size_t MAX_ENTRIES = 16; 27 static constexpr size_t ENTRY_SIZE = 256; 28 29 char entries_[MAX_ENTRIES][ENTRY_SIZE]; 30 size_t count_; 31 size_t max_entries_; 32 int current_index_; 33 bool is_deduplicating_; 34 }; 35 36 }