From 0d73304750dcf0286048f75a060a8498c3e820e3 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:24:15 +0500 Subject: [PATCH] #273 Fix clipboard forwarding --- src/netxs/console/ansi.hpp | 40 +++++++++++++++++++++++++++------- src/netxs/console/terminal.hpp | 22 +++++++++---------- src/netxs/text/utf.hpp | 31 +++++++++----------------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/netxs/console/ansi.hpp b/src/netxs/console/ansi.hpp index e2293c11f2..a45c8b7b67 100644 --- a/src/netxs/console/ansi.hpp +++ b/src/netxs/console/ansi.hpp @@ -303,6 +303,7 @@ namespace netxs::ansi auto rawdata = view{ data.utf8 }; if (data.kind == mime::disabled) { + auto valid = true; kind = ansi::clip::textonly; // rawdata=mime/size_x/size_y;data if (rawdata.starts_with(ansi::mimeansi)) { rawdata.remove_prefix(ansi::mimeansi.length()); kind = mime::ansitext; } @@ -312,21 +313,44 @@ namespace netxs::ansi else if (rawdata.starts_with(ansi::mimesafe)) { rawdata.remove_prefix(ansi::mimesafe.length()); kind = mime::safetext; } else { - rawdata = {}; + valid = faux; + kind = mime::textonly; + auto pos = rawdata.find(';'); + if (pos != text::npos) + { + rawdata = rawdata.substr(pos + 1); + } + else rawdata = {}; } - if (rawdata.size()) + if (valid && rawdata.size()) { - rawdata.remove_prefix(1); - if (auto v = utf::to_int(rawdata)) + if (rawdata.front() == '/') // Proceed preview size if present. { - size.x = std::abs(v.value()); rawdata.remove_prefix(1); if (auto v = utf::to_int(rawdata)) { - size.y = std::abs(v.value()); - if (rawdata.size()) rawdata.remove_prefix(1); + static constexpr auto max_value = twod{ 2000, 1000 }; //todo unify + size.x = v.value(); + if (rawdata.size()) + { + rawdata.remove_prefix(1); + if (auto v = utf::to_int(rawdata)) + { + size.y = v.value(); + } + else size.x = 0; + } + size = std::clamp(size, dot_00, max_value); } - else size.x = 0; + } + if (rawdata.size() && rawdata.front() == ';') + { + rawdata.remove_prefix(1); + } + else // Unknown format. + { + size = {}; + rawdata = {}; } } } diff --git a/src/netxs/console/terminal.hpp b/src/netxs/console/terminal.hpp index c8588d81ec..63d06034ff 100644 --- a/src/netxs/console/terminal.hpp +++ b/src/netxs/console/terminal.hpp @@ -5368,11 +5368,6 @@ namespace netxs::ui dnbox.move({ 0, y_end + 1 }); dest.plot(upbox, cell::shaders::full); dest.plot(dnbox, cell::shaders::full); - //test - //auto temp = ansi::esc{}; - //auto mark = cell{}; - //temp.s11n(dest, mark); - //owner.forward_clipboard(temp); } // scroll_buf: Materialize selection of the scrollbuffer part. void selection_pickup(ansi::esc& yield, si32 selmod) @@ -6040,20 +6035,23 @@ namespace netxs::ui vtty ptycon; // term: PTY device. Should be destroyed first. // term: Forward clipboard data (OSC 52). - template void forward_clipboard(view data) { - // Take all foci. auto gates = e2::form::state::keybd::enlist.param(); - SIGNAL(tier::anycast, e2::form::state::keybd::enlist, gates); - // Signal them to set the clipboard data. - for (auto gate_id : gates) + SIGNAL(tier::anycast, e2::form::state::keybd::enlist, gates); // Take all foci. + for (auto gate_id : gates) // Signal them to set the clipboard data. { if (auto ptr = bell::getref(gate_id)) if (auto gear_ptr = std::dynamic_pointer_cast(ptr)) { - if constexpr (Decode) gear_ptr->set_clip_data(clip{ target->panel, utf::unbase64(data), clip::disabled }); - else gear_ptr->set_clip_data(clip{ target->panel, data, clip::ansitext }); + auto pos = data.find(';'); + if (pos != text::npos) + { + auto utf8 = text{}; + utf8 += data.substr(0, ++pos); + utf8 += utf::unbase64(data.substr(pos)); + gear_ptr->set_clip_data(clip{ target->panel, utf8, clip::disabled }); + } } } } diff --git a/src/netxs/text/utf.hpp b/src/netxs/text/utf.hpp index 76655242d6..60f9cc36ac 100644 --- a/src/netxs/text/utf.hpp +++ b/src/netxs/text/utf.hpp @@ -1263,16 +1263,10 @@ namespace netxs::utf auto pos = 0_sz; while ((pos = utf8.find(delimiter, cur)) != V1::npos) { - if constexpr (Plain) - { - proc(view{ utf8.data() + cur, pos - cur }); - cur = pos + 1; - } - else - { - if (!proc(view{ utf8.data() + cur, pos - cur })) return; - cur = pos + 1; - } + auto frag = view{ utf8.data() + cur, pos - cur }; + if constexpr (Plain) proc(frag); + else if (!proc(frag)) return; + cur = pos + 1; } auto end = view{ utf8.data() + cur, utf8.size() - cur }; proc(end); @@ -1281,18 +1275,13 @@ namespace netxs::utf { auto cur = utf8.size(); auto pos = utf8.size(); - while ((pos = utf8.rfind(delimiter, cur)) != V1::npos) + while (cur && (pos = utf8.rfind(delimiter, cur - 1)) != V1::npos) { - if constexpr (Plain) - { - proc(view{ utf8.data() + pos + 1, cur }); - cur = pos; - } - else - { - if (!proc(view{ utf8.data() + pos + 1, cur })) return; - cur = pos; - } + auto next = pos + 1; + auto frag = view{ utf8.data() + next, cur - next }; + if constexpr (Plain) proc(frag); + else if (!proc(frag)) return; + cur = pos; } auto end = view{ utf8.data(), cur }; proc(end);