MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / tail

Method tail

common/script/scriptconsole.cpp:315–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315std::string ScriptConsole::tail(size_t maxBytes) const
316{
317 std::lock_guard<std::mutex> lock(mMutex);
318
319 // Walk back from the newest line until the joined text would exceed the
320 // budget, so the tail always ends on the last thing the script said — which
321 // is where a picoc diagnostic is.
322 size_t bytes = 0, first = mLines.size();
323 while (first > 0) {
324 const size_t cost = mLines[first - 1].size() + 1;
325 if (bytes + cost > maxBytes) {
326 break;
327 }
328 bytes += cost;
329 first--;
330 }
331
332 std::string out;
333 out.reserve(bytes);
334 for (size_t i = first; i < mLines.size(); i++) {
335 out += mLines[i];
336 out += '\n';
337 }
338 return out;
339}
340
341/* ---- C shim ------------------------------------------------------------- */
342/* picoc's stdlib and platform layer are C; these are the only entry points

Callers 1

runMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected