#pragma once #include #include "command.h" #include "textblob.h" using namespace std; //Everything is zero-based. class Manager; class Buffer{ struct Cell{ char c; bool special; i64 linex; //position in line }; struct ScreenLine{ i64 line,part; //part: n'th screen line of the logical line `line` i64 fromx; //starting at what x into the line does this screen line have text vector cells; }; struct Cursorpos{ i64 line,x; }; struct Screenpos{ i64 y,x; }; Manager *const manager; const bool singleLineMode=false; TextBlob tb; bool dirty=false; vector screen; i64 lastWidth=-1,lastHeight=-1; //excluding the gutter Cursorpos cursor={0,0}; vector layoutLine(const string &line,i64 linenum,i64 width); void performInitialLayout(i64 width,i64 height); void renewLayout(i64 topLine,i64 topPart,i64 width,i64 height); void relayoutScreen(); void scrollUp(); Screenpos findCursorInScreen() const; void handleCommand(const Command &cmd); public: string filename; Buffer(Manager *manager); Buffer(Manager *manager,bool singleLineMode); void receive(const Command &cmd); void show(i64 atx,i64 aty,i64 width,i64 height); string getText() const; bool isDirty() const; };