Commit d720fdfcf9
Unsigned
Layout: unified · split
src/render.rs +90 −25
| @@ -27,7 +27,15 @@ pub(crate) trait RenderableEvent { | |||
| 27 | impl RenderableEvent for EncryptedEvent { | 27 | impl RenderableEvent for EncryptedEvent { |
| 28 | // TODO: this is not implemented yet | 28 | // TODO: this is not implemented yet |
| 29 | fn render(&self, displayname: &str) -> String { | 29 | fn render(&self, displayname: &str) -> String { |
| 30 | format!("{}\t{}", displayname, "Unable to decrypt message") | 30 | let color_user = Weechat::color("green"); // TODO: get per-user color |
| 31 | let color_reset = Weechat::color("reset"); | ||
| 32 | format!( | ||
| 33 | "{color_user}{}{color_reset}\t{}", | ||
| 34 | displayname, | ||
| 35 | "Unable to decrypt message", | ||
| 36 | color_user = color_user, | ||
| 37 | color_reset = color_reset | ||
| 38 | ) | ||
| 31 | } | 39 | } |
| 32 | 40 | ||
| 33 | fn sender(&self) -> &UserId { | 41 | fn sender(&self) -> &UserId { |
| @@ -38,7 +46,8 @@ impl RenderableEvent for EncryptedEvent { | |||
| 38 | impl RenderableEvent for MemberEvent { | 46 | impl RenderableEvent for MemberEvent { |
| 39 | fn render(&self, displayname: &str) -> String { | 47 | fn render(&self, displayname: &str) -> String { |
| 40 | use MembershipChange::*; | 48 | use MembershipChange::*; |
| 41 | let operation = match self.membership_change() { | 49 | let change_op = self.membership_change(); |
| 50 | let operation = match change_op { | ||
| 42 | None => "did nothing", | 51 | None => "did nothing", |
| 43 | Error => "caused an error", // must never happen | 52 | Error => "caused an error", // must never happen |
| 44 | Joined => "has joined the room", | 53 | Joined => "has joined the room", |
| @@ -53,12 +62,22 @@ impl RenderableEvent for MemberEvent { | |||
| 53 | ProfileChanged => "changed the display name or avatar", | 62 | ProfileChanged => "changed the display name or avatar", |
| 54 | NotImplemented => "performed an unimplemented operation", | 63 | NotImplemented => "performed an unimplemented operation", |
| 55 | }; | 64 | }; |
| 65 | |||
| 66 | let (prefix, color_action) = match change_op { | ||
| 67 | Joined | Invited => ("join", "green"), | ||
| 68 | _ => ("quit", "red"), | ||
| 69 | }; | ||
| 70 | |||
| 56 | format!( | 71 | format!( |
| 57 | "{} {} ({}) {}", | 72 | "{prefix}{color_user}{name} {color_deli}({color_reset}{state}{color_deli}){color_reset} {color_action}{op}", |
| 58 | Weechat::prefix("join"), | 73 | prefix = Weechat::prefix(prefix), |
| 59 | displayname, | 74 | color_user = Weechat::color("reset"), // TODO |
| 60 | self.state_key, | 75 | color_deli = Weechat::color("chat_delimiters"), |
| 61 | operation | 76 | color_action = Weechat::color(color_action), |
| 77 | color_reset = Weechat::color("reset"), | ||
| 78 | name = displayname, | ||
| 79 | state = self.state_key, | ||
| 80 | op = operation, | ||
| 62 | ) | 81 | ) |
| 63 | } | 82 | } |
| 64 | 83 | ||
| @@ -71,25 +90,71 @@ impl RenderableEvent for MessageEvent { | |||
| 71 | fn render(&self, displayname: &str) -> String { | 90 | fn render(&self, displayname: &str) -> String { |
| 72 | use MessageEventContent::*; | 91 | use MessageEventContent::*; |
| 73 | 92 | ||
| 93 | let color_user = Weechat::color("green"); // TODO: get per-user color | ||
| 94 | let color_reset = Weechat::color("reset"); | ||
| 74 | match &self.content { | 95 | match &self.content { |
| 75 | Text(t) => format!("{}\t{}", displayname, t.resolve_body()), | 96 | // TODO: formatting for inline markdown and so on |
| 76 | Emote(e) => format!("{}\t{}", displayname, e.resolve_body()), | 97 | Text(t) => format!( |
| 77 | Audio(a) => { | 98 | "{color_user}{}{color_reset}\t{}", |
| 78 | format!("{}\t{}: {}", displayname, a.body, a.resolve_url()) | 99 | displayname, |
| 79 | } | 100 | t.resolve_body(), |
| 80 | File(f) => { | 101 | color_user = color_user, |
| 81 | format!("{}\t{}: {}", displayname, f.body, f.resolve_url()) | 102 | color_reset = color_reset |
| 82 | } | 103 | ), |
| 83 | Image(i) => { | 104 | Emote(e) => format!( |
| 84 | format!("{}\t{}: {}", displayname, i.body, i.resolve_url()) | 105 | "{color_user}{}{color_reset}\t{}", |
| 85 | } | 106 | displayname, |
| 86 | Location(l) => { | 107 | e.resolve_body(), |
| 87 | format!("{}\t{}: {}", displayname, l.body, l.geo_uri) | 108 | color_user = color_user, |
| 88 | } | 109 | color_reset = color_reset |
| 89 | Notice(n) => format!("{}\t{}", displayname, n.resolve_body()), | 110 | ), |
| 90 | Video(v) => { | 111 | Audio(a) => format!( |
| 91 | format!("{}\t{}: {}", displayname, v.body, v.resolve_url()) | 112 | "{color_user}{}{color_reset}\t{}: {}", |
| 92 | } | 113 | displayname, |
| 114 | a.body, | ||
| 115 | a.resolve_url(), | ||
| 116 | color_user = color_user, | ||
| 117 | color_reset = color_reset | ||
| 118 | ), | ||
| 119 | File(f) => format!( | ||
| 120 | "{color_user}{}{color_reset}\t{}: {}", | ||
| 121 | displayname, | ||
| 122 | f.body, | ||
| 123 | f.resolve_url(), | ||
| 124 | color_user = color_user, | ||
| 125 | color_reset = color_reset | ||
| 126 | ), | ||
| 127 | Image(i) => format!( | ||
| 128 | "{color_user}{}{color_reset}\t{}: {}", | ||
| 129 | displayname, | ||
| 130 | i.body, | ||
| 131 | i.resolve_url(), | ||
| 132 | color_user = color_user, | ||
| 133 | color_reset = color_reset | ||
| 134 | ), | ||
| 135 | Location(l) => format!( | ||
| 136 | "{color_user}{}{color_reset}\t{}: {}", | ||
| 137 | displayname, | ||
| 138 | l.body, | ||
| 139 | l.geo_uri, | ||
| 140 | color_user = color_user, | ||
| 141 | color_reset = color_reset | ||
| 142 | ), | ||
| 143 | Notice(n) => format!( | ||
| 144 | "{color_user}{}{color_reset}\t{}", | ||
| 145 | displayname, | ||
| 146 | n.resolve_body(), | ||
| 147 | color_user = color_user, | ||
| 148 | color_reset = color_reset | ||
| 149 | ), | ||
| 150 | Video(v) => format!( | ||
| 151 | "{color_user}{}{color_reset}\t{}: {}", | ||
| 152 | displayname, | ||
| 153 | v.body, | ||
| 154 | v.resolve_url(), | ||
| 155 | color_user = color_user, | ||
| 156 | color_reset = color_reset | ||
| 157 | ), | ||
| 93 | ServerNotice(sn) => { | 158 | ServerNotice(sn) => { |
| 94 | format!("SERVER\t{}", sn.body) // TODO | 159 | format!("SERVER\t{}", sn.body) // TODO |
| 95 | } | 160 | } |