silly
parent
e885df622a
commit
3f59528ecc
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
include(cmake/color.cmake)
|
||||
set(BLT_VERSION 5.2.10)
|
||||
set(BLT_VERSION 5.2.11)
|
||||
|
||||
set(BLT_TARGET BLT)
|
||||
|
||||
|
|
|
@ -249,8 +249,12 @@ namespace blt::logging::ansi
|
|||
namespace cursor
|
||||
{
|
||||
inline const std::string home = BLT_ANSI_CSI "H";
|
||||
inline const std::string lower_left_corner = BLT_ANSI_ESCAPE " F";
|
||||
inline const std::string hide_cursor = BLT_ANSI_CSI "?2 5l";
|
||||
inline const std::string show_cursor = BLT_ANSI_CSI "?2 5h";
|
||||
inline const std::string report_position = BLT_ANSI_CSI "6n";
|
||||
|
||||
template <bool UseH>
|
||||
template <bool UseH = true>
|
||||
std::string move_to(const i64 line, const i64 column)
|
||||
{
|
||||
if constexpr (UseH)
|
||||
|
@ -302,6 +306,14 @@ namespace blt::logging::ansi
|
|||
inline const std::string restore_cursor_position_sco = BLT_ANSI_CSI "u";
|
||||
}
|
||||
|
||||
namespace scroll
|
||||
{
|
||||
inline std::string scroll_up(const int lines)
|
||||
{
|
||||
return std::string(BLT_ANSI_CSI) + std::to_string(lines) + "S";
|
||||
};
|
||||
}
|
||||
|
||||
namespace erase
|
||||
{
|
||||
inline const std::string to_end_of_screen = BLT_ANSI_CSI "0J";
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace blt::logging
|
|||
{
|
||||
std::string new_logging_output;
|
||||
// should we continue processing the injector call chain?
|
||||
bool should_continue;
|
||||
bool should_continue = true;
|
||||
// should we log the resulting string at the end of the injector call chain? If false for any injector, it becomes false for all injectors.
|
||||
bool should_log;
|
||||
bool should_log = true;
|
||||
};
|
||||
|
||||
class injector_t
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#define BLT_LOGGING_LOGGING_CONFIG_H
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -140,9 +139,9 @@ namespace blt::logging
|
|||
return *this;
|
||||
}
|
||||
|
||||
logging_config_t& add_injector(injector_t* injector)
|
||||
logging_config_t& add_injector(injector_t& injector)
|
||||
{
|
||||
m_injectors.push_back(std::unique_ptr<injector_t>(injector));
|
||||
m_injectors.push_back(&injector);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -206,13 +205,13 @@ namespace blt::logging
|
|||
std::optional<std::string> generate(const std::string& user_str, const std::string& thread_name, log_level_t level, const char* file,
|
||||
i32 line) const;
|
||||
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<injector_t>>& get_injectors() const
|
||||
[[nodiscard]] const std::vector<injector_t*>& get_injectors() const
|
||||
{
|
||||
return m_injectors;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<injector_t>> m_injectors;
|
||||
std::vector<injector_t*> m_injectors;
|
||||
// wrappers for streams exist in blt/fs/stream_wrappers.h
|
||||
std::vector<fs::writer_t*> m_log_outputs = get_default_log_outputs();
|
||||
std::string m_log_format = get_default_log_format();
|
||||
|
|
|
@ -19,9 +19,38 @@
|
|||
#ifndef BLT_LOGGING_STATUS_H
|
||||
#define BLT_LOGGING_STATUS_H
|
||||
|
||||
#include <string>
|
||||
#include <blt/logging/injector.h>
|
||||
#include <blt/std/types.h>
|
||||
|
||||
namespace blt::logging
|
||||
{
|
||||
|
||||
class status_item_t
|
||||
{
|
||||
public:
|
||||
virtual ~status_item_t() = default;
|
||||
|
||||
[[nodiscard]] virtual i32 lines_used() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string print();
|
||||
};
|
||||
|
||||
class status_bar_t final : public injector_t
|
||||
{
|
||||
public:
|
||||
explicit status_bar_t(i32 status_size);
|
||||
|
||||
injector_output_t inject(const std::string& input) override;
|
||||
|
||||
virtual ~status_bar_t() override;
|
||||
private:
|
||||
i32 m_status_size;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //BLT_LOGGING_STATUS_H
|
||||
|
|
|
@ -225,11 +225,11 @@ namespace blt::logging
|
|||
for (const auto& injector : config.get_injectors())
|
||||
{
|
||||
auto [new_logging_output, should_continue, should_log] = injector->inject(str);
|
||||
if (!should_continue)
|
||||
break;
|
||||
if (!should_log)
|
||||
should_print = false;
|
||||
str = std::move(new_logging_output);
|
||||
if (!should_continue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (should_print)
|
||||
|
|
|
@ -15,9 +15,97 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <blt/logging/ansi.h>
|
||||
#include <blt/logging/fmt_tokenizer.h>
|
||||
#include <blt/logging/status.h>
|
||||
#include <blt/math/vectors.h>
|
||||
|
||||
namespace blt::logging
|
||||
{
|
||||
vec2i get_cursor_position()
|
||||
{
|
||||
termios save{}, raw{};
|
||||
|
||||
tcgetattr(0, &save);
|
||||
cfmakeraw(&raw);
|
||||
tcsetattr(0,TCSANOW, &raw);
|
||||
|
||||
char buf[32];
|
||||
char cmd[] = "\033[6n";
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
if (isatty(fileno(stdin)))
|
||||
{
|
||||
write(1, cmd, sizeof(cmd));
|
||||
read(0, buf, sizeof(buf));
|
||||
|
||||
int sep = 0;
|
||||
int end = 0;
|
||||
for (int i = 2; i < 8; i++)
|
||||
{
|
||||
if (buf[i] == ';')
|
||||
sep = i;
|
||||
if (buf[i] == 'R')
|
||||
{
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
row = std::stoi(std::string(buf + 2, buf + sep));
|
||||
col = std::stoi(std::string(buf + sep + 1, buf + end));
|
||||
// printf("{Row: %d, Col: %d}", row, col);
|
||||
}
|
||||
|
||||
tcsetattr(0,TCSANOW, &save);
|
||||
|
||||
return vec2i{row, col};
|
||||
}
|
||||
|
||||
vec2i get_screen_size()
|
||||
{
|
||||
std::cout << ansi::cursor::move_to(9999, 9999);
|
||||
const auto pos = get_cursor_position();
|
||||
std::cout << ansi::cursor::lower_left_corner;
|
||||
std::cout << " ";
|
||||
return pos;
|
||||
}
|
||||
|
||||
status_bar_t::status_bar_t(const i32 status_size): m_status_size(status_size)
|
||||
{
|
||||
std::cout << ansi::cursor::hide_cursor;
|
||||
}
|
||||
|
||||
std::string status_item_t::print()
|
||||
{}
|
||||
|
||||
injector_output_t status_bar_t::inject(const std::string& input)
|
||||
{
|
||||
injector_output_t output{input, false, false};
|
||||
|
||||
std::cout << ansi::cursor::lower_left_corner;
|
||||
std::cout << ansi::scroll::scroll_up(1);
|
||||
for (int i = 0; i < m_status_size; i++)
|
||||
std::cout << ansi::erase::entire_line << ansi::cursor::move_begin_up(1);
|
||||
std::cout << output.new_logging_output;
|
||||
std::cout << ansi::erase::entire_line;
|
||||
std::cout << "[----status----]";
|
||||
std::cout << ansi::cursor::move_begin_down(1) << ansi::erase::entire_line;
|
||||
std::cout << "[----Second Line----]";
|
||||
std::cout << std::flush;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
status_bar_t::~status_bar_t()
|
||||
{
|
||||
// std::cout << "\033[" << m_scrolling_region + 1 << ";1H";
|
||||
std::cout << ansi::cursor::lower_left_corner;
|
||||
std::cout << ansi::cursor::show_cursor;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
#include <blt/fs/filesystem.h>
|
||||
#include <blt/logging/ansi.h>
|
||||
#include <blt/logging/logging.h>
|
||||
#include <blt/logging/status.h>
|
||||
#include <blt/std/assert.h>
|
||||
#include <blt/std/utility.h>
|
||||
|
||||
|
@ -131,31 +132,31 @@ int main()
|
|||
blt::logging::println(ss, "This is a println with fill no alignment {:%20} end value", 46);
|
||||
blt::logging::println(ss, "This is a println with arg reference {0:{1}.{2}f}", 46.0232, 20, 2);
|
||||
blt::logging::println(ss, "This is a println with arg reference {0:&{1}}", "", 20);
|
||||
blt::logging::print(ss.str());
|
||||
// blt::logging::print(ss.str());
|
||||
auto [passed, error_msg] = compare_strings(expected_str, ss.str());
|
||||
BLT_ASSERT_MSG(passed && "Logger logged string doesn't match precomputed expected string!", error_msg.c_str());
|
||||
|
||||
namespace ansi = blt::logging::ansi;
|
||||
namespace color = ansi::color;
|
||||
|
||||
for (blt::u8 r = 0; r < 6; r++)
|
||||
{
|
||||
for (blt::u8 g = 0; g < 6; g++)
|
||||
{
|
||||
for (blt::u8 b = 0; b < 6; b++)
|
||||
{
|
||||
blt::logging::println("{}This is a println with a color {:#3x} {:#3x} {:#3x}{}",
|
||||
build(fg(color::color256{r, g, b}), bg(color::color256{
|
||||
static_cast<unsigned char>(5 - r),
|
||||
static_cast<unsigned char>(5 - g),
|
||||
static_cast<unsigned char>(5 - b)
|
||||
})), r, g, b, build(color::color_mode::RESET_ALL));
|
||||
}
|
||||
}
|
||||
}
|
||||
blt::logging::println("{}This is a color now with background{}",
|
||||
build(color::color_mode::BOLD, fg(color::color8::RED), color::color_mode::DIM, bg(color::color_rgb(0, 100, 255))),
|
||||
build(color::color_mode::RESET_ALL));
|
||||
// for (blt::u8 r = 0; r < 6; r++)
|
||||
// {
|
||||
// for (blt::u8 g = 0; g < 6; g++)
|
||||
// {
|
||||
// for (blt::u8 b = 0; b < 6; b++)
|
||||
// {
|
||||
// blt::logging::println("{}This is a println with a color {:#3x} {:#3x} {:#3x}{}",
|
||||
// build(fg(color::color256{r, g, b}), bg(color::color256{
|
||||
// static_cast<unsigned char>(5 - r),
|
||||
// static_cast<unsigned char>(5 - g),
|
||||
// static_cast<unsigned char>(5 - b)
|
||||
// })), r, g, b, build(color::color_mode::RESET_ALL));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// blt::logging::println("{}This is a color now with background{}",
|
||||
// build(color::color_mode::BOLD, fg(color::color8::RED), color::color_mode::DIM, bg(color::color_rgb(0, 100, 255))),
|
||||
// build(color::color_mode::RESET_ALL));
|
||||
|
||||
|
||||
std::ofstream os("test.txt");
|
||||
|
@ -171,17 +172,36 @@ int main()
|
|||
writer.write("What about just a new line character?\n");
|
||||
size_t charCount = 0;
|
||||
|
||||
blt::logging::println("Logged {} characters", charCount);
|
||||
// blt::logging::println("Logged {} characters", charCount);
|
||||
//
|
||||
// BLT_TRACE("Hello this is am empty trace!");
|
||||
// BLT_TRACE("This is a trace with data {} {} {}", "bad at code", 413, "boy");
|
||||
//
|
||||
// BLT_DEBUG("This is complete? {}", "this is working!");
|
||||
// BLT_INFO("Hello there!");
|
||||
// BLT_WARN("This is a warning!");
|
||||
// BLT_ERROR("This is an error!");
|
||||
// BLT_FATAL("This is a fatal error!");
|
||||
// BLT_TRACE("This is a pointer {:f}", &charCount);
|
||||
//
|
||||
// BLT_TRACE("Now time to test the logger status box");
|
||||
|
||||
BLT_TRACE("Hello this is am empty trace!");
|
||||
BLT_TRACE("This is a trace with data {} {} {}", "bad at code", 413, "boy");
|
||||
blt::logging::status_bar_t status{2};
|
||||
blt::logging::get_global_config().add_injector(status);
|
||||
|
||||
BLT_DEBUG("This is complete? {}", "this is working!");
|
||||
BLT_INFO("Hello there!");
|
||||
BLT_WARN("This is a warning!");
|
||||
BLT_ERROR("This is an error!");
|
||||
BLT_FATAL("This is a fatal error!");
|
||||
BLT_TRACE("This is a pointer {:f}", &charCount);
|
||||
BLT_TRACE("Hello There!");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
BLT_TRACE("I am printing stuff!");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
BLT_TRACE("How are you!?");
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
BLT_INFO("I am printing some output {} times!", i + 1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
|
||||
/*std::cout << "\033[2J";
|
||||
constexpr int totalRows = 24;
|
||||
|
|
Loading…
Reference in New Issue