Commit 6aa326c390

6aa326c3909b82286ff0c5877e58f35272e2f782

parent: 071dd1ec35

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-09-05 16:15 UTC

weechat-matrix: Add a /devices command.

Layout: unified · split

Cargo.lock +31 −14
@@ -743,6 +743,14 @@ dependencies = [
743743 "hashbrown 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
744744]
745745
746[[package]]
747name = "indoc"
748version = "1.0.2"
749source = "registry+https://github.com/rust-lang/crates.io-index"
750dependencies = [
751 "unindent 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
752]
753
746754[[package]]
747755name = "instant"
748756version = "0.1.6"
@@ -868,7 +876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
868876[[package]]
869877name = "matrix-sdk"
870878version = "0.1.0"
871source = "git+https://github.com/matrix-org/matrix-rust-sdk/#89efcee337443cd446e99f40b9ccf69edb16715e"
879source = "git+https://github.com/matrix-org/matrix-rust-sdk/#6c7dbb814bcec79b9b3292ac2743adf355d41c62"
872880dependencies = [
873881 "async-trait 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
874882 "dashmap 3.11.10 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -888,7 +896,7 @@ dependencies = [
888896[[package]]
889897name = "matrix-sdk-base"
890898version = "0.1.0"
891source = "git+https://github.com/matrix-org/matrix-rust-sdk/#89efcee337443cd446e99f40b9ccf69edb16715e"
899source = "git+https://github.com/matrix-org/matrix-rust-sdk/#6c7dbb814bcec79b9b3292ac2743adf355d41c62"
892900dependencies = [
893901 "async-trait 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
894902 "matrix-sdk-common 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk/)",
@@ -905,7 +913,7 @@ dependencies = [
905913[[package]]
906914name = "matrix-sdk-common"
907915version = "0.1.0"
908source = "git+https://github.com/matrix-org/matrix-rust-sdk/#89efcee337443cd446e99f40b9ccf69edb16715e"
916source = "git+https://github.com/matrix-org/matrix-rust-sdk/#6c7dbb814bcec79b9b3292ac2743adf355d41c62"
909917dependencies = [
910918 "assign 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
911919 "futures-locks 0.5.1-pre (git+https://github.com/asomers/futures-locks)",
@@ -919,7 +927,7 @@ dependencies = [
919927[[package]]
920928name = "matrix-sdk-common-macros"
921929version = "0.1.0"
922source = "git+https://github.com/matrix-org/matrix-rust-sdk/#89efcee337443cd446e99f40b9ccf69edb16715e"
930source = "git+https://github.com/matrix-org/matrix-rust-sdk/#6c7dbb814bcec79b9b3292ac2743adf355d41c62"
923931dependencies = [
924932 "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
925933 "syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -928,7 +936,7 @@ dependencies = [
928936[[package]]
929937name = "matrix-sdk-crypto"
930938version = "0.1.0"
931source = "git+https://github.com/matrix-org/matrix-rust-sdk/#89efcee337443cd446e99f40b9ccf69edb16715e"
939source = "git+https://github.com/matrix-org/matrix-rust-sdk/#6c7dbb814bcec79b9b3292ac2743adf355d41c62"
932940dependencies = [
933941 "async-trait 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
934942 "atomic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1981,6 +1989,11 @@ name = "unicode-xid"
19811989version = "0.2.1"
19821990source = "registry+https://github.com/rust-lang/crates.io-index"
19831991
1992[[package]]
1993name = "unindent"
1994version = "0.1.6"
1995source = "registry+https://github.com/rust-lang/crates.io-index"
1996
19841997[[package]]
19851998name = "url"
19861999version = "2.1.1"
@@ -2122,7 +2135,7 @@ dependencies = [
21222135[[package]]
21232136name = "weechat"
21242137version = "0.3.1"
2125source = "registry+https://github.com/rust-lang/crates.io-index"
2138source = "git+https://github.com/poljar/rust-weechat#dc47d110249ca823f44c835c3a210fd8a048220e"
21262139dependencies = [
21272140 "async-task 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
21282141 "async-trait 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2132,14 +2145,14 @@ dependencies = [
21322145 "paste 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
21332146 "pipe-channel 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
21342147 "strum 0.19.2 (registry+https://github.com/rust-lang/crates.io-index)",
2135 "weechat-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
2136 "weechat-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
2148 "weechat-macro 0.3.1 (git+https://github.com/poljar/rust-weechat)",
2149 "weechat-sys 0.3.1 (git+https://github.com/poljar/rust-weechat)",
21372150]
21382151
21392152[[package]]
21402153name = "weechat-macro"
21412154version = "0.3.1"
2142source = "registry+https://github.com/rust-lang/crates.io-index"
2155source = "git+https://github.com/poljar/rust-weechat#dc47d110249ca823f44c835c3a210fd8a048220e"
21432156dependencies = [
21442157 "libc 0.2.76 (registry+https://github.com/rust-lang/crates.io-index)",
21452158 "proc-macro2 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2153,20 +2166,22 @@ version = "0.1.0"
21532166dependencies = [
21542167 "async-std 1.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
21552168 "async-trait 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
2169 "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
21562170 "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
2171 "indoc 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
21572172 "matrix-sdk 0.1.0 (git+https://github.com/matrix-org/matrix-rust-sdk/)",
21582173 "tokio 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
21592174 "tracing 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
21602175 "tracing-subscriber 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
21612176 "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
21622177 "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
2163 "weechat 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
2178 "weechat 0.3.1 (git+https://github.com/poljar/rust-weechat)",
21642179]
21652180
21662181[[package]]
21672182name = "weechat-sys"
21682183version = "0.3.1"
2169source = "registry+https://github.com/rust-lang/crates.io-index"
2184source = "git+https://github.com/poljar/rust-weechat#dc47d110249ca823f44c835c3a210fd8a048220e"
21702185dependencies = [
21712186 "bindgen 0.55.1 (registry+https://github.com/rust-lang/crates.io-index)",
21722187 "libc 0.2.76 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2344,6 +2359,7 @@ dependencies = [
23442359"checksum hyper-tls 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed"
23452360"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
23462361"checksum indexmap 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a3566dd4fd4eec714ae6ceabdee0caec795be835c223d92c2d40f1e8cf1c"
2362"checksum indoc 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644defcefee68d7805653a682e99a2e2a5014a1fc3cc9be7059a215844eeea6f"
23472363"checksum instant 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
23482364"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
23492365"checksum ipnet 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135"
@@ -2478,6 +2494,7 @@ dependencies = [
24782494"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
24792495"checksum unicode-width 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
24802496"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
2497"checksum unindent 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "af41d708427f8fd0e915dcebb2cae0f0e6acb2a939b2d399c265c39a38a18942"
24812498"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
24822499"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
24832500"checksum vcpkg 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
@@ -2496,9 +2513,9 @@ dependencies = [
24962513"checksum wasm-bindgen-macro-support 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556"
24972514"checksum wasm-bindgen-shared 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092"
24982515"checksum web-sys 0.3.44 (registry+https://github.com/rust-lang/crates.io-index)" = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47"
2499"checksum weechat 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9347ef4aec950d94e5e2628cd9a7f5359c7ebb5c488f5a820a3e20bf7d114bcd"
2500"checksum weechat-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a939b44ce807e5e0dfffdd5df9535e890cc85de95f5c40bd5871575d61397f46"
2501"checksum weechat-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "432d9ec63b71ca962fa9df527d5eabd175bf1b484960fc090e341116fb4db133"
2516"checksum weechat 0.3.1 (git+https://github.com/poljar/rust-weechat)" = "<none>"
2517"checksum weechat-macro 0.3.1 (git+https://github.com/poljar/rust-weechat)" = "<none>"
2518"checksum weechat-sys 0.3.1 (git+https://github.com/poljar/rust-weechat)" = "<none>"
25022519"checksum wepoll-sys-stjepang 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694"
25032520"checksum which 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
25042521"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
Cargo.toml +3 −1
@@ -18,9 +18,11 @@ async-std = { version = "1.6.3", features = [ "unstable" ] }
1818clap = "2.33.3"
1919async-trait = "0.1.40"
2020uuid = { version = "0.8.1", features = ["v4"] }
21indoc = "1.0.2"
22chrono = "0.4.15"
2123
2224[dependencies.weechat]
23version = "0.3.1"
25git = "https://github.com/poljar/rust-weechat"
2426features = ["async", "config_macro"]
2527
2628[dependencies.matrix-sdk]
Makefile +3 −1
@@ -1,9 +1,11 @@
11WEECHAT_HOME ?= $(HOME)/.weechat
22PREFIX ?= $(WEECHAT_HOME)
33
4SOURCES := $(wildcard src/*.rs src/commands/*.rs)
5
46.PHONY: install install-dir lint
57
6target/debug/libmatrix.so: src/lib.rs src/server.rs src/room_buffer.rs src/commands/mod.rs src/config.rs
8target/debug/libmatrix.so: $(SOURCES)
79 cargo build
810
911install: install-dir target/debug/libmatrix.so
src/commands/devices.rs added +105
@@ -0,0 +1,105 @@
1use clap::{
2 App as Argparse, AppSettings as ArgParseSettings, Arg,
3 SubCommand,
4};
5
6use weechat::{
7 buffer::Buffer,
8 hooks::{Command, CommandCallback, CommandSettings},
9 Args, Weechat,
10};
11
12use crate::Servers;
13
14pub struct DevicesCommand {
15 servers: Servers,
16}
17
18impl DevicesCommand {
19 pub fn create(servers: &Servers) -> Result<Command, ()> {
20 let settings = CommandSettings::new("devices")
21 .description("List, delete or rename Matrix devices.")
22 .add_argument("list")
23 .add_argument("delete <device-id>")
24 .add_argument("set-name <device-id> <name>")
25 .arguments_description(
26 "device-id: The unique id of the device that should be deleted.
27 name:
28 ",
29 )
30 .add_completion("list")
31 .add_completion("delete %(matrix-own-devices)")
32 .add_completion("set-name %(matrix-own-devices)")
33 .add_completion("help list|delete|set-name");
34
35 Command::new(
36 settings,
37 DevicesCommand {
38 servers: servers.clone(),
39 },
40 )
41 }
42
43 fn list(&self, buffer: &Buffer) {
44 let server = self.servers.find_server(buffer);
45
46 if let Some(s) = server {
47 let devices = || async move {
48 s.devices().await;
49 };
50 Weechat::spawn(devices());
51 } else {
52 Weechat::print("Must be executed on Matrix buffer")
53 }
54 }
55}
56
57impl CommandCallback for DevicesCommand {
58 fn callback(
59 &mut self,
60 _: &Weechat,
61 buffer: &Buffer,
62 arguments: Args,
63 ) {
64 let argparse = Argparse::new("devices")
65 .global_setting(ArgParseSettings::DisableHelpFlags)
66 .global_setting(ArgParseSettings::DisableVersion)
67 .global_setting(ArgParseSettings::VersionlessSubcommands)
68 .setting(ArgParseSettings::SubcommandRequiredElseHelp)
69 .subcommand(
70 SubCommand::with_name("list")
71 .about("List your own Matrix devices on the server."),
72 )
73 .subcommand(
74 SubCommand::with_name("delete")
75 .about("Delete the given device")
76 .arg(Arg::with_name("device-id").required(true)),
77 )
78 .subcommand(
79 SubCommand::with_name("set-name")
80 .about("Set the human readable name of the given device")
81 .arg(Arg::with_name("device-id").required(true))
82 .arg(Arg::with_name("name").required(true))
83 );
84
85 let matches = match argparse.get_matches_from_safe(arguments) {
86 Ok(m) => m,
87 Err(e) => {
88 Weechat::print(
89 &Weechat::execute_modifier(
90 "color_decode_ansi",
91 "1",
92 &e.to_string(),
93 )
94 .unwrap(),
95 );
96 return;
97 }
98 };
99
100 match matches.subcommand() {
101 ("list", _) => self.list(buffer),
102 _ => Weechat::print(&format!("{}Subcommand isn't implemented", Weechat::prefix("error"))),
103 }
104 }
105}
src/commands/matrix.rs +2 −4
@@ -4,15 +4,14 @@ use clap::{
44};
55use url::Url;
66
7use crate::PLUGIN_NAME;
8
9use crate::{config::ConfigHandle, MatrixServer, Servers};
107use weechat::{
118 buffer::Buffer,
129 hooks::{Command, CommandCallback, CommandSettings},
1310 Args, Weechat,
1411};
1512
13use crate::{PLUGIN_NAME, config::ConfigHandle, MatrixServer, Servers};
14
1615pub struct MatrixCommand {
1716 servers: Servers,
1817 config: ConfigHandle,
@@ -250,7 +249,6 @@ impl CommandCallback for MatrixCommand {
250249
251250 let argparse = Argparse::new("matrix")
252251 .about("Matrix chat protocol command.")
253 // .global_setting(ArgParseSettings::ColorNever)
254252 .global_setting(ArgParseSettings::DisableHelpFlags)
255253 .global_setting(ArgParseSettings::DisableVersion)
256254 .global_setting(ArgParseSettings::VersionlessSubcommands)
src/commands/mod.rs +4
@@ -1,12 +1,15 @@
11use crate::{config::ConfigHandle, Servers};
22use weechat::hooks::Command;
33
4mod devices;
45mod matrix;
56
7use devices::DevicesCommand;
68use matrix::MatrixCommand;
79
810pub struct Commands {
911 _matrix: Command,
12 _devices: Command,
1013}
1114
1215impl Commands {
@@ -16,6 +19,7 @@ impl Commands {
1619 ) -> Result<Commands, ()> {
1720 Ok(Commands {
1821 _matrix: MatrixCommand::create(servers, config)?,
22 _devices: DevicesCommand::create(servers)?,
1923 })
2024 }
2125}
src/lib.rs +11 −2
@@ -19,7 +19,10 @@ use weechat::{
1919 plugin, Args, Plugin, ReturnCode, Weechat,
2020};
2121
22use crate::{commands::Commands, config::ConfigHandle, server::MatrixServer, room_buffer::RoomBuffer};
22use crate::{
23 commands::Commands, config::ConfigHandle, room_buffer::RoomBuffer,
24 server::MatrixServer,
25};
2326
2427const PLUGIN_NAME: &str = "matrix";
2528
@@ -47,9 +50,15 @@ impl Servers {
4750 let servers = self.borrow();
4851
4952 for server in servers.values() {
53 if let Some(b) = &*server.inner().server_buffer() {
54 if b.upgrade().map_or(false, |b| &b == buffer) {
55 return Some(server.clone());
56 }
57 }
58
5059 for room_buffer in server.inner().room_buffers.values() {
5160 if buffer == &room_buffer.weechat_buffer() {
52 return Some(server.clone())
61 return Some(server.clone());
5362 }
5463 }
5564 }
src/room_buffer.rs +4 −4
@@ -106,10 +106,6 @@ impl BufferInputCallbackAsync for MatrixRoom {
106106 async fn callback(&mut self, buffer: BufferHandle, input: String) {
107107 let connection = &self.connection;
108108
109 let buffer = buffer
110 .upgrade()
111 .expect("Running input cb but buffer is closed");
112
113109 if let Some(c) = &*connection.borrow() {
114110 // TODO check for errors and print them out.
115111 match c.send_message(&self.room_id, input).await {
@@ -117,6 +113,10 @@ impl BufferInputCallbackAsync for MatrixRoom {
117113 Err(_e) => (),
118114 }
119115 } else {
116 let buffer = buffer
117 .upgrade()
118 .expect("Running input cb but buffer is closed");
119
120120 buffer.print("Error not connected");
121121 }
122122 }
src/server.rs +102 −3
@@ -55,6 +55,8 @@
5555//! that processing events will not block the Weechat mainloop for too long.
5656
5757use async_std::sync::{channel as async_channel, Receiver, Sender};
58use chrono::{offset::Utc, DateTime};
59use indoc::indoc;
5860use std::{
5961 cell::{Ref, RefCell, RefMut},
6062 collections::HashMap,
@@ -72,6 +74,7 @@ use matrix_sdk::api::r0::session::login::Response as LoginResponse;
7274use matrix_sdk::{
7375 self,
7476 api::r0::{
77 device::get_devices::Response as DevicesResponse,
7578 message::send_message_event::Response as RoomSendResponse,
7679 typing::create_typing_event::{Response as TypingResponse, Typing},
7780 },
@@ -167,6 +170,20 @@ impl Connection {
167170 Err(e) => panic!("Tokio error while sending a message {:?}", e),
168171 }
169172 }
173
174 pub async fn devices(&self) -> MatrixResult<DevicesResponse> {
175 let client = self.client.clone();
176 let handle = self
177 .runtime
178 .spawn(async move { client.devices().await })
179 .await;
180
181 match handle {
182 Ok(response) => response,
183 Err(e) => panic!("Tokio error while sending a message {:?}", e),
184 }
185 }
186
170187 pub async fn send_typing_notice(
171188 &self,
172189 room_id: &RoomId,
@@ -257,6 +274,80 @@ impl MatrixServer {
257274 self.inner.borrow()
258275 }
259276
277 pub fn connection(&self) -> Rc<RefCell<Option<Connection>>> {
278 self.inner().connection.clone()
279 }
280
281 pub async fn devices(&self) {
282 let connection = self.connection();
283
284 if let Some(c) = &*connection.borrow() {
285 let response = match c.devices().await {
286 Ok(r) => r,
287 Err(e) => {
288 self.print_error(&format!(
289 "Error fetching devices {:?}",
290 e
291 ));
292 return;
293 }
294 };
295
296 if response.devices.is_empty() {
297 self.print_error("No devices were found for this server");
298 return;
299 }
300
301 self.print_network(&format!(
302 indoc!(
303 "
304 Devices for server {}{}{}:
305 Device ID Device name Last seen
306 "
307 ),
308 Weechat::color("chat_server"),
309 self.name(),
310 Weechat::color("reset")
311 ));
312
313 let lines: Vec<String> = response
314 .devices
315 .iter()
316 .map(|d| {
317 let device_color = Weechat::info_get(
318 "nick_color_name",
319 d.device_id.as_str(),
320 )
321 .expect("Can't get device color");
322
323 let last_seen_date =
324 d.last_seen_ts.map_or("?".to_owned(), |d| {
325 let date: DateTime<Utc> = d.into();
326 date.format("%Y/%m/%d %H:%M").to_string()
327 });
328
329 let last_seen = format!(
330 "{} @ {}",
331 d.last_seen_ip.as_deref().unwrap_or("-"),
332 last_seen_date
333 );
334
335 format!(
336 " {}{:<15}{}{:<30}{:<}",
337 Weechat::color(&device_color),
338 d.device_id.as_str(),
339 Weechat::color("reset"),
340 d.display_name.as_deref().unwrap_or(""),
341 last_seen,
342 )
343 })
344 .collect();
345
346 let line = lines.join("\n");
347 self.print_network(&line);
348 };
349 }
350
260351 /// Parse an URL returning a None if the string is empty.
261352 ///
262353 /// # Panics
@@ -868,7 +959,12 @@ impl InnerServer {
868959 buffer_handle
869960 }
870961
871 pub fn server_buffer<'a>(
962 /// Borrow the server buffer handle.
963 pub fn server_buffer(&self) -> Ref<Option<BufferHandle>> {
964 self.server_buffer.borrow()
965 }
966
967 fn get_or_create_buffer<'a>(
872968 &self,
873969 server_buffer: &'a mut RefMut<Option<BufferHandle>>,
874970 ) -> &'a BufferHandle {
@@ -888,13 +984,16 @@ impl InnerServer {
888984 /// Print a neutral message to the server buffer.
889985 pub fn print(&self, message: &str) {
890986 let mut server_buffer = self.server_buffer.borrow_mut();
891 let buffer = self.server_buffer(&mut server_buffer).upgrade().unwrap();
987 let buffer = self
988 .get_or_create_buffer(&mut server_buffer)
989 .upgrade()
990 .unwrap();
892991 buffer.print(message);
893992 }
894993
895994 /// Print a message with a given prefix to the server buffer.
896995 pub fn print_with_prefix(&self, prefix: &str, message: &str) {
897 self.print(&format!("{}\t{}", prefix, message));
996 self.print(&format!("{}{}", prefix, message));
898997 }
899998
900999 /// Print an network message to the server buffer.