HAL
python_console_history.cpp
Go to the documentation of this file.
1
#include <QDir>
2
#include <fstream>
3
#include <
gui/python/python_console_history.h
>
4
5
#include "
gui/python/python_console_history.h
"
6
7
namespace
hal
8
{
9
PythonConsoleHistory::PythonConsoleHistory
() : mFileName(
QDir
::home().filePath(
".hal_history"
).toLocal8Bit().constData()), mHistory()
10
{
11
updateFromFile
();
12
}
13
14
PythonConsoleHistory::~PythonConsoleHistory
()
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
29
int
PythonConsoleHistory::size
()
const
30
{
31
return
mHistory.size();
32
}
33
34
void
PythonConsoleHistory::updateFromFile
()
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
}
hal::PythonConsoleHistory::updateFromFile
void updateFromFile()
Definition:
python_console_history.cpp:34
hal::PythonConsoleHistory::size
int size() const
Definition:
python_console_history.cpp:29
hal::PythonConsoleHistory::getHistoryItem
const std::string & getHistoryItem(const int &index) const
Definition:
python_console_history.cpp:24
hal::PythonConsoleHistory::~PythonConsoleHistory
~PythonConsoleHistory()
Definition:
python_console_history.cpp:14
hal::PythonConsoleHistory::addHistory
void addHistory(const std::string &command)
Definition:
python_console_history.cpp:18
hal::PythonConsoleHistory::PythonConsoleHistory
PythonConsoleHistory()
Definition:
python_console_history.cpp:9
control.command
string command
Definition:
control.py:76
hal
Definition:
parser_liberty.cpp:10
python_console_history.h
QDir
plugins
gui
src
python
python_console_history.cpp
Generated on Fri Feb 14 2025 14:22:43 for HAL by
1.9.1