sources/interface.cpp

changeset 181
e254398fcc7c
parent 179
7fc34735178e
child 182
20ca0a6be175
equal deleted inserted replaced
180:2e7225dbd9b2 181:e254398fcc7c
165 ::refresh(); 165 ::refresh();
166 ::timeout(0); 166 ::timeout(0);
167 m_inputHistory.clear(); 167 m_inputHistory.clear();
168 m_inputHistory.push_back(""); 168 m_inputHistory.push_back("");
169 m_outputLines.clear(); 169 m_outputLines.clear();
170 m_outputLines << ColoredLine(); 170 m_outputLines.push_back(ColoredLine());
171 m_session.setInterface(this); 171 m_session.setInterface(this);
172 resetTitle(); 172 resetTitle();
173 173
174 if (::has_colors()) 174 if (::has_colors())
175 { 175 {
302 void Interface::renderOutput() 302 void Interface::renderOutput()
303 { 303 {
304 if (m_outputLines.size() == 1) 304 if (m_outputLines.size() == 1)
305 return; 305 return;
306 306
307 m_outputScroll = clamp(m_outputScroll, 0, m_outputLines.size() - 1); 307 m_outputScroll = clamp(m_outputScroll, 0, static_cast<signed>(m_outputLines.size() - 1));
308 308
309 int height = LINES - 3; 309 int height = LINES - 3;
310 int width = COLS - nicklistWidth(); 310 int width = COLS - nicklistWidth();
311 int printOffset = 0; 311 int printOffset = 0;
312 int end = m_outputLines.size() - 1 - m_outputScroll; 312 int end = m_outputLines.size() - 1 - m_outputScroll;
332 } 332 }
333 333
334 // See if there's any more rows to use(end may be too small) 334 // See if there's any more rows to use(end may be too small)
335 if (not tightFit) 335 if (not tightFit)
336 { 336 {
337 while (end < m_outputLines.size()) 337 while (end < static_cast<int>(m_outputLines.size()))
338 { 338 {
339 int rows = m_outputLines[end].rows(width); 339 int rows = m_outputLines[end].rows(width);
340 340
341 if (usedHeight + rows > height) 341 if (usedHeight + rows > height)
342 { 342 {
961 961
962 for (char ch : message) 962 for (char ch : message)
963 { 963 {
964 if (ch == '\n') 964 if (ch == '\n')
965 { 965 {
966 m_outputLines.last().finalize(); 966 zfc::last(m_outputLines).finalize();
967 m_outputLines << ColoredLine(); 967 m_outputLines.push_back({});
968 continue; 968 continue;
969 } 969 }
970 970
971 if (m_outputLines.last().length() == 0) 971 if (zfc::last(m_outputLines).length() == 0)
972 { 972 {
973 time_t now; 973 time_t now;
974 time(&now); 974 time(&now);
975 char timestamp[32]; 975 char timestamp[32];
976 strftime(timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime(&now)); 976 strftime(timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime(&now));
977 977
978 for (char ch : String(timestamp)) 978 for (char ch : String(timestamp))
979 m_outputLines.last().addChar(ch); 979 zfc::last(m_outputLines).addChar(ch);
980 } 980 }
981 981
982 // Remove some lines if there's too many of them. 20,000 should be enough, I hope. 982 // Remove some lines if there's too many of them. 20,000 should be enough, I hope.
983 while (m_outputLines.size() > 20000) 983 while (m_outputLines.size() > 20000)
984 m_outputLines.remove_at(0); 984 m_outputLines.erase(m_outputLines.begin());
985 985
986 m_outputLines.last().addChar(ch); 986 zfc::last(m_outputLines).addChar(ch);
987 } 987 }
988 988
989 m_needOutputRender = true; 989 m_needOutputRender = true;
990 } 990 }
991 991

mercurial