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

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