source: trunk/FACT++/src/ReadlineColor.cc@ 11302

Last change on this file since 11302 was 11044, checked in by tbretz, 13 years ago
Added '.w' to list of commands.
File size: 6.8 KB
Line 
1// **************************************************************************
2/** @namespace ReadlineColor
3
4@brief A fewer helper functions to apply color attributes and redirect the output
5
6 */
7// **************************************************************************
8#include "ReadlineColor.h"
9
10#include <boost/filesystem.hpp>
11
12#include "Time.h"
13#include "Readline.h"
14#include "WindowLog.h"
15
16using namespace std;
17
18// --------------------------------------------------------------------------
19//
20//! @returns
21//! always true
22//
23bool ReadlineColor::PrintBootMsg(ostream &out, const string &name, bool interactive)
24{
25 const string n = boost::filesystem::path(name).filename();
26
27 out << kBlue << kBold << kUnderline << "\n Master Control Program (compiled "__DATE__" " __TIME__ << ") " << endl;
28 out << kBlue <<
29 "\n"
30 " ENCOM MX 16-923 USER # 0" << int(Time().Mjd()) << Time::fmt(" %H:%M:%S") << Time() << Time::reset << " INFORMATION\n"
31 "\n"
32 " TELESCOPE CONTROL PROGRAM: " << n << "\n"
33 " ANNEXED BY FACT COLLABORATION\n"
34 " ORIGINAL PROGRAM WRITTEN BY T.BRETZ\n"
35 " THIS INFOMATION " << kUnderline << "PRIORITY ONE"
36 << endl;
37 out << kBlue << " END OF LINE\n" << endl;
38
39 if (!interactive)
40 return true;
41
42 out << "Enter 'h' for help." << endl;
43 out << endl;
44
45 return true;
46}
47
48// --------------------------------------------------------------------------
49//
50//! @returns
51//! always true
52//
53bool ReadlineColor::PrintCommands(ostream &out)
54{
55 out << endl;
56 out << " " << kUnderline << " Commands:" << endl;
57 out << " No application specific commands defined." << endl;
58 out << endl;
59
60 return true;
61}
62
63// --------------------------------------------------------------------------
64//
65//! Displays the available ncurses attributes, like color.
66//!
67//! @returns
68//! always true
69//
70bool ReadlineColor::PrintAttributes(ostream &out)
71{
72 out << endl;
73 out << " Attributes:" << endl;
74 out << " " << kReset << "kReset" << endl;
75 out << " " << kNormal << "kNormal" << endl;
76 out << " " << kHighlight << "kHighlight" << endl;
77 out << " " << kReverse << "kReverse" << endl;
78 out << " " << kUnderline << "kUnderline" << endl;
79 out << " " << kBlink << "kBlink" << endl;
80 out << " " << kDim << "kDim" << endl;
81 out << " " << kBold << "kBold" << endl;
82 out << " " << kProtect << "kProtect" << endl;
83 out << " " << kInvisible << "kInvisible" << endl;
84 out << " " << kAltCharset << "kAltCharset" << kReset << " (kAltCharset)" << endl;
85 out << endl;
86 out << " Colors:" << endl;
87 out << " " << kDefault << "kDefault " << kBold << "+ kBold" << endl;
88 out << " " << kRed << "kRed " << kBold << "+ kBold" << endl;
89 out << " " << kGreen << "kGreen " << kBold << "+ kBold" << endl;
90 out << " " << kYellow << "kYellow " << kBold << "+ kBold" << endl;
91 out << " " << kBlue << "kBlue " << kBold << "+ kBold" << endl;
92 out << " " << kMagenta << "kMagenta " << kBold << "+ kBold" << endl;
93 out << " " << kCyan << "kCyan " << kBold << "+ kBold" << endl;
94 out << " " << kWhite << "kWhite " << kBold << "+ kBold" << endl;
95 out << " " << endl;
96
97 return true;
98}
99
100// --------------------------------------------------------------------------
101//
102//! Displays the keybindings available due to the Shell class
103//!
104//! @returns
105//! always true
106//!
107//! @todo
108//! Update output
109//
110bool ReadlineColor::PrintKeyBindings(ostream &out)
111{
112 out << endl;
113 out << " " << kUnderline << "Key bindings:" << endl << endl;;
114 out << " Default key-bindings are identical with your bash." << endl;
115 out << endl;
116 out << kBold << " Page-up " << kReset << "Search backward in history" << endl;
117 out << kBold << " Page-dn " << kReset << "Search forward in history" << endl;
118 out << kBold << " Ctrl-left " << kReset << "One word backward" << endl;
119 out << kBold << " Ctrl-right " << kReset << "One word forward" << endl;
120 out << kBold << " Ctrl-d " << kReset << "Quit" << endl;
121 out << kBold << " Ctrl-y " << kReset << "Delete line" << endl;
122 out << kBold << " Alt-end/Ctrl-k " << kReset << "Delete until the end of the line" << endl;
123 out << endl;
124
125 return true;
126}
127
128// --------------------------------------------------------------------------
129//
130//! Print a general help text which also includes the commands pre-defined
131//! by the Shell class.
132//!
133//! @returns
134//! always true
135//!
136//! @todo
137//! Get it up-to-date
138//
139bool ReadlineColor::PrintGeneralHelp(ostream &out, const string &name)
140{
141 out << endl;
142 out << " " << kUnderline << "General help:" << endl << endl;
143 out << " The command history is automatically loaded and saves to" << endl;
144 out << " and from " << name << endl;
145 out << endl;
146 out << kBold << " h,help " << kReset << "Print this help message" << endl;
147 out << kBold << " clear " << kReset << "Clear history buffer" << endl;
148 out << kBold << " lh,history " << kReset << "Dump the history buffer to the screen" << endl;
149 out << kBold << " v,variable " << kReset << "Dump readline variables" << endl;
150 out << kBold << " f,function " << kReset << "Dump readline functions" << endl;
151 out << kBold << " m,funmap " << kReset << "Dump readline funmap" << endl;
152 out << kBold << " c,command " << kReset << "Dump available commands" << endl;
153 out << kBold << " k,keylist " << kReset << "Dump key bindings" << endl;
154 out << kBold << " a,attrs " << kReset << "Dump available stream attributes" << endl;
155 out << kBold << " .w n " << kReset << "Sleep n milliseconds";
156 out << kBold << " .x filename " << kReset << "Execute a script of commands" << endl;
157 out << kBold << " .q,quit " << kReset << "Quit" << endl;
158 out << endl;
159
160 return true;
161}
162
163
164bool ReadlineColor::Process(ostream &out, const string &str)
165{
166 // ----------- Readline -----------
167
168 if (str=="lh" || str=="history")
169 {
170 out << endl << kBold << "History:" << endl;
171 return Readline::RedirectionWrapper(out, Readline::DumpHistory);
172 }
173
174 if (str=="v" || str=="variable")
175 {
176 out << endl << kBold << "Variables:" << endl;
177 return Readline::RedirectionWrapper(out, Readline::DumpVariables);
178 }
179
180 if (str=="f" || str=="function")
181 {
182 out << endl << kBold << "Functions:" << endl;
183 return Readline::RedirectionWrapper(out, Readline::DumpFunctions);
184 }
185
186 if (str=="m" || str=="funmap")
187 {
188 out << endl << kBold << "Funmap:" << endl;
189 return Readline::RedirectionWrapper(out, Readline::DumpFunmap);
190 }
191
192 // ------------ ReadlineWindow -------------
193
194 if (str=="a" || str=="attrs")
195 return PrintAttributes(out);
196
197 return false;
198}
Note: See TracBrowser for help on using the repository browser.