Assembled from klammertext-dev f344a37d0f6e. The commands, the library,
the Standard Klammer Set, the reflection klammerset and the Python
binding build and run natively on Windows (MSYS2 UCRT64 gcc, python.org
Python), and both test tiers pass there. doc/install/windows_source_install.md
is the fifth install guide: a source install parallel to the Linux and
macOS ones, verified by following it on a pristine Windows 11.
Behaviour on every system: paths Klammertext prints use forward slashes;
output is LF; the command line is UTF-8 on Windows; @eval :shell is a
POSIX shell command everywhere -- on Windows it runs the sh Klammertext
ships, BusyBox for Windows (win/busybox/, GPLv2, with its licence and the
source pointer). KLAMMERTEXT_FONTS and KLAMMERTEXT_KLAMMERSETS are lists in
the system's PATH convention (';' on Windows). On Linux and macOS nothing
observable changes.
48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#include <sstream>
|
|
|
|
#include "error.h"
|
|
#include "show.h"
|
|
#include "util.h"
|
|
#include "file.h"
|
|
|
|
bool display_source(const std::string& filename_arg)
|
|
{
|
|
if (filename_arg.empty()) {
|
|
return false;
|
|
} else {
|
|
fs::path filename = fs::path(filename_arg).filename();
|
|
return sks_commands.count(filename.string()) == 0;
|
|
}
|
|
}
|
|
|
|
std::string Error::message(const std::string& epilog) const
|
|
{
|
|
// The separator is not cosmetic: the description ends with a sentence, and
|
|
// appending the advice straight onto it ran the two together into one word
|
|
// ("...for an unspecified targetkdiag loads no klammerset..."). m_desc is
|
|
// then justified to 80 columns, so the break has to be a blank line rather
|
|
// than a single newline, which justify() would fold back into the flow.
|
|
std::string desc = m_desc;
|
|
if (epilog != "") {
|
|
desc += "\n\n" + epilog + "\n";
|
|
}
|
|
std::stringstream ss {};
|
|
ss << command_name << " (" << m_type << " error)";
|
|
if (display_source(m_loc.m_filename)) {
|
|
ss << ":\n " << m_loc.m_filename;
|
|
}
|
|
if (m_loc.m_line > -1) {
|
|
ss << ", line " << m_loc.m_line;
|
|
}
|
|
if (m_loc.m_chr > -1) {
|
|
ss << ", character " << m_loc.m_chr + 1;
|
|
}
|
|
ss << ":\n\n" << justify(desc, 80, 0);
|
|
return ss.str();
|
|
}
|
|
|
|
void Error::print_message(const std::string& epilog)
|
|
{
|
|
std::cerr << "\n" << red << message(epilog) << reset << "\n";
|
|
}
|