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