Fix tests.

This commit is contained in:
ArthurSonzogni 2025-06-19 14:52:39 +02:00
parent d86a08b8c9
commit 6dbe1843a7
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
2 changed files with 32 additions and 19 deletions

View File

@ -106,13 +106,12 @@ class ScreenInteractive : public Screen {
TerminalOutput, TerminalOutput,
}; };
const Dimension dimension_ = Dimension::Fixed; const Dimension dimension_ = Dimension::Fixed;
const int dimension_fixed_x_ = 0;
const int dimension_fixed_y_ = 0;
const bool use_alternative_screen_ = false; const bool use_alternative_screen_ = false;
ScreenInteractive(Dimension dimension, ScreenInteractive(Dimension dimension,
int dimx,
int dimy,
bool use_alternative_screen); bool use_alternative_screen);
ScreenInteractive(int dimx, int dimy); // Dimension::Fixed constructor.
bool track_mouse_ = true; bool track_mouse_ = true;
@ -131,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

@ -347,23 +347,23 @@ void AnimationListener(std::atomic<bool>* quit, Sender<Task> out) {
} // namespace } // namespace
ScreenInteractive::ScreenInteractive(Dimension dimension, ScreenInteractive::ScreenInteractive(Dimension dimension,
int dimx,
int dimy,
bool use_alternative_screen) bool use_alternative_screen)
: Screen(0, 0), : Screen(dimx, dimy),
dimension_(dimension), dimension_(dimension),
use_alternative_screen_(use_alternative_screen) { use_alternative_screen_(use_alternative_screen) {
task_receiver_ = MakeReceiver<Task>(); task_receiver_ = MakeReceiver<Task>();
} }
ScreenInteractive::ScreenInteractive(int dimx, int dimy)
: Screen(0, 0),
dimension_fixed_x_(dimx),
dimension_fixed_y_(dimy) {
task_receiver_ = MakeReceiver<Task>();
}
// static // static
ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) { ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) {
return { dimx, dimy }; return {
Dimension::Fixed,
dimx,
dimy,
/*use_alternative_screen=*/false,
};
} }
/// Create a ScreenInteractive taking the full terminal size. This is using the /// Create a ScreenInteractive taking the full terminal size. This is using the
@ -379,9 +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 {
Dimension::Fullscreen, Dimension::Fullscreen,
false, terminal.dimx,
terminal.dimy,
/*use_alternative_screen=*/false,
}; };
} }
@ -389,9 +392,12 @@ 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 {
Dimension::Fullscreen, Dimension::Fullscreen,
true, terminal.dimx,
terminal.dimy,
/*use_alternative_screen=*/true,
}; };
} }
@ -399,9 +405,12 @@ ScreenInteractive ScreenInteractive::FullscreenAlternateScreen() {
/// the height matches the component being drawn. /// the height matches the component being drawn.
// static // static
ScreenInteractive ScreenInteractive::TerminalOutput() { ScreenInteractive ScreenInteractive::TerminalOutput() {
auto terminal = Terminal::Size();
return { return {
Dimension::TerminalOutput, Dimension::TerminalOutput,
false, terminal.dimx,
terminal.dimy, // Best guess.
/*use_alternative_screen=*/false,
}; };
} }
@ -409,8 +418,11 @@ ScreenInteractive ScreenInteractive::TerminalOutput() {
/// drawn. /// drawn.
// static // static
ScreenInteractive ScreenInteractive::FitComponent() { ScreenInteractive ScreenInteractive::FitComponent() {
auto terminal = Terminal::Size();
return { return {
Dimension::FitComponent, Dimension::FitComponent,
terminal.dimx, // Best guess.
terminal.dimy, // Best guess.
false, false,
}; };
} }
@ -900,8 +912,8 @@ void ScreenInteractive::Draw(Component component) {
document->ComputeRequirement(); document->ComputeRequirement();
switch (dimension_) { switch (dimension_) {
case Dimension::Fixed: case Dimension::Fixed:
dimx = dimension_fixed_x_; dimx = dimx_;
dimy = dimension_fixed_y_; dimy = dimy_;
break; break;
case Dimension::TerminalOutput: case Dimension::TerminalOutput:
dimx = terminal.dimx; dimx = terminal.dimx;
@ -917,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);
@ -1000,6 +1012,7 @@ void ScreenInteractive::Draw(Component component) {
Flush(); Flush();
Clear(); Clear();
frame_valid_ = true; frame_valid_ = true;
frame_count_++;
} }
// private // private