HAL
v4.5.0-254-g8f9f6a423
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
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
namespace
10
{
11
// one history entry per line in file, line breaks within multi-line commands are stored as U+2029 (UTF-8)
12
const
std::string sFileLineBreak =
"\xE2\x80\xA9"
;
13
14
std::string replaceAll(std::string text,
const
std::string& from,
const
std::string&
to
)
15
{
16
for
(
size_t
pos = text.find(from); pos != std::string::npos; pos = text.find(from, pos +
to
.size()))
17
text.replace(pos, from.size(),
to
);
18
return
text;
19
}
20
}
21
22
PythonConsoleHistory::PythonConsoleHistory
() : mFileName(
QDir
::home().filePath(
".hal_history"
).toLocal8Bit().constData()), mHistory()
23
{
24
updateFromFile
();
25
}
26
27
PythonConsoleHistory::~PythonConsoleHistory
()
28
{
29
}
30
31
void
PythonConsoleHistory::addHistory
(
const
std::string& command)
32
{
33
mHistory.push_back(command);
34
appendToFile(command);
35
}
36
37
const
std::string&
PythonConsoleHistory::getHistoryItem
(
const
int
&
index
)
const
38
{
39
return
mHistory.at(
index
);
40
}
41
42
int
PythonConsoleHistory::size
()
const
43
{
44
return
mHistory.size();
45
}
46
47
void
PythonConsoleHistory::updateFromFile
()
48
{
49
std::ifstream f(mFileName);
50
mHistory.clear();
51
std::string line;
52
while
(std::getline(f, line))
53
{
54
mHistory.push_back(replaceAll(line, sFileLineBreak,
"\n"
));
55
}
56
}
57
58
void
PythonConsoleHistory::appendToFile(
const
std::string& command)
59
{
60
std::ofstream f(mFileName, std::ios::out | std::ios::app);
61
f << replaceAll(command,
"\n"
, sFileLineBreak) << std::endl;
62
}
63
}
hal::PythonConsoleHistory::updateFromFile
void updateFromFile()
Definition:
python_console_history.cpp:47
hal::PythonConsoleHistory::size
int size() const
Definition:
python_console_history.cpp:42
hal::PythonConsoleHistory::getHistoryItem
const std::string & getHistoryItem(const int &index) const
Definition:
python_console_history.cpp:37
hal::PythonConsoleHistory::~PythonConsoleHistory
~PythonConsoleHistory()
Definition:
python_console_history.cpp:27
hal::PythonConsoleHistory::addHistory
void addHistory(const std::string &command)
Definition:
python_console_history.cpp:31
hal::PythonConsoleHistory::PythonConsoleHistory
PythonConsoleHistory()
Definition:
python_console_history.cpp:22
hal::core_strings::to
S to(const T &str)
Definition:
special_strings.h:48
hal
Definition:
defines.h:45
index
u32 index
Definition:
netlist_preprocessing.cpp:2111
python_console_history.h
QDir
plugins
gui
src
python
python_console_history.cpp
Generated by
1.9.1