elna/shell/history.cpp

55 lines
1.3 KiB
C++

#include "elna/shell/history.hpp"
namespace elna
{
editor_history::editor_history()
: commands{}, current_pointer(commands.cend())
{
}
void editor_history::push(const std::string& entry)
{
commands.push_back(entry);
current_pointer = commands.cend();
}
void editor_history::clear()
{
commands.clear();
current_pointer = commands.cend();
}
editor_history::const_iterator editor_history::prev() noexcept
{
if (this->current_pointer != cbegin())
{
this->current_pointer = std::prev(this->current_pointer);
}
return this->current_pointer;
}
editor_history::const_iterator editor_history::next() noexcept
{
if (this->current_pointer != cend())
{
this->current_pointer = std::next(this->current_pointer);
}
return this->current_pointer;
}
editor_history::const_iterator editor_history::cbegin() const noexcept
{
return this->commands.cbegin();
}
editor_history::const_iterator editor_history::cend() const noexcept
{
return this->commands.cend();
}
editor_history::const_iterator editor_history::current() const noexcept
{
return this->current_pointer;
}
}