summaryrefslogtreecommitdiff
path: root/src/tmate/stdout.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/tmate/stdout.vala')
-rw-r--r--src/tmate/stdout.vala69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/tmate/stdout.vala b/src/tmate/stdout.vala
index 804ccbb..223eb26 100644
--- a/src/tmate/stdout.vala
+++ b/src/tmate/stdout.vala
@@ -5,9 +5,9 @@ namespace Tmate
class Stdout : Object
{
public enum TokenType {
- SOCKET, ADDRESS, MATES, EMPTY,
- COMMENT, RESTART, INIT, TERM,
- UNRECOGNIZED, NET_ERROR;
+ SOCKET, ADDRESS, MATES,
+ EMPTY, COMMENT, RESTART,
+ INIT, TERM, UNKNOWN, ERROR;
public string to_string() {
return EnumClass.to_string(typeof(TokenType), this)
@@ -18,29 +18,24 @@ namespace Tmate
public class Token
{
public TokenType @class {get; private set;}
- public string[] tokens {get; private set;}
- public Token(string[] tokens, TokenType @class = UNRECOGNIZED)
+ public string[] list {get; private set;}
+ public Token(string[] list, TokenType @class = UNKNOWN)
{
this.class = @class;
- this.tokens = tokens;
+ this.list = list;
}
public string to_string()
{
- var sep = "";
- var end = "";
-
- if (this.tokens.length > 1) {
- sep += "\n\t";
- end += "\n";
- }
- if(this.tokens.length > 0) {
- sep += "\"";
- end += "\"";
- }
- return @"<$(this.class) {$sep$(
- string.joinv(@"\", $sep", this.tokens)
- )$(end.reverse())
- }>";
+ if (this.list.length == 0)
+ return "<%s>".printf(this.@class.to_string());
+ else if(this.list.length == 1)
+ return "<%s {\"%s\"}>".printf(
+ this.@class.to_string(),
+ this.list[0]);
+ else
+ return "<%s {\n\t\"%s\"\n}>".printf(
+ this.@class.to_string(),
+ string.joinv("\",\n\t\"", this.list));
}
}
@@ -50,36 +45,38 @@ namespace Tmate
private Regex r_closed = /^Session closed$/;
private Regex r_restarted = /^Session shell restarted$/;
private Regex r_comment = /^(Note: |Reconnecting)/;
- private Regex r_dnsfail = /^([^ ]+ lookup failure\.).+ \((.+)\)$/;
- private Regex r_netfail = /^(Error [^:]+)[:] [^:]+[:] (.+)$/;
+ private Regex r_dnsfail = /^(?P<body>[^ ]+ lookup failure\.).+ \((non-recoverable )?(?P<summery>.+)\)$/;
+ private Regex r_netfail = /^(?P<summery>Error [^:]+)[:] [^:]+[:] (?P<body>.+)$/;
private Regex r_address = /^(ssh|web) \w+ ?(|read only)[:](?:|.+) ([^ ]+)$/;
+ private MatchInfo info;
- public Token parse(string line)
+ public Token parse(string input)
{
- MatchInfo info;
+ var line = input.strip();
+
if(line == "")
return new Token({}, EMPTY);
else if(r_mates.match(line, 0, out info))
return new Token({
- info.fetch(1), // joined | left
- info.fetch(2), // mate ip/domain
- info.fetch(3) // active mates
- }, MATES);
+ info.fetch(1), // joined | left
+ info.fetch(2), // mate ip/domain
+ info.fetch(3) // active mates
+ }, MATES);
else if(r_dnsfail.match(line, 0, out info) || r_netfail.match(line, 0, out info))
return new Token({
- info.fetch(1),
- info.fetch(2),
- }, NET_ERROR);
+ info.fetch_named("summery"),
+ info.fetch_named("body"),
+ }, ERROR);
else if(r_comment.match(line))
return new Token({line}, COMMENT);
else if(r_restarted.match(line))
return new Token({}, RESTART);
else if(r_address.match(line, 0, out info))
return new Token({
- info.fetch(1), // web | ssh
- info.fetch(2), // read only?
- info.fetch(3) // address
- }, ADDRESS);
+ info.fetch(1), // web | ssh
+ info.fetch(2), // read only?
+ info.fetch(3) // address
+ }, ADDRESS);
else if(r_socket.match(line, 0, out info))
return new Token({ info.fetch(1) }, SOCKET);
else if(r_closed.match(line))