Skip to content

Commit

Permalink
Fix a bug with the ubuntu ASCII art
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntRanch committed Jun 23, 2024
1 parent 54fe3e3 commit 6c95981
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion assets/ascii/ubuntu.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
${red} .-/+oossssoo+\-.
${red} ´:+ssssssssssssssssss+:`
${red} `:+ssssssssssssssssss+:`
${red} -+ssssssssssssssssssyyssss+-
${red} .ossssssssssssssssss${white}dMMMNy${red}sssso.
${red} /sssssssssss${white}hdmmNNmmyNMMMMh${red}ssssss\
Expand Down
3 changes: 2 additions & 1 deletion include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class RAM {
// Parse input, in-place, with data from systemInfo.
// Documentation on formatting is in the default config.toml file.
// pureOutput is set to the string, but without the brackets.
std::string parse(const std::string& input, systemInfo_t& systemInfo, const std::unique_ptr<std::string>& pureOutput, Config& config, colors_t& colors );
std::string parse(const std::string& input, systemInfo_t& systemInfo, std::string &pureOutput, Config& config, colors_t& colors );
std::string parse(const std::string& input, systemInfo_t& systemInfo, Config& config, colors_t& colors );

// Set module values to a systemInfo_t map.
// If the name of said module matches any module name, it will be added
Expand Down
19 changes: 11 additions & 8 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <magic.h>
#include <iostream>
#include <memory>

std::string Display::detect_distro(Config& config) {
Expand Down Expand Up @@ -60,8 +61,7 @@ std::vector<std::string>& Display::render(Config& config, colors_t& colors) {
}

for (std::string& layout : config.layouts) {
std::unique_ptr<std::string> _;
layout = parse(layout, systemInfo, _, config, colors);
layout = parse(layout, systemInfo, config, colors);
}

std::string path = config.m_display_distro ? detect_distro(config) : config.source_path;
Expand All @@ -75,20 +75,20 @@ std::vector<std::string>& Display::render(Config& config, colors_t& colors) {

std::string line;
std::vector<std::string> asciiArt;
std::vector<std::unique_ptr<std::string>> pureAsciiArt;
std::vector<std::string> pureAsciiArt;
int maxLineLength = -1;

while (std::getline(file, line)) {
std::unique_ptr<std::string> pureOutput = std::make_unique<std::string>();
std::string pureOutput;
std::string asciiArt_s = parse(line, systemInfo, pureOutput, config, colors);
asciiArt_s += config.gui ? "" : NOCOLOR;

asciiArt.push_back(asciiArt_s);

if (static_cast<int>(pureOutput->length()) > maxLineLength)
maxLineLength = pureOutput->length();
if (static_cast<int>(pureOutput.length()) > maxLineLength)
maxLineLength = pureOutput.length();

pureAsciiArt.push_back(std::move(pureOutput));
pureAsciiArt.push_back(pureOutput);
}

size_t i;
Expand All @@ -100,7 +100,10 @@ std::vector<std::string>& Display::render(Config& config, colors_t& colors) {
origin = asciiArt[i].length();
}

size_t spaces = (maxLineLength + (config.m_disable_source ? 1 : config.offset)) - (i < asciiArt.size() ? pureAsciiArt[i]->length() : 0);
size_t spaces = (maxLineLength + (config.m_disable_source ? 1 : config.offset)) - (i < asciiArt.size() ? pureAsciiArt[i].length() : 0);

debug("spaces: {}", spaces);

for (size_t j = 0; j < spaces; j++)
config.layouts[i].insert(origin, " ");

Expand Down
5 changes: 2 additions & 3 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ static std::vector<std::string>& render_with_image(Config& config, colors_t& col
}

for (std::string& layout : config.layouts) {
std::unique_ptr<std::string> _;
layout = parse(layout, systemInfo, _, config, colors);
layout = parse(layout, systemInfo, config, colors);
}

for (size_t i = 0; i < config.layouts.size(); i++) {
for (size_t _ = 0; _ < config.offset; _++) // I use _ because we don't need it
config.layouts.at(i).insert(0, " ");
config.layouts[i].insert(0, " ");
}
config.offset = 0;

Expand Down
24 changes: 14 additions & 10 deletions src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ static std::string getInfoFromName( systemInfo_t& systemInfo, const std::string&
};
}

std::string parse( const std::string& input, systemInfo_t& systemInfo, const std::unique_ptr<std::string>& pureOutput, Config& config, colors_t& colors )
std::string _parse( const std::string& input, systemInfo_t& systemInfo, std::string &pureOutput, Config& config, colors_t& colors )
{
std::string output = input;
if ( pureOutput )
*pureOutput = output;
pureOutput = output;

size_t dollarSignIndex = 0;
size_t pureOutputOffset = 0;
Expand Down Expand Up @@ -207,8 +206,7 @@ std::string parse( const std::string& input, systemInfo_t& systemInfo, const std
if ( command == "0" )
{
output = output.replace( dollarSignIndex, ( endBracketIndex + 1 ) - dollarSignIndex, config.gui ? "</span><span>" : NOCOLOR );
if ( pureOutput )
*pureOutput = pureOutput->replace( pureOutput->size() /*dollarSignIndex-pureOutputOffset*/,
pureOutput = pureOutput.replace( pureOutput.size() /*dollarSignIndex-pureOutputOffset*/,
( endBracketIndex + 1 ) - dollarSignIndex, "" );

pureOutputOffset += endBracketIndex - dollarSignIndex + 1;
Expand Down Expand Up @@ -259,8 +257,7 @@ std::string parse( const std::string& input, systemInfo_t& systemInfo, const std
else
error( "PARSER: failed to parse line with color '{}'", str_clr );

if ( pureOutput )
*pureOutput = pureOutput->replace( pureOutput->size() /*dollarSignIndex - pureOutputOffset*/,
pureOutput = pureOutput.replace( pureOutput.size() /*dollarSignIndex - pureOutputOffset*/,
endBracketIndex - dollarSignIndex + 1, "" );

pureOutputOffset += endBracketIndex - dollarSignIndex + 1;
Expand Down Expand Up @@ -316,11 +313,10 @@ std::string parse( const std::string& input, systemInfo_t& systemInfo, const std

output = output.replace( dollarSignIndex, output.length() - dollarSignIndex, formatted_replacement_string);

if ( pureOutput )
*pureOutput = pureOutput->replace(dollarSignIndex - pureOutputOffset,
pureOutput = pureOutput.replace(dollarSignIndex - pureOutputOffset,
endBracketIndex - dollarSignIndex + 1, "" );

pureOutputOffset += formatted_replacement_string.length() - unformatted_replacement_string.length() - 1;
pureOutputOffset += formatted_replacement_string.length() - unformatted_replacement_string.length() - 4;
}
}
break;
Expand All @@ -330,6 +326,14 @@ std::string parse( const std::string& input, systemInfo_t& systemInfo, const std
return output;
}

std::string parse(const std::string& input, systemInfo_t& systemInfo, std::string &pureOutput, Config& config, colors_t& colors ) {
return _parse(input, systemInfo, pureOutput, config, colors);
}
std::string parse(const std::string& input, systemInfo_t& systemInfo, Config& config, colors_t& colors ) {
std::string _;
return _parse(input, systemInfo, _, config, colors);
}

void addModuleValues(systemInfo_t& sysInfo, const std::string_view moduleName) {
// yikes, here we go.

Expand Down

0 comments on commit 6c95981

Please sign in to comment.