Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/TrayIcon.cpp (C++)

Code before:
        mi.cbSize = sizeof(MENUINFO);
        mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS | MIM_MENUDATA;
        mi.dwStyle = MNS_NOTIFYBYPOS;
        mi.dwMenuData = NULL;
        SetMenuInfo(hMenu, &mi);

        // Focus Current Terminal Window
        AppendMenu(hMenu, MF_STRING, gsl::narrow<UINT_PTR>(TrayMenuItemAction::FocusTerminal), RS_(L"TrayIconFocusTerminal").c_str());
        AppendMenu(hMenu, MF_SEPARATOR, 0, L"");

        // Submenu for Windows
        if (auto submenu = CreatePopupMenu())
        {
            for (const auto& p : peasants)
            {
                winrt::hstring displayText{ fmt::format(L"#{} : ", p.Id) };

                if (!p.TabTitle.empty())
                {
                    displayText = fmt::format(L"{} {}", displayText, p.TabTitle);
                }

                if (!p.Name.empty())
                {
                    displayText = fmt::format(L"{} [{}]", displayText, p.Name);
                }

                AppendMenu(submenu, MF_STRING, gsl::narrow<UINT_PTR>(p.Id), displayText.c_str());
            }

            MENUINFO submenuInfo{};
            submenuInfo.cbSize = sizeof(MENUINFO);
            submenuInfo.fMask = MIM_MENUDATA;
            submenuInfo.dwStyle = MNS_NOTIFYBYPOS;
            submenuInfo.dwMenuData = (UINT_PTR)TrayMenuItemAction::SummonWindow;
            SetMenuInfo(submenu, &submenuInfo);

            AppendMenu(hMenu, MF_POPUP, (UINT_PTR)submenu, RS_(L"TrayIconWindowSubmenu").c_str());
        }
    }
    return hMenu;
}

// Method Description:
// - This is the handler for when one of the menu items are selected within
//   the tray icon's context menu.
// Arguments:
// - menu: The handle to the menu that holds the menu item that was selected.
// - menuItemIndex: The index of the menu item within the given menu.
// Return Value:
// - <none>

Review comment (suggestion):
`fmt` has a large binary size overhead and this code looks like it's building a string incrementally.
So it sounds like good ol' `std::wstringstream` might be a better fit here.

Alternatively you can also calculate your paddings yourself...
```cpp
static constexpr auto choose = [](const auto& str, const std::wstring_view& padding) {
	return str.empty() ? {} : padding;
};

fmt::format(
	L"#{} {:^{}}{}{}{}",
	p.Id,
	p.TabTitle,
	p.TabTitle.empty() ? 0 : p.TabTitle.size() + 2,
	p.Name.empty() ? : L"" : L"[",
	p.Name,
	p.Name.empty() ? : L"" : L"]"
);
```

I'm not sure which of the two is better, but I believe the current code isn't using `fmt` as it's intended. A `std::wstringstream` might be easier to understand though...

Code after:
        mi.cbSize = sizeof(MENUINFO);
        mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS | MIM_MENUDATA;
        mi.dwStyle = MNS_NOTIFYBYPOS;
        mi.dwMenuData = NULL;
        SetMenuInfo(hMenu, &mi);

        // Focus Current Terminal Window
        AppendMenu(hMenu, MF_STRING, gsl::narrow<UINT_PTR>(TrayMenuItemAction::FocusTerminal), RS_(L"TrayIconFocusTerminal").c_str());
        AppendMenu(hMenu, MF_SEPARATOR, 0, L"");

        // Submenu for Windows
        if (auto submenu = CreatePopupMenu())
        {
            for (const auto& p : peasants)
            {
                std::wstringstream displayText;
                displayText << L"#" << p.Id;

                if (!p.TabTitle.empty())
                {
                    displayText << L": " << std::wstring_view{ p.TabTitle };
                }

                if (!p.Name.empty())
                {
                    displayText << L" [" << std::wstring_view{ p.Name } << L"]";
                }

                AppendMenu(submenu, MF_STRING, gsl::narrow<UINT_PTR>(p.Id), displayText.str().c_str());
            }

            MENUINFO submenuInfo{};
            submenuInfo.cbSize = sizeof(MENUINFO);
            submenuInfo.fMask = MIM_MENUDATA;
            submenuInfo.dwStyle = MNS_NOTIFYBYPOS;
            submenuInfo.dwMenuData = (UINT_PTR)TrayMenuItemAction::SummonWindow;
            SetMenuInfo(submenu, &submenuInfo);

            AppendMenu(hMenu, MF_POPUP, (UINT_PTR)submenu, RS_(L"TrayIconWindowSubmenu").c_str());
        }
    }
    return hMenu;
}

// Method Description:
// - This is the handler for when one of the menu items are selected within
//   the tray icon's context menu.
// Arguments:
// - menu: The handle to the menu that holds the menu item that was selected.
// - menuItemIndex: The index of the menu item within the given menu.
// Return Value: