aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/fbrun/FbRun.cc72
-rw-r--r--util/fbrun/FbRun.hh16
-rw-r--r--util/fbrun/main.cc13
3 files changed, 93 insertions, 8 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
36using namespace std; 37using namespace std;
37FbRun::FbRun(int x, int y, size_t width): 38FbRun::FbRun(int x, int y, size_t width):
@@ -40,7 +41,8 @@ m_win(None),
40m_display(BaseDisplay::getXDisplay()), 41m_display(BaseDisplay::getXDisplay()),
41m_bevel(4), 42m_bevel(4),
42m_gc(DefaultGC(m_display, DefaultScreen(m_display))), 43m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
43m_end(false) { 44m_end(false),
45m_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
77bool 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
65bool FbRun::loadFont(const string &fontname) { 102bool 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
254void 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
262void 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}
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh
index ba7bf25..5c8a2dc 100644
--- a/util/fbrun/FbRun.hh
+++ b/util/fbrun/FbRun.hh
@@ -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.hh,v 1.2 2002/11/12 16:47:37 fluxgen Exp $ 22// $Id: FbRun.hh,v 1.3 2002/11/12 19:20:31 fluxgen Exp $
23 23
24#ifndef FBRUN_HH 24#ifndef FBRUN_HH
25#define FBRUN_HH 25#define FBRUN_HH
@@ -28,10 +28,10 @@
28#include "Font.hh" 28#include "Font.hh"
29 29
30#include <string> 30#include <string>
31#include <vector>
31 32
32/** 33/**
33 Creates and managed a run window 34 Creates and managed a run window
34 TODO: a command history
35*/ 35*/
36class FbRun: public FbTk::EventHandler<XEvent> { 36class FbRun: public FbTk::EventHandler<XEvent> {
37public: 37public:
@@ -54,9 +54,16 @@ public:
54 const FbTk::Font &font() const { return m_font; } 54 const FbTk::Font &font() const { return m_font; }
55 /// execute command and exit 55 /// execute command and exit
56 void run(const std::string &execstring); 56 void run(const std::string &execstring);
57 /// is this object done? 57 /// is this application done?
58 bool end() const { return m_end; } 58 bool end() const { return m_end; }
59 /**
60 loads history file.
61 @return true on success, else false
62 */
63 bool loadHistory(const char *filename);
59private: 64private:
65 void nextHistoryItem();
66 void prevHistoryItem();
60 void drawString(int x, int y, const char *text, size_t len); 67 void drawString(int x, int y, const char *text, size_t len);
61 void getSize(size_t &width, size_t &height); 68 void getSize(size_t &width, size_t &height);
62 void createWindow(int x, int y, size_t width, size_t height); 69 void createWindow(int x, int y, size_t width, size_t height);
@@ -72,6 +79,9 @@ private:
72 int m_bevel; ///< distance to window edge from font in pixels 79 int m_bevel; ///< distance to window edge from font in pixels
73 GC m_gc; 80 GC m_gc;
74 bool m_end; 81 bool m_end;
82 std::vector<std::string> m_history; ///< history list of commands
83 size_t m_current_history_item;
84 std::string m_history_file;
75}; 85};
76 86
77#endif // FBRUN_HH 87#endif // FBRUN_HH
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc
index 2237340..574dd76 100644
--- a/util/fbrun/main.cc
+++ b/util/fbrun/main.cc
@@ -19,10 +19,11 @@
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: main.cc,v 1.2 2002/11/12 16:46:17 fluxgen Exp $ 22// $Id: main.cc,v 1.3 2002/11/12 19:16:26 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25#include "BaseDisplay.hh" 25#include "BaseDisplay.hh"
26#include "StringUtil.hh"
26 27
27#include <string> 28#include <string>
28#include <iostream> 29#include <iostream>
@@ -57,6 +58,7 @@ void showUsage(const char *progname) {
57 " -fg [color name] Foreground text color"<<endl<< 58 " -fg [color name] Foreground text color"<<endl<<
58 " -bg [color name] Background color"<<endl<< 59 " -bg [color name] Background color"<<endl<<
59 " -a Antialias"<<endl<< 60 " -a Antialias"<<endl<<
61 " -hf [history file] History file to load (default ~/.fluxbox/history)"<<endl<<
60 " -help Show this help"<<endl<<endl<< 62 " -help Show this help"<<endl<<endl<<
61 "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl; 63 "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
62} 64}
@@ -73,7 +75,7 @@ int main(int argc, char **argv) {
73 string foreground("black"); // text color 75 string foreground("black"); // text color
74 string background("white"); // text background color 76 string background("white"); // text background color
75 string display_name; // name of the display connection 77 string display_name; // name of the display connection
76 78 string history_file("~/.fluxbox/fbrun_history"); // command history file
77 // parse arguments 79 // parse arguments
78 for (int i=1; i<argc; i++) { 80 for (int i=1; i<argc; i++) {
79 if (strcmp(argv[i], "-font") == 0 && i+1 < argc) { 81 if (strcmp(argv[i], "-font") == 0 && i+1 < argc) {
@@ -109,6 +111,8 @@ int main(int argc, char **argv) {
109 background = argv[i]; 111 background = argv[i];
110 } else if (strcmp(argv[i], "-a") == 0) { 112 } else if (strcmp(argv[i], "-a") == 0) {
111 antialias = true; 113 antialias = true;
114 } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) {
115 history_file = argv[++i];
112 } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { 116 } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
113 showUsage(argv[0]); 117 showUsage(argv[0]);
114 exit(0); 118 exit(0);
@@ -159,6 +163,11 @@ int main(int argc, char **argv) {
159 fbrun.resize(width, height); 163 fbrun.resize(width, height);
160 if (antialias) 164 if (antialias)
161 fbrun.setAntialias(antialias); 165 fbrun.setAntialias(antialias);
166 // expand and load command history
167 string expanded_filename = StringUtil::expandFilename(history_file);
168 if (!fbrun.loadHistory(expanded_filename.c_str()))
169 cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl;
170
162 fbrun.setTitle(title); 171 fbrun.setTitle(title);
163 fbrun.setText(text); 172 fbrun.setText(text);
164 fbrun.show(); 173 fbrun.show();