Rain пре 5 месеци
родитељ
комит
1a774ae3e5
3 измењених фајлова са 34 додато и 1 уклоњено
  1. 1 0
      client/Cargo.toml
  2. 2 1
      client/src/actions.rs
  3. 31 0
      client/src/ui.rs

+ 1 - 0
client/Cargo.toml

@@ -9,6 +9,7 @@ utils = { path = "../utils" }
 logging = { path = "../logging" }
 
 cursive = "0.21"
+cli-clipboard = "0.4.0"
 
 # TODO: Write an HTTP client.
 reqwest = { version = "0.12.15", features = [ "blocking" ] }

+ 2 - 1
client/src/actions.rs

@@ -14,9 +14,10 @@ pub fn on_message_click(siv: &mut Cursive, message_id: &str) {
     let message = appdata.messages.get(message_id);
 
     if let Some(message) = message {
-        ui::alert(
+        ui::copyable(
             siv,
             ui::Labels::Message.localize(appdata.language),
+            // TODO: Use labels
             format!(
                 "Time: {}\nChannel: {}\nSender: {}\nContent: {}",
                 message.time, message.channel, message.sender, message.content

+ 31 - 0
client/src/ui.rs

@@ -1,3 +1,4 @@
+use cli_clipboard::ClipboardProvider as _;
 use cursive::view::{Nameable as _, Resizable as _};
 use cursive::views::{
     Button, Dialog, DummyView, EditView, LinearLayout, NamedView, Panel, ScrollView, SelectView,
@@ -44,6 +45,7 @@ pub enum Labels {
     Ok,
     Cancel,
     Close,
+    Copy,
     Submit,
     Send,
     New,
@@ -92,6 +94,7 @@ impl Labels {
             Labels::Ok => ["OK", "OK", "OK"],
             Labels::Cancel => ["Cancel", "Annuleren", "キャンセル"],
             Labels::Close => ["Close", "Sluiten", "閉じる"],
+            Labels::Copy => ["Copy", "Kopiëren", "コピー"],
             Labels::Error => ["Error", "Fout", "エラー"],
             Labels::User => ["User", "Gebruiker", "ユーザー"],
             Labels::Messages => ["Messages", "Berichten", "メッセージ"],
@@ -304,6 +307,34 @@ where
     );
 }
 
+pub fn copyable<S>(siv: &mut Cursive, title: S, text: S)
+where
+    S: Into<String> + Clone,
+{
+    let language = get_appdata(siv).language;
+
+    keybind_setup_close_once(siv);
+
+    let text_s = text.clone().into();
+    siv.add_layer(
+        Dialog::text(text)
+            .title(title)
+            .button(Labels::Copy.localize(language), move |siv| {
+
+                let ctx = cli_clipboard::ClipboardContext::new();
+                if ctx.and_then(|mut x| x.set_contents(text_s.clone())).is_err() {
+                    logging::error("Failed to copy text to clipboard.");
+                }
+
+                keybind_close_manual_end(siv, false);
+            })
+            .button(Labels::Close.localize(language), |siv| {
+                keybind_close_manual_end(siv, false);
+            })
+            .min_size((20, 5)),
+    );
+}
+
 pub fn error<S>(siv: &mut Cursive, text: S)
 where
     S: Into<String>,