Skip to content

Commit

Permalink
Updated license; Tested ToHTML redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed May 29, 2024
1 parent 03ac190 commit 3ab0496
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 259 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2012-2024 Dimo Markov
Copyright (c) 2012 Dimo Markov <team@langulus.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions include/Logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/// Copyright (c) 2012 Dimo Markov <team@langulus.com>
/// Part of the Langulus framework, see https://langulus.com
///
/// Distributed under GNU General Public License v3+
/// See LICENSE file, or https://www.gnu.org/licenses
/// SPDX-License-Identifier: MIT
///
#pragma once
#include "../../source/Logger.hpp"
100 changes: 63 additions & 37 deletions source/HTML.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
///
/// Langulus::Logger
/// Copyright (c) 2012 Dimo Markov <team@langulus.com>
/// Part of the Langulus framework, see https://langulus.com
///
/// SPDX-License-Identifier: MIT
///
#include "Logger.hpp"
#include <string>

using namespace Langulus;
using namespace Langulus::Logger;


/// Create an HTML file duplicator/redirector
/// @param filename - the relative filename of the log file
ToHTML::ToHTML(const std::string& filename) {
mFile.open(filename, std::ios::out | std::ios::app | std::ios::ate);
ToHTML::ToHTML(const std::string& filename) : mFilename {filename} {
mFile.open(mFilename, std::ios::out | std::ios::trunc);
if (not mFile)
throw std::runtime_error {"Can't open log file"};
WriteHeader();
}

ToHTML::~ToHTML() {
mFile.close();
}

/// Write text
Expand All @@ -23,24 +34,24 @@ void ToHTML::Write(const TextView& text) const noexcept {
/// @param style - the style to set
void ToHTML::Write(const Style& style) const noexcept {
// Always reset before a style change
Write("</strong></em></u></blink></del></span>");
Write(" </strong></em></u></blink></del></span>");

if (style.has_emphasis()) {
const auto em = static_cast<uint8_t>(style.get_emphasis());
if (em & static_cast<uint8_t>(fmt::emphasis::bold))
Write("<strong>");
if (em & static_cast<uint8_t>(fmt::emphasis::faint))
;
//if (em & static_cast<uint8_t>(fmt::emphasis::faint))
// ;
if (em & static_cast<uint8_t>(fmt::emphasis::italic))
Write("<em>");
if (em & static_cast<uint8_t>(fmt::emphasis::underline))
Write("<u>");
if (em & static_cast<uint8_t>(fmt::emphasis::blink))
Write("<blink>");
if (em & static_cast<uint8_t>(fmt::emphasis::reverse))
;
if (em & static_cast<uint8_t>(fmt::emphasis::conceal))
;
//if (em & static_cast<uint8_t>(fmt::emphasis::reverse))
// ;
//if (em & static_cast<uint8_t>(fmt::emphasis::conceal))
// ;
if (em & static_cast<uint8_t>(fmt::emphasis::strikethrough))
Write("<del>");
}
Expand All @@ -54,46 +65,46 @@ void ToHTML::Write(const Style& style) const noexcept {
Write("<span style = \"color: black;\">");
break;
case fmt::terminal_color::red:
Write("<span style = \"color: red;\">");
Write("<span style = \"color: DarkRed;\">");
break;
case fmt::terminal_color::green:
Write("<span style = \"color: green;\">");
Write("<span style = \"color: ForestGreen;\">");
break;
case fmt::terminal_color::yellow:
Write("<span style = \"color: yellow;\">");
Write("<span style = \"color: DarkOrange;\">");
break;
case fmt::terminal_color::blue:
Write("<span style = \"color: blue;\">");
break;
case fmt::terminal_color::magenta:
Write("<span style = \"color: magenta;\">");
Write("<span style = \"color: DarkMagenta;\">");
break;
case fmt::terminal_color::cyan:
Write("<span style = \"color: cyan;\">");
Write("<span style = \"color: DarkCyan;\">");
break;
case fmt::terminal_color::white:
Write("<span style = \"color: gray;\">");
Write("<span style = \"color: LightGray;\">");
break;
case fmt::terminal_color::bright_black:
Write("<span style = \"color: dark gray;\">");
Write("<span style = \"color: gray;\">");
break;
case fmt::terminal_color::bright_red:
Write("<span style = \"color: bright red;\">");
Write("<span style = \"color: Red;\">");
break;
case fmt::terminal_color::bright_green:
Write("<span style = \"color: bright green;\">");
Write("<span style = \"color: GreenYellow;\">");
break;
case fmt::terminal_color::bright_yellow:
Write("<span style = \"color: bright yellow;\">");
Write("<span style = \"color: Gold;\">");
break;
case fmt::terminal_color::bright_blue:
Write("<span style = \"color: bright blue;\">");
Write("<span style = \"color: LightSkyBlue;\">");
break;
case fmt::terminal_color::bright_magenta:
Write("<span style = \"color: bright magenta;\">");
Write("<span style = \"color: magenta;\">");
break;
case fmt::terminal_color::bright_cyan:
Write("<span style = \"color: bright cyan;\">");
Write("<span style = \"color: cyan;\">");
break;
case fmt::terminal_color::bright_white:
Write("<span style = \"color: white;\">");
Expand All @@ -110,46 +121,46 @@ void ToHTML::Write(const Style& style) const noexcept {
Write("<span style = \"background-color: black;\">");
break;
case fmt::terminal_color::red:
Write("<span style = \"background-color: red;\">");
Write("<span style = \"background-color: DarkRed;\">");
break;
case fmt::terminal_color::green:
Write("<span style = \"background-color: green;\">");
Write("<span style = \"background-color: ForestGreen;\">");
break;
case fmt::terminal_color::yellow:
Write("<span style = \"background-color: yellow;\">");
Write("<span style = \"background-color: DarkOrange;\">");
break;
case fmt::terminal_color::blue:
Write("<span style = \"background-color: blue;\">");
break;
case fmt::terminal_color::magenta:
Write("<span style = \"background-color: magenta;\">");
Write("<span style = \"background-color: DarkMagenta;\">");
break;
case fmt::terminal_color::cyan:
Write("<span style = \"background-color: cyan;\">");
Write("<span style = \"background-color: DarkCyan;\">");
break;
case fmt::terminal_color::white:
Write("<span style = \"background-color: gray;\">");
Write("<span style = \"background-color: LightGray;\">");
break;
case fmt::terminal_color::bright_black:
Write("<span style = \"background-color: dark gray;\">");
Write("<span style = \"background-color: gray;\">");
break;
case fmt::terminal_color::bright_red:
Write("<span style = \"background-color: bright red;\">");
Write("<span style = \"background-color: Red;\">");
break;
case fmt::terminal_color::bright_green:
Write("<span style = \"background-color: bright green;\">");
Write("<span style = \"background-color: GreenYellow;\">");
break;
case fmt::terminal_color::bright_yellow:
Write("<span style = \"background-color: bright yellow;\">");
Write("<span style = \"background-color: Gold;\">");
break;
case fmt::terminal_color::bright_blue:
Write("<span style = \"background-color: bright blue;\">");
Write("<span style = \"background-color: LightSkyBlue;\">");
break;
case fmt::terminal_color::bright_magenta:
Write("<span style = \"background-color: bright magenta;\">");
Write("<span style = \"background-color: magenta;\">");
break;
case fmt::terminal_color::bright_cyan:
Write("<span style = \"background-color: bright cyan;\">");
Write("<span style = \"background-color: cyan;\">");
break;
case fmt::terminal_color::bright_white:
Write("<span style = \"background-color: white;\">");
Expand All @@ -174,4 +185,19 @@ void ToHTML::NewLine() const noexcept {
--tabs;
}
}
}
}

/// Clear the log file
void ToHTML::Clear() const noexcept {
mFile.close();
mFile.open(mFilename, std::ios::out | std::ios::trunc);
WriteHeader();
}

/// Write file header - general HTML styling options, etc.
void ToHTML::WriteHeader() const {
Write("<body style = \"color: gray; background-color: black; font-family: monospace; font-size: 14px;\">");
Write("<h1>Log started - ");
Write(GetAdvancedTime());
Write("</h1>");
}
Loading

0 comments on commit 3ab0496

Please sign in to comment.