Polyphase Game Engine
Loading...
Searching...
No Matches
AnsiStripper.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
6
7#include <string>
8
33class AnsiStripper : public ITerminalOutputParser
34{
35public:
37 std::string Process(const char* data, size_t len) override;
38
40 void Reset() override { mState = State::Normal; mEndsWithNewline = true; }
41
42 const char* GetName() const override { return "default"; }
43
52 void SetSynthesizeFrameNewlines(bool enable) { mSynthesizeFrameNewlines = enable; }
53 bool GetSynthesizeFrameNewlines() const { return mSynthesizeFrameNewlines; }
54
55private:
56 enum class State
57 {
58 Normal, // regular text
59 JustSawCr, // last byte was CR; deciding CRLF vs bare CR
60 Esc, // last byte was ESC; deciding what kind of sequence follows
61 Csi, // inside ESC [ ... <final>
62 Osc, // inside ESC ] ... ( BEL | ESC \ )
63 OscEscaped, // inside OSC, just saw ESC; waiting for backslash
64 };
65
66 State mState = State::Normal;
67
68 // Buffer for accumulating CSI parameter bytes so we can interpret a few
69 // common cursor movements (specifically "cursor forward N" -> emit N
70 // spaces) which TUI apps use for layout instead of literal spaces.
71 std::string mCsiParams;
72
73 // Tracks whether the last byte we emitted (across all Process() calls)
74 // was a newline. Used to suppress synthetic frame-redraw newlines that
75 // would otherwise stack up on TTY backends (notably Linux PTY) where
76 // TUI apps like `claude` emit a clear-screen + cursor-home at the start
77 // of every chunk, producing a blank line per redraw cycle.
78 bool mEndsWithNewline = true;
79
80 // See SetSynthesizeFrameNewlines.
81 bool mSynthesizeFrameNewlines = true;
82};
83
84#endif