HAL
python_console_history.cpp
Go to the documentation of this file.
1 #include <QDir>
2 #include <fstream>
4 
6 
7 namespace hal
8 {
9  PythonConsoleHistory::PythonConsoleHistory() : mFileName(QDir::home().filePath(".hal_history").toLocal8Bit().constData()), mHistory()
10  {
12  }
13 
15  {
16  }
17 
18  void PythonConsoleHistory::addHistory(const std::string& command)
19  {
20  mHistory.push_back(command);
21  appendToFile(command);
22  }
23 
24  const std::string& PythonConsoleHistory::getHistoryItem(const int& index) const
25  {
26  return mHistory.at(index);
27  }
28 
30  {
31  return mHistory.size();
32  }
33 
35  {
36  std::ifstream f(mFileName);
37  mHistory.clear();
38  std::string line;
39  while (std::getline(f, line))
40  {
41  mHistory.push_back(line);
42  }
43  }
44 
45  void PythonConsoleHistory::appendToFile(const std::string& command)
46  {
47  std::ofstream f(mFileName, std::ios::out | std::ios::app);
48  f << command << std::endl;
49  }
50 }
const std::string & getHistoryItem(const int &index) const
void addHistory(const std::string &command)
string command
Definition: control.py:76