size_t CommandLine::DrawPrompt() { const auto PromptList = GetPrompt(); const size_t MaxLength = PromptSize*ObjWidth() / 100; std::vector<size_t> Sizes; Sizes.reserve(PromptList.size()); size_t PromptLength = 0; size_t FixedLength = 0; size_t CollapsibleCount = 0; for (const auto& i: PromptList) { Sizes.emplace_back(i.Text.size()); PromptLength += i.Text.size(); if (i.Collapsible) ++CollapsibleCount; else FixedLength += i.Text.size(); } size_t CollapsibleItemLength = 0; bool TryCollapse = false; if (PromptLength > MaxLength) { if (CollapsibleCount) { if (FixedLength < MaxLength) CollapsibleItemLength = (MaxLength - FixedLength) / CollapsibleCount; TryCollapse = true; } } size_t CurLength = 0; GotoXY(m_X1, m_Y1); for (const auto& i: PromptList) { auto str = i.Text; if (TryCollapse && i.Collapsible) { TruncPathStr(str, static_cast<int>(CollapsibleItemLength)); } if (CurLength + str.size() > MaxLength) TruncPathStr(str, std::max(0, static_cast<int>(MaxLength - CurLength))); SetColor(i.Colour); Text(str); CurLength += str.size(); if (CurLength >= MaxLength) break; } return CurLength; }
void CommandLine::DisplayObject() { _OT(SysLog(L"[%p] CommandLine::DisplayObject()",this)); auto PromptList = GetPrompt(); size_t MaxLength = PromptSize*ObjWidth()/100; size_t CurLength = 0; GotoXY(X1,Y1); std::for_each(CONST_RANGE(PromptList, i) { SetColor(i.second); string str(i.first); if(CurLength + str.size() > MaxLength) TruncPathStr(str, std::max(0, static_cast<int>(MaxLength - CurLength))); Text(str); CurLength += str.size(); });