Skip to content

Commit

Permalink
#273 Fix clipboard forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 8, 2022
1 parent 2294524 commit 0d73304
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
40 changes: 32 additions & 8 deletions src/netxs/console/ansi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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 = {};
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/netxs/console/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<true, faux, true>(dest, mark);
//owner.forward_clipboard<faux>(temp);
}
// scroll_buf: Materialize selection of the scrollbuffer part.
void selection_pickup(ansi::esc& yield, si32 selmod)
Expand Down Expand Up @@ -6040,20 +6035,23 @@ namespace netxs::ui
vtty ptycon; // term: PTY device. Should be destroyed first.

// term: Forward clipboard data (OSC 52).
template<bool Decode = true>
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<hids>(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 });
}
}
}
}
Expand Down
31 changes: 10 additions & 21 deletions src/netxs/text/utf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0d73304

Please sign in to comment.