|
6 | 6 |
|
7 | 7 | #include <til/unicode.h>
|
8 | 8 |
|
| 9 | +#include "directio.h" |
9 | 10 | #include "handle.h" // LockConsole
|
10 | 11 | #include "output.h" // CloseConsoleProcessState
|
11 | 12 | #include "../interactivity/inc/ServiceLocator.hpp"
|
@@ -790,3 +791,51 @@ void VtIo::Writer::WriteInfos(til::point target, std::span<const CHAR_INFO> info
|
790 | 791 | } while (--repeat);
|
791 | 792 | }
|
792 | 793 | }
|
| 794 | + |
| 795 | +void VtIo::Writer::WriteScreenInfo(SCREEN_INFORMATION& newContext, til::size oldSize) const |
| 796 | +{ |
| 797 | + const auto area = static_cast<size_t>(oldSize.width * oldSize.height); |
| 798 | + |
| 799 | + auto& main = newContext.GetMainBuffer(); |
| 800 | + auto& alt = newContext.GetActiveBuffer(); |
| 801 | + const auto hasAltBuffer = &alt != &main; |
| 802 | + |
| 803 | + // TODO GH#5094: This could use xterm's XTWINOPS "\e[8;<height>;<width>t" escape sequence here. |
| 804 | + if (oldSize != main.GetBufferSize().Dimensions()) |
| 805 | + { |
| 806 | + THROW_IF_NTSTATUS_FAILED(main.ResizeTraditional(oldSize)); |
| 807 | + main.SetViewportSize(&oldSize); |
| 808 | + } |
| 809 | + if (hasAltBuffer && oldSize != alt.GetBufferSize().Dimensions()) |
| 810 | + { |
| 811 | + THROW_IF_NTSTATUS_FAILED(alt.ResizeTraditional(oldSize)); |
| 812 | + alt.SetViewportSize(&oldSize); |
| 813 | + } |
| 814 | + |
| 815 | + const auto request = Viewport::FromDimensions({}, oldSize); |
| 816 | + Viewport read; |
| 817 | + til::small_vector<CHAR_INFO, 1024> infos; |
| 818 | + infos.resize(area, CHAR_INFO{ L' ', FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED }); |
| 819 | + |
| 820 | + const auto dumpScreenInfo = [&](SCREEN_INFORMATION& screenInfo) { |
| 821 | + THROW_IF_FAILED(ReadConsoleOutputWImplHelper(screenInfo, infos, request, read)); |
| 822 | + for (til::CoordType i = 0; i < oldSize.height; i++) |
| 823 | + { |
| 824 | + WriteInfos({ 0, i }, { infos.begin() + i * oldSize.width, static_cast<size_t>(oldSize.width) }); |
| 825 | + } |
| 826 | + |
| 827 | + WriteCUP(screenInfo.GetTextBuffer().GetCursor().GetPosition()); |
| 828 | + WriteAttributes(screenInfo.GetAttributes()); |
| 829 | + WriteDECTCEM(screenInfo.GetTextBuffer().GetCursor().IsVisible()); |
| 830 | + WriteDECAWM(WI_IsFlagSet(screenInfo.OutputMode, ENABLE_WRAP_AT_EOL_OUTPUT)); |
| 831 | + }; |
| 832 | + |
| 833 | + WriteASB(false); |
| 834 | + dumpScreenInfo(main); |
| 835 | + |
| 836 | + if (hasAltBuffer) |
| 837 | + { |
| 838 | + WriteASB(true); |
| 839 | + dumpScreenInfo(alt); |
| 840 | + } |
| 841 | +} |
0 commit comments