#ifndef TYPER_H #define TYPER_H #include #include #include #include #include #define SIMILARITY_LINE_COUNT 8 #define SIMILARITY_COPY_THRESHOLD 0.75f #define BLOCK_UNSIMILAR_LIMIT 2 struct Line { int prio; size_t index; std::string text; std::array similarity; Line() { } Line(int prio, size_t index, std::string text) : prio(prio), index(index), text(text) { } }; class Typer { public: Typer(std::unique_ptr keyHandler) : m_keyHandler(std::move(keyHandler)) { } virtual ~Typer() { } void ProcessFile(std::string fname); void TogglePaused(); protected: virtual void OnStart() { } virtual void KeyUp(); virtual void KeyDown(); virtual void KeyLeft(); virtual void KeyRight(); virtual void KeyHome(); virtual void KeyEnd(); virtual void KeyNewline(); virtual void KeyString(std::string str); private: int GetLinePriority(std::string& line); void ReadFile(std::string fname); void ComputeDiffs(); // These methods type and also update the "screen" void Newline(); void TypeString(std::string str); void NavigateTo(size_t row, size_t col); void NavigateToRow(size_t row); void NavigateToCol(size_t col); bool IsKeyShifted(char c); // constants static const size_t COL_END = static_cast(-2); static const size_t COL_HOME = static_cast(-1); protected: // key handler std::unique_ptr m_keyHandler; private: // lines to write std::vector m_lines; // current state of the screen std::vector> m_scrOutput; size_t m_scrCol, m_scrRow; }; #endif // TYPER_H