diff --git a/src/vtbackend/Functions.h b/src/vtbackend/Functions.h index cd554af1ce..af45b6fee2 100644 --- a/src/vtbackend/Functions.h +++ b/src/vtbackend/Functions.h @@ -158,6 +158,7 @@ constexpr inline auto SETICON = FunctionDocumentation { .mnemonic = "SETICON", . constexpr inline auto SETTITLE = FunctionDocumentation { .mnemonic = "SETTITLE", .comment = "Change Window & Icon Title" }; constexpr inline auto SETWINTITLE = FunctionDocumentation { .mnemonic = "SETWINTITLE", .comment = "Change Window Title" }; constexpr inline auto SETXPROP = FunctionDocumentation { .mnemonic = "SETXPROP", .comment = "Set X11 property" }; +constexpr inline auto SCREENSHOT = FunctionDocumentation { .mnemonic = "SCREENSHOT", .comment = "Screenshot of the screen" }; } // namespace documentation @@ -621,6 +622,7 @@ constexpr inline auto SETICON = detail::OSC(1, VTExtension::XTerm, doc constexpr inline auto SETTITLE = detail::OSC(0, VTExtension::XTerm, documentation::SETTITLE); constexpr inline auto SETWINTITLE = detail::OSC(2, VTExtension::XTerm, documentation::SETWINTITLE); constexpr inline auto SETXPROP = detail::OSC(3, VTExtension::XTerm, documentation::SETXPROP); +constexpr inline auto SCREENSHOT = detail::OSC(533, VTExtension::Contour, documentation::SCREENSHOT); constexpr inline auto CaptureBufferCode = 314; @@ -754,6 +756,7 @@ constexpr static auto allFunctionsArray() noexcept SETTITLE, SETWINTITLE, SETXPROP, + SCREENSHOT, SETCOLPAL, SETCWD, HYPERLINK, diff --git a/src/vtbackend/Screen.cpp b/src/vtbackend/Screen.cpp index d085dbaa47..19e0fbdf87 100644 --- a/src/vtbackend/Screen.cpp +++ b/src/vtbackend/Screen.cpp @@ -34,6 +34,8 @@ #include #include +#include "vtbackend/primitives.h" + #if defined(_WIN32) #include #endif @@ -3703,6 +3705,35 @@ ApplyResult Screen::apply(Function const& function, Sequence const& seq) case SETICON: return ApplyResult::Ok; // NB: Silently ignore! case SETWINTITLE: _terminal->setWindowTitle(seq.intermediateCharacters()); break; case SETXPROP: return ApplyResult::Unsupported; + case SCREENSHOT: { + auto coords = seq.intermediateCharacters(); + // format: top;left;bottom;right + auto splitted = crispy::split(coords, ';'); + auto top = std::stoi(std::string { splitted[0] }); + auto left = std::stoi(std::string { splitted[1] }); + auto bottom = std::stoi(std::string { splitted[2] }); + auto right = std::stoi(std::string { splitted[3] }); + + // OSC 533 ; top ; left ; lines ; columns ; format ; Pt ST + std::string answer; + auto out = std::back_inserter(answer); + std::format_to( + out, "{};{};{};{};{};Pt", top, left, bottom - top, right - left, "plain text"); + + for (auto indexRow = top; indexRow <= bottom; ++indexRow) + { + for (auto indexColumn = left; indexColumn <= right; ++indexColumn) + { + auto& cell = at(LineOffset { indexRow }, ColumnOffset { indexColumn }); + std::format_to(out, "{}", cell.toUtf8()); + } + std::format_to(out, "\n"); + } + std::cout << std::format("HERE: {} '{}'\n", answer.size(), answer); + answer = std::format("\033]533;{}",answer); + + return ApplyResult::Unsupported; + } case SETCOLPAL: return impl::SETCOLPAL(seq, *_terminal); case RCOLPAL: return impl::RCOLPAL(seq, *_terminal); case SETCWD: return impl::SETCWD(seq, *this); @@ -3761,6 +3792,7 @@ unique_ptr Screen::hookSixel(Sequence const& seq) case 4: case 3: return 3; case 2: return 5; + case 1: case 0: return 2; default: return 1;