source: trunk/FACT++/src/RemoteControl.cc@ 14868

Last change on this file since 14868 was 14674, checked in by tbretz, 12 years ago
Implemenetd a way to just check if a server is available and command descriptions have been received.
File size: 2.9 KB
Line 
1#include "RemoteControl.h"
2
3// ==========================================================================
4
5bool RemoteControlImp::ProcessCommand(const std::string &str, bool change)
6{
7 if (fCurrentServer.empty())
8 {
9 const size_t p1 = str.find_first_of(' ');
10 const size_t p2 = str.find_first_of('/');
11
12 const bool is_cmd = p2!=string::npos && p1>p2;
13
14 string s = str;
15 if (is_cmd)
16 s = str.substr(0, p2);
17
18 if (p2<p1 && p2!=str.length()-1)
19 {
20 const string c = str.substr(p2+1);
21 return SendDimCommand(lout, s, c, !change);
22 }
23
24 if (HasServer(s))
25 {
26 if (!change)
27 return SendDimCommand(lout, str, "", !change);
28
29 fCurrentServer = s;
30 return true;
31 }
32
33 if (!change && is_cmd)
34 throw runtime_error("Unkown server '"+s+"'");
35
36 if (change)
37 lout << kRed << "Unkown server '" << s << "'" << endl;
38
39 return false;
40 }
41
42 if (!fCurrentServer.empty() && str=="..")
43 {
44 fCurrentServer = "";
45 return true;
46 }
47 return SendDimCommand(lout, fCurrentServer, str, !change);
48}
49
50// ==========================================================================
51
52#include "tools.h"
53
54string RemoteConsole::GetUpdatePrompt() const
55{
56 // If we are continously flushing the buffer omit the buffer size
57 // If we are buffering show the buffer size
58 const string beg = '\n' + GetLinePrompt();
59
60 // If we have not cd'ed to a server show only the line start
61 if (fCurrentServer.empty() || !fImp)
62 return beg + "> ";
63
64 // Check if we have cd'ed to a valid server
65 const State state = fImp->GetServerState(fCurrentServer);
66 if (state.index==-256)
67 return beg + "> ";
68
69 // The server
70 const string serv = "\033[34m\033[1m"+fCurrentServer+"\033[0m";
71
72 // If no match found or something wrong found just output the server
73 if (state.index<-1)
74 return beg + " " + serv + "> ";
75
76 // If everything found add the state to the server
77 return beg + " " + serv + ":\033[32m\033[1m" + state.name + "\033[0m> ";
78}
79
80string RemoteShell::GetUpdatePrompt() const
81{
82 // If we are continously flushing the buffer omit the buffer size
83 // If we are buffering show the buffer size
84 const string beg = GetLinePrompt();
85
86 // If we have not cd'ed to a server show only the line start
87 if (fCurrentServer.empty() || !fImp)
88 return beg + "> ";
89
90 const State state = fImp->GetServerState(fCurrentServer);
91 if (state.index==-256)
92 return beg + "> ";//Form("\n[%d] \033[34m\033[1m%s\033[0m> ", GetLine(), fCurrentServer.c_str());
93
94 // If no match found or something wrong found just output the server
95 if (state.index<-1)
96 return beg + " " + fCurrentServer + "> ";
97
98 // If everything found add the state to the server
99 return beg + " " + fCurrentServer + ":" + state.name + "> ";
100}
Note: See TracBrowser for help on using the repository browser.