This commit is contained in:
Zane Zhou 2025-06-19 14:52:49 +02:00 committed by GitHub
commit f3eaadb44c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 21 deletions

View File

@ -105,11 +105,12 @@ class ScreenInteractive : public Screen {
Fullscreen, Fullscreen,
TerminalOutput, TerminalOutput,
}; };
Dimension dimension_ = Dimension::Fixed; const Dimension dimension_ = Dimension::Fixed;
bool use_alternative_screen_ = false; const bool use_alternative_screen_ = false;
ScreenInteractive(int dimx,
ScreenInteractive(Dimension dimension,
int dimx,
int dimy, int dimy,
Dimension dimension,
bool use_alternative_screen); bool use_alternative_screen);
bool track_mouse_ = true; bool track_mouse_ = true;
@ -129,6 +130,7 @@ class ScreenInteractive : public Screen {
int cursor_x_ = 1; int cursor_x_ = 1;
int cursor_y_ = 1; int cursor_y_ = 1;
std::uint64_t frame_count_ = 0;
bool mouse_captured = false; bool mouse_captured = false;
bool previous_frame_resized_ = false; bool previous_frame_resized_ = false;

View File

@ -346,9 +346,9 @@ void AnimationListener(std::atomic<bool>* quit, Sender<Task> out) {
} // namespace } // namespace
ScreenInteractive::ScreenInteractive(int dimx, ScreenInteractive::ScreenInteractive(Dimension dimension,
int dimx,
int dimy, int dimy,
Dimension dimension,
bool use_alternative_screen) bool use_alternative_screen)
: Screen(dimx, dimy), : Screen(dimx, dimy),
dimension_(dimension), dimension_(dimension),
@ -359,10 +359,10 @@ ScreenInteractive::ScreenInteractive(int dimx,
// static // static
ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) { ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) {
return { return {
Dimension::Fixed,
dimx, dimx,
dimy, dimy,
Dimension::Fixed, /*use_alternative_screen=*/false,
false,
}; };
} }
@ -379,11 +379,12 @@ ScreenInteractive ScreenInteractive::Fullscreen() {
/// content might mess up with the terminal content. /// content might mess up with the terminal content.
// static // static
ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() { ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() {
auto terminal = Terminal::Size();
return { return {
0, Dimension::Fullscreen,
0, terminal.dimx,
Dimension::Fullscreen, terminal.dimy,
false, /*use_alternative_screen=*/false,
}; };
} }
@ -391,30 +392,37 @@ ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() {
/// alternate screen buffer to avoid messing with the terminal content. /// alternate screen buffer to avoid messing with the terminal content.
// static // static
ScreenInteractive ScreenInteractive::FullscreenAlternateScreen() { ScreenInteractive ScreenInteractive::FullscreenAlternateScreen() {
auto terminal = Terminal::Size();
return { return {
0,
0,
Dimension::Fullscreen, Dimension::Fullscreen,
true, terminal.dimx,
terminal.dimy,
/*use_alternative_screen=*/true,
}; };
} }
/// Create a ScreenInteractive whose width match the terminal output width and
/// the height matches the component being drawn.
// static // static
ScreenInteractive ScreenInteractive::TerminalOutput() { ScreenInteractive ScreenInteractive::TerminalOutput() {
auto terminal = Terminal::Size();
return { return {
0,
0,
Dimension::TerminalOutput, Dimension::TerminalOutput,
false, terminal.dimx,
terminal.dimy, // Best guess.
/*use_alternative_screen=*/false,
}; };
} }
/// Create a ScreenInteractive whose width and height match the component being
/// drawn.
// static // static
ScreenInteractive ScreenInteractive::FitComponent() { ScreenInteractive ScreenInteractive::FitComponent() {
auto terminal = Terminal::Size();
return { return {
0,
0,
Dimension::FitComponent, Dimension::FitComponent,
terminal.dimx, // Best guess.
terminal.dimy, // Best guess.
false, false,
}; };
} }
@ -921,7 +929,7 @@ void ScreenInteractive::Draw(Component component) {
break; break;
} }
const bool resized = (dimx != dimx_) || (dimy != dimy_); const bool resized = frame_count_ == 0 || (dimx != dimx_) || (dimy != dimy_);
ResetCursorPosition(); ResetCursorPosition();
std::cout << ResetPosition(/*clear=*/resized); std::cout << ResetPosition(/*clear=*/resized);
@ -1004,6 +1012,7 @@ void ScreenInteractive::Draw(Component component) {
Flush(); Flush();
Clear(); Clear();
frame_valid_ = true; frame_valid_ = true;
frame_count_++;
} }
// private // private