// @topic S-0301-01-10-15 C++ console window animation
// @brief uses C++ std::this_thread::sleep_for()

#include <cstdlib>
#include <string>
#include <thread>
#include <chrono>
#include <iostream>

int main()
{
    // animation loop
    const int DISPLAY_SIZE = 90;
    for ( int idx = 0; idx < 20; ++idx ) {
        std::this_thread::sleep_for( std::chrono::milliseconds( 200 ) );
        std::cout << "\r"; // carriage return on the same line
        system( "cls" ); // clear screen -- windows-specific
        std::string animation_frame( DISPLAY_SIZE, ' ' );
        animation_frame[ idx ] = '[';
        animation_frame[ idx + 1 ] = 'A';
        animation_frame[ idx + 2 ] = ']';
        std::cout << animation_frame << "\n";
        std::cout << animation_frame << "\n";
        std::cout << animation_frame << "\n";
        std::cout << animation_frame;
    }
    std::cout << "\n";
    system( "pause" );
    return 0;
}