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 |
|
---|
16 | using namespace std;
|
---|
17 |
|
---|
18 | // --------------------------------------------------------------------------
|
---|
19 | //
|
---|
20 | //! @returns
|
---|
21 | //! always true
|
---|
22 | //
|
---|
23 | bool 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 | //
|
---|
53 | bool 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 | //
|
---|
70 | bool 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 | //
|
---|
110 | bool 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 | //
|
---|
139 | bool 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 << " .x filename " << kReset << "Execute a script of commands" << endl;
|
---|
156 | out << kBold << " .q,quit " << kReset << "Quit" << endl;
|
---|
157 | out << endl;
|
---|
158 |
|
---|
159 | return true;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | bool ReadlineColor::Process(ostream &out, const string &str)
|
---|
164 | {
|
---|
165 | // ----------- Readline -----------
|
---|
166 |
|
---|
167 | if (str=="lh" || str=="history")
|
---|
168 | {
|
---|
169 | out << endl << kBold << "History:" << endl;
|
---|
170 | return Readline::RedirectionWrapper(out, Readline::DumpHistory);
|
---|
171 | }
|
---|
172 |
|
---|
173 | if (str=="v" || str=="variable")
|
---|
174 | {
|
---|
175 | out << endl << kBold << "Variables:" << endl;
|
---|
176 | return Readline::RedirectionWrapper(out, Readline::DumpVariables);
|
---|
177 | }
|
---|
178 |
|
---|
179 | if (str=="f" || str=="function")
|
---|
180 | {
|
---|
181 | out << endl << kBold << "Functions:" << endl;
|
---|
182 | return Readline::RedirectionWrapper(out, Readline::DumpFunctions);
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (str=="m" || str=="funmap")
|
---|
186 | {
|
---|
187 | out << endl << kBold << "Funmap:" << endl;
|
---|
188 | return Readline::RedirectionWrapper(out, Readline::DumpFunmap);
|
---|
189 | }
|
---|
190 |
|
---|
191 | // ------------ ReadlineWindow -------------
|
---|
192 |
|
---|
193 | if (str=="a" || str=="attrs")
|
---|
194 | return PrintAttributes(out);
|
---|
195 |
|
---|
196 | return false;
|
---|
197 | }
|
---|