dropshell release 2025.0521.1906
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
@ -42,7 +42,7 @@ namespace dropshell
|
||||
std::lock_guard<std::mutex> lock(output_mutex);
|
||||
if (c == EOF)
|
||||
return !EOF;
|
||||
if (at_line_start_ && c != '\n')
|
||||
if (at_line_start_) // && c != '\n')
|
||||
{
|
||||
dest_ << GREY << tag_ << RESET << ' ' << colour_;
|
||||
at_line_start_ = false;
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
#include <random>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
@ -388,4 +390,46 @@ std::string substitute_provided_key_value_pairs(std::string str, const std::map<
|
||||
return result;
|
||||
}
|
||||
|
||||
int get_console_width()
|
||||
{
|
||||
struct winsize w;
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0) {
|
||||
return w.ws_col;
|
||||
}
|
||||
// Fallback to a reasonable default if we can't get the width
|
||||
return 80;
|
||||
}
|
||||
|
||||
std::string remove_return(std::string str)
|
||||
{
|
||||
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string get_line_wrap(std::string &src, int maxchars)
|
||||
{
|
||||
if (src.empty())
|
||||
return "";
|
||||
|
||||
if (src.length() <= maxchars)
|
||||
{
|
||||
std::string out = src;
|
||||
src.erase();
|
||||
return remove_return(out) + '\n';
|
||||
}
|
||||
|
||||
// find last whitespace up to but not more than maxchars
|
||||
size_t grab_to=maxchars;
|
||||
size_t lastreturn = src.rfind('\n', maxchars);
|
||||
size_t lastspace = src.rfind(' ', maxchars);
|
||||
if (lastreturn != std::string::npos)
|
||||
grab_to = lastreturn;
|
||||
else if (lastspace != std::string::npos)
|
||||
grab_to = lastspace;
|
||||
|
||||
std::string out = src.substr(0, grab_to);
|
||||
src = src.substr(grab_to + 1);
|
||||
return remove_return(out) + '\n';
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
@ -55,4 +55,8 @@ std::string center_align(const std::string & str, int width);
|
||||
std::string replace_with_environment_variables_like_bash(std::string str);
|
||||
std::string substitute_provided_key_value_pairs(std::string str, const std::map<std::string, std::string> & env_vars);
|
||||
|
||||
int get_console_width();
|
||||
|
||||
std::string get_line_wrap(std::string & src, int maxchars);
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user