]> git.armaanb.net Git - gen-shell.git/blob - src/prompt.cpp
5b594983ade912ae5068b4ab2ddfd83386305559
[gen-shell.git] / src / prompt.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez, 2020 Armaan Bhojwani
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
23 // http://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #include <cmake.h>
28 #include <vector>
29 #include <string>
30
31 static std::vector <std::string> contextColors = {
32   "bold white on red",
33   "bold white on blue",
34   "bold white on green",
35   "bold white on magenta",
36   "black on cyan",
37   "black on yellow",
38   "black on white",
39 };
40
41 static std::vector <std::string> contexts;
42
43 std::string composeContexts (bool pretty = false);
44
45 ////////////////////////////////////////////////////////////////////////////////
46 int promptClear ()
47 {
48   contexts.clear ();
49   return 0;
50 }
51
52 ////////////////////////////////////////////////////////////////////////////////
53 int promptRemove ()
54 {
55   if (contexts.size ())
56     contexts.pop_back ();
57
58   return 0;
59 }
60
61 ////////////////////////////////////////////////////////////////////////////////
62 int promptAdd (const std::string& context)
63 {
64   contexts.push_back (context);
65   return 0;
66 }
67
68 ////////////////////////////////////////////////////////////////////////////////
69 std::string composeContexts (bool pretty /* = false */)
70 {
71   std::string combined;
72   for (unsigned int i = 0; i < contexts.size (); i++)
73     if (pretty)
74       combined += (combined != "" ? " " : "")
75                 + std::string ("\001")
76                 + "\002";
77     else
78       combined += (combined != "" ? " " : "") + contexts[i];
79
80   if (combined != "")
81     combined += ' ';
82
83   return combined;
84 }
85
86 ////////////////////////////////////////////////////////////////////////////////
87 std::string promptCompose ()
88 {
89   return ">>>";
90 }
91
92 ////////////////////////////////////////////////////////////////////////////////