Repository: microsoft/terminal
File: src/host/screenInfo.hpp (C++)

Code before:

#include "../renderer/inc/FontInfo.hpp"
#include "../renderer/inc/FontInfoDesired.hpp"

#include "../types/inc/Viewport.hpp"
class ConversionAreaInfo; // forward decl window. circular reference

class SCREEN_INFORMATION : public ConsoleObjectHeader, public Microsoft::Console::IIoProvider
{
public:
    // This little helper works like wil::scope_exit but is slimmer
    // (= easier to optimize) and has a concrete type (= can declare).
    struct SnapOnScopeExit
    {
        ~SnapOnScopeExit()
        {
            if (self)
            {
                self->_makeCursorVisible();
            }
        }

        SCREEN_INFORMATION* self;
    };

    [[nodiscard]] static NTSTATUS CreateInstance(_In_ til::size coordWindowSize,
                                                 const FontInfo fontInfo,
                                                 _In_ til::size coordScreenBufferSize,
                                                 const TextAttribute defaultAttributes,
                                                 const TextAttribute popupAttributes,
                                                 const UINT uiCursorSize,
                                                 _Outptr_ SCREEN_INFORMATION** const ppScreen);

    ~SCREEN_INFORMATION();

    void GetScreenBufferInformation(_Out_ til::size* pcoordSize,
                                    _Out_ til::point* pcoordCursorPosition,
                                    _Out_ til::inclusive_rect* psrWindow,
                                    _Out_ PWORD pwAttributes,
                                    _Out_ til::size* pcoordMaximumWindowSize,
                                    _Out_ PWORD pwPopupAttributes,
                                    _Out_writes_(COLOR_TABLE_SIZE) LPCOLORREF lpColorTable) const;

    void GetRequiredConsoleSizeInPixels(_Out_ til::size* const pRequiredSize) const;

    void MakeCurrentCursorVisible();
    void MakeCursorVisible(til::point position);
    void SnapOnInput(WORD vkey);
    SnapOnScopeExit SnapOnOutput() noexcept;

    void ClipToScreenBuffer(_Inout_ til::inclusive_rect* const psrClip) const;

Review comment (bug):
```suggestion

        void release()
        {
            self = nullptr;
        }

```

Code after:

#include "../renderer/inc/FontInfo.hpp"
#include "../renderer/inc/FontInfoDesired.hpp"

#include "../types/inc/Viewport.hpp"
class ConversionAreaInfo; // forward decl window. circular reference

class SCREEN_INFORMATION : public ConsoleObjectHeader, public Microsoft::Console::IIoProvider
{
public:
    // This little helper works like wil::scope_exit but is slimmer
    // (= easier to optimize) and has a concrete type (= can declare).
    struct SnapOnScopeExit
    {
        ~SnapOnScopeExit()
        {
            if (self)
            {
                try
                {
                    self->_makeCursorVisible();
                }
                CATCH_LOG();
            }
        }

        SCREEN_INFORMATION* self;
    };

    [[nodiscard]] static NTSTATUS CreateInstance(_In_ til::size coordWindowSize,
                                                 const FontInfo fontInfo,
                                                 _In_ til::size coordScreenBufferSize,
                                                 const TextAttribute defaultAttributes,
                                                 const TextAttribute popupAttributes,
                                                 const UINT uiCursorSize,
                                                 _Outptr_ SCREEN_INFORMATION** const ppScreen);

    ~SCREEN_INFORMATION();

    void GetScreenBufferInformation(_Out_ til::size* pcoordSize,
                                    _Out_ til::point* pcoordCursorPosition,
                                    _Out_ til::inclusive_rect* psrWindow,
                                    _Out_ PWORD pwAttributes,
                                    _Out_ til::size* pcoordMaximumWindowSize,
                                    _Out_ PWORD pwPopupAttributes,
                                    _Out_writes_(COLOR_TABLE_SIZE) LPCOLORREF lpColorTable) const;

    void GetRequiredConsoleSizeInPixels(_Out_ til::size* const pRequiredSize) const;

    void MakeCurrentCursorVisible();
    void MakeCursorVisible(til::point position);