diff options
Diffstat (limited to 'util/fbrun/FbRun.cc')
-rw-r--r-- | util/fbrun/FbRun.cc | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 2042c17..6a0e6d8 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: FbRun.cc,v 1.3 2002/11/12 17:10:13 fluxgen Exp $ | 22 | // $Id: FbRun.cc,v 1.4 2002/11/12 19:20:31 fluxgen Exp $ |
23 | 23 | ||
24 | #include "FbRun.hh" | 24 | #include "FbRun.hh" |
25 | 25 | ||
@@ -32,6 +32,7 @@ | |||
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | 33 | ||
34 | #include <iostream> | 34 | #include <iostream> |
35 | #include <fstream> | ||
35 | 36 | ||
36 | using namespace std; | 37 | using namespace std; |
37 | FbRun::FbRun(int x, int y, size_t width): | 38 | FbRun::FbRun(int x, int y, size_t width): |
@@ -40,7 +41,8 @@ m_win(None), | |||
40 | m_display(BaseDisplay::getXDisplay()), | 41 | m_display(BaseDisplay::getXDisplay()), |
41 | m_bevel(4), | 42 | m_bevel(4), |
42 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), | 43 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), |
43 | m_end(false) { | 44 | m_end(false), |
45 | m_current_history_item(0) { | ||
44 | createWindow(x, y, width + m_bevel, m_font.height()); | 46 | createWindow(x, y, width + m_bevel, m_font.height()); |
45 | } | 47 | } |
46 | 48 | ||
@@ -57,11 +59,46 @@ void FbRun::run(const std::string &command) { | |||
57 | exit(0); //exit fork | 59 | exit(0); //exit fork |
58 | } | 60 | } |
59 | 61 | ||
60 | hide(); | 62 | hide(); // hide gui |
63 | |||
64 | // save command history to file | ||
65 | if (m_runtext.size() != 0) { // no need to save empty command | ||
66 | // open file in append mode | ||
67 | ofstream outfile(m_history_file.c_str(), ios::app); | ||
68 | if (outfile) | ||
69 | outfile<<m_runtext<<endl; | ||
70 | else | ||
71 | cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; | ||
72 | } | ||
61 | 73 | ||
62 | m_end = true; // mark end of processing | 74 | m_end = true; // mark end of processing |
63 | } | 75 | } |
64 | 76 | ||
77 | bool FbRun::loadHistory(const char *filename) { | ||
78 | if (filename == 0) | ||
79 | return false; | ||
80 | ifstream infile(filename); | ||
81 | if (!infile) { | ||
82 | //even though we fail to load file, we should try save to it | ||
83 | m_history_file = filename; | ||
84 | return false; | ||
85 | } | ||
86 | // clear old history and load new one from file | ||
87 | m_history.clear(); | ||
88 | // each line is a command | ||
89 | string line; | ||
90 | while (!infile.eof()) { | ||
91 | getline(infile, line); | ||
92 | if (line.size()) // don't add empty lines | ||
93 | m_history.push_back(line); | ||
94 | } | ||
95 | // set no current histor to display | ||
96 | m_current_history_item = m_history.size(); | ||
97 | // set history file | ||
98 | m_history_file = filename; | ||
99 | return true; | ||
100 | } | ||
101 | |||
65 | bool FbRun::loadFont(const string &fontname) { | 102 | bool FbRun::loadFont(const string &fontname) { |
66 | if (!m_font.load(fontname.c_str())) | 103 | if (!m_font.load(fontname.c_str())) |
67 | return false; | 104 | return false; |
@@ -171,6 +208,16 @@ void FbRun::handleEvent(XEvent * const xev) { | |||
171 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { | 208 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { |
172 | m_runtext+=keychar[0]; // append character | 209 | m_runtext+=keychar[0]; // append character |
173 | redrawLabel(); | 210 | redrawLabel(); |
211 | } else if (IsCursorKey(ks)) { | ||
212 | switch (ks) { | ||
213 | case XK_Up: | ||
214 | prevHistoryItem(); | ||
215 | break; | ||
216 | case XK_Down: | ||
217 | nextHistoryItem(); | ||
218 | break; | ||
219 | } | ||
220 | redrawLabel(); | ||
174 | } | 221 | } |
175 | } break; | 222 | } break; |
176 | case Expose: | 223 | case Expose: |
@@ -203,3 +250,22 @@ void FbRun::setNoMaximize() { | |||
203 | sh.min_height = height; | 250 | sh.min_height = height; |
204 | XSetWMNormalHints(m_display, m_win, &sh); | 251 | XSetWMNormalHints(m_display, m_win, &sh); |
205 | } | 252 | } |
253 | |||
254 | void FbRun::prevHistoryItem() { | ||
255 | |||
256 | if (m_current_history_item > 0 && m_history.size() > 0) | ||
257 | m_current_history_item--; | ||
258 | if (m_current_history_item < m_history.size()) | ||
259 | m_runtext = m_history[m_current_history_item]; | ||
260 | } | ||
261 | |||
262 | void FbRun::nextHistoryItem() { | ||
263 | m_current_history_item++; | ||
264 | if (m_current_history_item >= m_history.size()) { | ||
265 | m_current_history_item = m_history.size(); | ||
266 | m_runtext = ""; | ||
267 | return; | ||
268 | } else | ||
269 | m_runtext = m_history[m_current_history_item]; | ||
270 | |||
271 | } | ||