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