
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <!-- See https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2017#BKMK_Syntax_reference for documentation -->
    <Type Name="TextColor">
        <DisplayString Condition="_meta==ColorType::IsIndex256">{{Index256:{_index}}}</DisplayString>
        <DisplayString Condition="_meta==ColorType::IsIndex16">{{Index16:{_index}}}</DisplayString>
        <DisplayString Condition="_meta==ColorType::IsDefault">{{Default}}</DisplayString>
        <DisplayString Condition="_meta==ColorType::IsRgb">{{RGB:{_red},{_green},{_blue}}}</DisplayString>
        <Expand></Expand>
    </Type>

    <Type Name="TextAttribute">
        <DisplayString Condition="_hyperlinkId == 0">{{FG: {_foreground}, BG: {_background}, Attr: {_attrs}}</DisplayString>
        <DisplayString Condition="_hyperlinkId != 0">{{FG: {_foreground}, BG: {_background}, Attr: {_attrs}, Hyperlink: {_hyperlinkId}}</DisplayString>
    </Type>

    <Type Name="Microsoft::Console::Types::Viewport">
        <!-- Can't call functions in here -->
        <DisplayString>{{LT({_sr.left}, {_sr.top}) RB({_sr.right}, {_sr.bottom}) [{_sr.right-_sr.left+1} x { _sr.bottom-_sr.top+1}]}}</DisplayString>
        <Expand>
            <ExpandedItem>_sr</ExpandedItem>
        </Expand>
    </Type>

    <Type Name="_COORD">
        <DisplayString>{{{X},{Y}}}</DisplayString>
    </Type>

    <Type Name="_SMALL_RECT">
        <DisplayString>{{LT({Left}, {Top}) RB({Right}, {Bottom}) In:[{Right-Left+1} x {Bottom-Top+1}] Ex:[{Right-Left} x {Bottom-Top}]}}</DisplayString>
    </Type>

    <Type Name="ROW">
        <DisplayString>{_chars.data(),[_charOffsets[_columnCount]]}</DisplayString>
        <StringView>_chars.data(),[_charOffsets[_columnCount]]</StringView>
        <Expand>
            <Item Name="_chars">_chars.data(),[_charOffsets[_columnCount]]</Item>
            <Item Name="_charOffsets">_charOffsets.data(),[_charOffsets.size()]</Item>
        </Expand>
    </Type>

    <Type Name="std::unique_ptr&lt;TextBuffer,std::default_delete&lt;TextBuffer&gt;&gt;">
        <Expand>
            <ExpandedItem>_Mypair._Myval2</ExpandedItem>
        </Expand>
    </Type>

    <Type Name="_KEY_EVENT_RECORD">
        <DisplayString Condition="bKeyDown != 0">↓ rep:{wRepeatCount} vk:{wVirtualKeyCode} sc:{wVirtualScanCode} ch:{uChar.UnicodeChar} ctrl:{(unsigned short)dwControlKeyState,x}</DisplayString>
        <DisplayString Condition="bKeyDown == 0">↑ rep:{wRepeatCount} vk:{wVirtualKeyCode} sc:{wVirtualScanCode} ch:{uChar.UnicodeChar} ctrl:{(unsigned short)dwControlKeyState,x}</DisplayString>
    </Type>
    <Type Name="_MOUSE_EVENT_RECORD">
        <DisplayString>pos:{dwMousePosition.X},{dwMousePosition.Y} state:{dwButtonState,x} ctrl:{(unsigned short)dwControlKeyState,x} flags:{(unsigned short)dwEventFlags,x}</DisplayString>
    </Type>
    <Type Name="_WINDOW_BUFFER_SIZE_RECORD">
        <DisplayString>size:{dwSize.X},{dwSize.Y}</DisplayString>
    </Type>
    <Type Name="_MENU_EVENT_RECORD">
        <DisplayString>id:{dwCommandId}</DisplayString>
    </Type>
    <Type Name="_FOCUS_EVENT_RECORD">
        <DisplayString>focus:{bSetFocus}</DisplayString>
    </Type>
    <Type Name="_INPUT_RECORD">
        <DisplayString Condition="EventType == 0x0001">Key {Event.KeyEvent}</DisplayString>
        <DisplayString Condition="EventType == 0x0002">Mouse {Event.MouseEvent}</DisplayString>
        <DisplayString Condition="EventType == 0x0004">WindowBufferSize {Event.WindowBufferSizeEvent}</DisplayString>
        <DisplayString Condition="EventType == 0x0008">Menu {Event.MenuEvent}</DisplayString>
        <DisplayString Condition="EventType == 0x0010">Focus {Event.FocusEvent}</DisplayString>
    </Type>

    <Type Name="til::size">
        <DisplayString>{{W: {width} x H: {height} -> A: {width * height}}}</DisplayString>
    </Type>

    <Type Name="til::point">
        <DisplayString>{{X: {x}, Y: {y}}}</DisplayString>
    </Type>

    <Type Name="til::rect">
        <DisplayString>{{L: {left}, T: {top}, R: {right} B: {bottom}   [W: {right - left} x H: {bottom - top} -> A: {(right - left) * (bottom - top)}]}}</DisplayString>
    </Type>

    <Type Name="til::color">
      <DisplayString>{{RGB: {(int)r,d}, {(int)g,d}, {(int)b,d}; α: {(int)a,d}}}</DisplayString>
    </Type>

    <Type Name="til::rle&lt;*&gt;">
        <DisplayString>{{Size: {_total_length,d}}}</DisplayString>
        <Expand>
            <Item Name="[size]">_total_length</Item>
            <ExpandedItem>_runs</ExpandedItem>
        </Expand>
    </Type>

    <Type Name="til::details::rle_const_iterator&lt;*&gt;">
        <DisplayString>{{run of {_it->first,d} for {_it->second,d} at {_usage,d}}}</DisplayString>
    </Type>

    <Type Name="til::small_vector&lt;*&gt;">
        <DisplayString>{{ size={_size} }}</DisplayString>
        <Expand>
            <Item Name="[capacity]" ExcludeView="simple">_capacity</Item>
            <Item Name="[size]" ExcludeView="simple">_size</Item>
            <ArrayItems>
                <Size>_size</Size>
                <ValuePointer>_data</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>

    <Type Name="til::small_vector_iterator&lt;*&gt;">
        <AlternativeType Name="til::small_vector_const_iterator&lt;*&gt;" />
        <SmartPointer Usage="Indexable">_ptr,na</SmartPointer>
        <Expand>
            <Item Name="[ptr]">_ptr</Item>
        </Expand>
    </Type>

    <Type Name="til::generational&lt;*&gt;">
        <AlternativeType Name="$T1" />
        <SmartPointer Usage="Minimal">&amp;_value</SmartPointer>
        <DisplayString>{{ generation={_generation._value} }}</DisplayString>
    </Type>

    <Type Name="til::linear_flat_set&lt;*,*&gt;">
        <DisplayString>{{ size={_load / $T3} }}</DisplayString>
        <Expand>
            <ArrayItems>
                <Size>_capacity</Size>
                <ValuePointer>_map._Mypair._Myval2</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>

    <Type Name="TextBuffer">
        <DisplayString>{{ width={_width}, height={_height} }}</DisplayString>
        <Expand>
            <Item Name="_firstRow">_firstRow</Item>
            <Item Name="scratchpad">*(ROW*)_buffer.__ptr_.__value_</Item>
            <IndexListItems>
                <Size>(_commitWatermark - _buffer.__ptr_.__value_ - 1) / _bufferRowStride</Size>
                <ValueNode>*(ROW*)(_buffer.__ptr_.__value_ + _bufferRowStride * ($i + 1))</ValueNode>
            </IndexListItems>
        </Expand>
    </Type>

    <Type Name="Microsoft::Console::Render::Atlas::Buffer&lt;*&gt;">
        <DisplayString>{{ size={_size} }}</DisplayString>
        <Expand>
            <Item Name="[size]" ExcludeView="simple">_size</Item>
            <ArrayItems>
                <Size>_size</Size>
                <ValuePointer>_data</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>

    <Type Name="Microsoft::Console::Render::Atlas::ShapedRow">
        <DisplayString>{{ dirtyTop={dirtyTop}, dirtyBottom={dirtyBottom} }}</DisplayString>
    </Type>

    <Type Name="Microsoft::Console::Render::Atlas::BackendD3D::AtlasGlyphEntry">
        <DisplayString Condition="occupied == 0">(empty)</DisplayString>
        <DisplayString Condition="occupied != 0">{glyphIndex}</DisplayString>
    </Type>

    <Type Name="Microsoft::Console::Render::Atlas::BackendD3D::AtlasFontFaceEntry">
        <DisplayString Condition="!fontFace.m_ptr">(empty)</DisplayString>
        <DisplayString Condition="fontFace.m_ptr">{*fontFace.m_ptr}</DisplayString>
        <Expand>
            <Item Name="Single Width" ExcludeView="simple">glyphs[0]</Item>
            <Item Name="Double Width" ExcludeView="simple">glyphs[1]</Item>
            <Item Name="Double Height Top" ExcludeView="simple">glyphs[2]</Item>
            <Item Name="Double Height Bottom" ExcludeView="simple">glyphs[3]</Item>
        </Expand>
    </Type>
</AutoVisualizer>
