|
@@ -1,3 +1,4 @@
|
|
|
|
|
+use cli_clipboard::ClipboardProvider as _;
|
|
|
use cursive::view::{Nameable as _, Resizable as _};
|
|
use cursive::view::{Nameable as _, Resizable as _};
|
|
|
use cursive::views::{
|
|
use cursive::views::{
|
|
|
Button, Dialog, DummyView, EditView, LinearLayout, NamedView, Panel, ScrollView, SelectView,
|
|
Button, Dialog, DummyView, EditView, LinearLayout, NamedView, Panel, ScrollView, SelectView,
|
|
@@ -44,6 +45,7 @@ pub enum Labels {
|
|
|
Ok,
|
|
Ok,
|
|
|
Cancel,
|
|
Cancel,
|
|
|
Close,
|
|
Close,
|
|
|
|
|
+ Copy,
|
|
|
Submit,
|
|
Submit,
|
|
|
Send,
|
|
Send,
|
|
|
New,
|
|
New,
|
|
@@ -92,6 +94,7 @@ impl Labels {
|
|
|
Labels::Ok => ["OK", "OK", "OK"],
|
|
Labels::Ok => ["OK", "OK", "OK"],
|
|
|
Labels::Cancel => ["Cancel", "Annuleren", "キャンセル"],
|
|
Labels::Cancel => ["Cancel", "Annuleren", "キャンセル"],
|
|
|
Labels::Close => ["Close", "Sluiten", "閉じる"],
|
|
Labels::Close => ["Close", "Sluiten", "閉じる"],
|
|
|
|
|
+ Labels::Copy => ["Copy", "Kopiëren", "コピー"],
|
|
|
Labels::Error => ["Error", "Fout", "エラー"],
|
|
Labels::Error => ["Error", "Fout", "エラー"],
|
|
|
Labels::User => ["User", "Gebruiker", "ユーザー"],
|
|
Labels::User => ["User", "Gebruiker", "ユーザー"],
|
|
|
Labels::Messages => ["Messages", "Berichten", "メッセージ"],
|
|
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)
|
|
pub fn error<S>(siv: &mut Cursive, text: S)
|
|
|
where
|
|
where
|
|
|
S: Into<String>,
|
|
S: Into<String>,
|