mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Clear terminal on resize. (#99)
This commit is contained in:
parent
e520ac59f9
commit
30a85c4c5b
@ -63,7 +63,7 @@ class Screen {
|
|||||||
int dimy() { return dimy_; }
|
int dimy() { return dimy_; }
|
||||||
|
|
||||||
// Move the terminal cursor n-lines up with n = dimy().
|
// Move the terminal cursor n-lines up with n = dimy().
|
||||||
std::string ResetPosition();
|
std::string ResetPosition(bool clear = false);
|
||||||
|
|
||||||
// Fill with space.
|
// Fill with space.
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -382,11 +382,6 @@ void ScreenInteractive::Loop(Component component) {
|
|||||||
// The main loop.
|
// The main loop.
|
||||||
while (!quit_) {
|
while (!quit_) {
|
||||||
if (!event_receiver_->HasPending()) {
|
if (!event_receiver_->HasPending()) {
|
||||||
std::cout << reset_cursor_position << ResetPosition();
|
|
||||||
static int i = -2;
|
|
||||||
if (i % 10 == 0)
|
|
||||||
std::cout << DeviceStatusReport(DSRMode::kCursor);
|
|
||||||
++i;
|
|
||||||
Draw(component);
|
Draw(component);
|
||||||
std::cout << ToString() << set_cursor_position;
|
std::cout << ToString() << set_cursor_position;
|
||||||
Flush();
|
Flush();
|
||||||
@ -442,8 +437,11 @@ void ScreenInteractive::Draw(Component component) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool resized = (dimx != dimx_) || (dimy != dimy_);
|
||||||
|
std::cout << reset_cursor_position << ResetPosition(/*clear=*/resized);
|
||||||
|
|
||||||
// Resize the screen if needed.
|
// Resize the screen if needed.
|
||||||
if (dimx != dimx_ || dimy != dimy_) {
|
if (resized) {
|
||||||
dimx_ = dimx;
|
dimx_ = dimx;
|
||||||
dimy_ = dimy;
|
dimy_ = dimy;
|
||||||
pixels_ = std::vector<std::vector<Pixel>>(dimy, std::vector<Pixel>(dimx));
|
pixels_ = std::vector<std::vector<Pixel>>(dimy, std::vector<Pixel>(dimx));
|
||||||
@ -451,6 +449,11 @@ void ScreenInteractive::Draw(Component component) {
|
|||||||
cursor_.y = dimy_ - 1;
|
cursor_.y = dimy_ - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int i = -2;
|
||||||
|
if (i % 10 == 0)
|
||||||
|
std::cout << DeviceStatusReport(DSRMode::kCursor);
|
||||||
|
++i;
|
||||||
|
|
||||||
Render(*this, document);
|
Render(*this, document);
|
||||||
|
|
||||||
// Set cursor position for user using tools to insert CJK characters.
|
// Set cursor position for user using tools to insert CJK characters.
|
||||||
|
@ -36,6 +36,7 @@ static const wchar_t* INVERTED_RESET = L"\x1B[27m";
|
|||||||
|
|
||||||
static const char* MOVE_LEFT = "\r";
|
static const char* MOVE_LEFT = "\r";
|
||||||
static const char* MOVE_UP = "\x1B[1A";
|
static const char* MOVE_UP = "\x1B[1A";
|
||||||
|
static const char* CLEAR_LINE = "\x1B[2K";
|
||||||
|
|
||||||
bool In(const Box& stencil, int x, int y) {
|
bool In(const Box& stencil, int x, int y) {
|
||||||
return stencil.x_min <= x && x <= stencil.x_max && //
|
return stencil.x_min <= x && x <= stencil.x_max && //
|
||||||
@ -219,12 +220,19 @@ Pixel& Screen::PixelAt(int x, int y) {
|
|||||||
///
|
///
|
||||||
/// @return The string to print in order to reset the cursor position to the
|
/// @return The string to print in order to reset the cursor position to the
|
||||||
/// beginning.
|
/// beginning.
|
||||||
std::string Screen::ResetPosition() {
|
std::string Screen::ResetPosition(bool clear) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
if (clear) {
|
||||||
|
ss << MOVE_LEFT << CLEAR_LINE;
|
||||||
|
for (int y = 1; y < dimy_; ++y) {
|
||||||
|
ss << MOVE_UP << CLEAR_LINE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ss << MOVE_LEFT;
|
ss << MOVE_LEFT;
|
||||||
for (int y = 1; y < dimy_; ++y) {
|
for (int y = 1; y < dimy_; ++y) {
|
||||||
ss << MOVE_UP;
|
ss << MOVE_UP;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user