Files
kte/TerminalRenderer.h
T
Claude 61a7338f88 Terminal loop, virtual buffers, yank bound
- kte refuses to start when stdin is not a terminal: piped bytes were
  executed as editor commands (C-k s plus a path writes a file), and
  after EOF the loop spun at full CPU with no way to quit.
- The terminal frontend handles all pending input before drawing (a
  paste used to cost a frame and a full redraw per character) and
  redraws only after input, a resize or deferred opens, else once a
  second. The renderer caches, per row and buffer version, where the
  horizontally scrolled part of a line starts and the cursor's render
  column, instead of rescanning the line every frame. Idle CPU with the
  cursor at the end of a 20 MB line: one full core -> ~1%.
- Buffers with a virtual name (+HELP+) are not journaled and saving one
  asks for a file name; it used to write ./+HELP+ and journal under
  that path.
- Yank with a repeat count is capped at 256 MiB in total instead of
  reserving count x size bytes (C-u 1000000 C-y of a large kill).
- Remove an overload clang reports as unused (-Werror on macOS).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
2026-09-24 09:16:04 -07:00

45 lines
1.1 KiB
C++

/*
* TerminalRenderer - ncurses-based renderer for terminal mode
*/
#pragma once
#include <vector>
#include <cstdint>
#include <cstddef>
#include "Renderer.h"
class TerminalRenderer final : public Renderer {
public:
TerminalRenderer();
~TerminalRenderer() override;
void Draw(Editor &ed) override;
private:
// Where a row's visible part starts (the draw loop's skip up to the
// horizontal scroll offset), cached per screen row. Scanning a very long
// line from column 0 on every frame made each redraw O(line length).
struct SkipCache {
const void *buf = nullptr;
std::uint64_t version = 0;
std::size_t row = 0;
std::size_t coloffs = 0;
std::size_t src = 0; // byte offset where drawing resumes
std::size_t col = 0; // render column at that offset
bool valid = false;
};
std::vector<SkipCache> skip_cache_;
// Render column of the cursor, cached the same way.
struct CursorCache {
const void *buf = nullptr;
std::uint64_t version = 0;
std::size_t row = 0;
std::size_t cx = 0;
std::size_t rx = 0;
bool valid = false;
} cursor_cache_;
};