AK: Rename new_out to out and new_warn to warn.
This commit is contained in:
parent
74438e6fdc
commit
3b3edbc4d2
Notes:
sideshowbarker
2024-07-19 01:29:10 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/3b3edbc4d20 Pull-request: https://github.com/SerenityOS/serenity/pull/4005
10 changed files with 38 additions and 41 deletions
13
AK/Format.h
13
AK/Format.h
|
@ -309,27 +309,24 @@ void vformat(const LogStream& stream, StringView fmtstr, TypeErasedFormatParams)
|
|||
#ifndef KERNEL
|
||||
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams, bool newline = false);
|
||||
|
||||
// FIXME: Rename 'new_out' to 'out' when the name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_out(FILE* file, StringView fmtstr, const Parameters&... parameters) { vout(file, fmtstr, VariadicFormatParams { parameters... }); }
|
||||
void out(FILE* file, StringView fmtstr, const Parameters&... parameters) { vout(file, fmtstr, VariadicFormatParams { parameters... }); }
|
||||
template<typename... Parameters>
|
||||
void outln(FILE* file, StringView fmtstr, const Parameters&... parameters) { vout(file, fmtstr, VariadicFormatParams { parameters... }, true); }
|
||||
template<typename... Parameters>
|
||||
void outln(FILE* file, const char* fmtstr, const Parameters&... parameters) { vout(file, fmtstr, VariadicFormatParams { parameters... }, true); }
|
||||
inline void outln(FILE* file) { fputc('\n', file); }
|
||||
|
||||
// FIXME: Rename 'new_out' to 'out' when the name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_out(StringView fmtstr, const Parameters&... parameters) { new_out(stdout, fmtstr, parameters...); }
|
||||
void out(StringView fmtstr, const Parameters&... parameters) { out(stdout, fmtstr, parameters...); }
|
||||
template<typename... Parameters>
|
||||
void outln(StringView fmtstr, const Parameters&... parameters) { outln(stdout, fmtstr, parameters...); }
|
||||
template<typename... Parameters>
|
||||
void outln(const char* fmtstr, const Parameters&... parameters) { outln(stdout, fmtstr, parameters...); }
|
||||
inline void outln() { outln(stdout); }
|
||||
|
||||
// FIXME: Rename 'new_warn' to 'warn' when the name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_warn(StringView fmtstr, const Parameters&... parameters) { new_out(stderr, fmtstr, parameters...); }
|
||||
void warn(StringView fmtstr, const Parameters&... parameters) { out(stderr, fmtstr, parameters...); }
|
||||
template<typename... Parameters>
|
||||
void warnln(StringView fmtstr, const Parameters&... parameters) { outln(stderr, fmtstr, parameters...); }
|
||||
template<typename... Parameters>
|
||||
|
@ -385,10 +382,10 @@ struct Formatter<FormatIfSupported<T>> : __FormatIfSupported<T, HasFormatter<T>:
|
|||
} // namespace AK
|
||||
|
||||
#ifndef KERNEL
|
||||
using AK::new_out;
|
||||
using AK::out;
|
||||
using AK::outln;
|
||||
|
||||
using AK::new_warn;
|
||||
using AK::warn;
|
||||
using AK::warnln;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ TEST_CASE(file_descriptor)
|
|||
FILE* file = fdopen(fd, "w+");
|
||||
|
||||
outln(file, "{}", "Hello, World!");
|
||||
new_out(file, "foo");
|
||||
out(file, "foo");
|
||||
outln(file, "bar");
|
||||
|
||||
rewind(file);
|
||||
|
|
|
@ -150,14 +150,14 @@ static bool handle_breakpoint_command(const String& command)
|
|||
|
||||
static void print_help()
|
||||
{
|
||||
new_out("Options:\n"
|
||||
"cont - Continue execution\n"
|
||||
"si - step to the next instruction\n"
|
||||
"sl - step to the next source line\n"
|
||||
"line - show the position of the current instruction in the source code\n"
|
||||
"regs - Print registers\n"
|
||||
"dis [number of instructions] - Print disassembly\n"
|
||||
"bp <address/symbol/file:line> - Insert a breakpoint\n");
|
||||
out("Options:\n"
|
||||
"cont - Continue execution\n"
|
||||
"si - step to the next instruction\n"
|
||||
"sl - step to the next source line\n"
|
||||
"line - show the position of the current instruction in the source code\n"
|
||||
"regs - Print registers\n"
|
||||
"dis [number of instructions] - Print disassembly\n"
|
||||
"bp <address/symbol/file:line> - Insert a breakpoint\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
|
@ -49,7 +49,7 @@ int main(int argc, char** argv, char** envp)
|
|||
auto byte_ptr = (uint8_t*)auxvp->a_un.a_ptr;
|
||||
outln(" My Random bytes are: ");
|
||||
for (size_t i = 0; i < 16; ++i)
|
||||
new_out("{:#02x} ", byte_ptr[i]);
|
||||
out("{:#02x} ", byte_ptr[i]);
|
||||
outln();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ void Project::rebuild_tree()
|
|||
#if 0
|
||||
Function<void(ProjectTreeNode&, int indent)> dump_tree = [&](ProjectTreeNode& node, int indent) {
|
||||
for (int i = 0; i < indent; ++i)
|
||||
new_out(" ");
|
||||
out(" ");
|
||||
if (node.name.is_null())
|
||||
outln("(null)");
|
||||
else
|
||||
|
|
|
@ -181,28 +181,28 @@ bool ArgsParser::parse(int argc, char** argv, bool exit_on_failure)
|
|||
|
||||
void ArgsParser::print_usage(FILE* file, const char* argv0)
|
||||
{
|
||||
new_out(file, "Usage:\n\t\033[1m{}\033[0m", argv0);
|
||||
out(file, "Usage:\n\t\033[1m{}\033[0m", argv0);
|
||||
|
||||
for (auto& opt : m_options) {
|
||||
if (opt.long_name && !strcmp(opt.long_name, "help"))
|
||||
continue;
|
||||
if (opt.requires_argument)
|
||||
new_out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
||||
out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
||||
else
|
||||
new_out(file, " [{}]", opt.name_for_display());
|
||||
out(file, " [{}]", opt.name_for_display());
|
||||
}
|
||||
for (auto& arg : m_positional_args) {
|
||||
bool required = arg.min_values > 0;
|
||||
bool repeated = arg.max_values > 1;
|
||||
|
||||
if (required && repeated)
|
||||
new_out(file, " <{}...>", arg.name);
|
||||
out(file, " <{}...>", arg.name);
|
||||
else if (required && !repeated)
|
||||
new_out(file, " <{}>", arg.name);
|
||||
out(file, " <{}>", arg.name);
|
||||
else if (!required && repeated)
|
||||
new_out(file, " [{}...]", arg.name);
|
||||
out(file, " [{}...]", arg.name);
|
||||
else if (!required && !repeated)
|
||||
new_out(file, " [{}]", arg.name);
|
||||
out(file, " [{}]", arg.name);
|
||||
}
|
||||
outln(file);
|
||||
|
||||
|
@ -212,25 +212,25 @@ void ArgsParser::print_usage(FILE* file, const char* argv0)
|
|||
auto print_argument = [&]() {
|
||||
if (opt.value_name) {
|
||||
if (opt.requires_argument)
|
||||
new_out(file, " {}", opt.value_name);
|
||||
out(file, " {}", opt.value_name);
|
||||
else
|
||||
new_out(file, " [{}]", opt.value_name);
|
||||
out(file, " [{}]", opt.value_name);
|
||||
}
|
||||
};
|
||||
new_out(file, "\t");
|
||||
out(file, "\t");
|
||||
if (opt.short_name) {
|
||||
new_out(file, "\033[1m-{}\033[0m", opt.short_name);
|
||||
out(file, "\033[1m-{}\033[0m", opt.short_name);
|
||||
print_argument();
|
||||
}
|
||||
if (opt.short_name && opt.long_name)
|
||||
new_out(file, ", ");
|
||||
out(file, ", ");
|
||||
if (opt.long_name) {
|
||||
new_out(file, "\033[1m--{}\033[0m", opt.long_name);
|
||||
out(file, "\033[1m--{}\033[0m", opt.long_name);
|
||||
print_argument();
|
||||
}
|
||||
|
||||
if (opt.help_string)
|
||||
new_out(file, "\t{}", opt.help_string);
|
||||
out(file, "\t{}", opt.help_string);
|
||||
outln(file);
|
||||
}
|
||||
|
||||
|
@ -238,9 +238,9 @@ void ArgsParser::print_usage(FILE* file, const char* argv0)
|
|||
outln(file, "\nArguments:");
|
||||
|
||||
for (auto& arg : m_positional_args) {
|
||||
new_out(file, "\t\033[1m{}\033[0m", arg.name);
|
||||
out(file, "\t\033[1m{}\033[0m", arg.name);
|
||||
if (arg.help_string)
|
||||
new_out(file, "\t{}", arg.help_string);
|
||||
out(file, "\t{}", arg.help_string);
|
||||
outln(file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ Print the value of EXPRESSION to standard output.)");
|
|||
template<typename... Args>
|
||||
[[noreturn]] void fail(Args&&... args)
|
||||
{
|
||||
new_warn("ERROR: \e[31m");
|
||||
warn("ERROR: \e[31m");
|
||||
warnln(args...);
|
||||
new_warn("\e[0m");
|
||||
warn("\e[0m");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ static void handle_sigint(int)
|
|||
static void print_function_call(String function_name, size_t depth)
|
||||
{
|
||||
for (size_t i = 0; i < depth; ++i) {
|
||||
new_out(" ");
|
||||
out(" ");
|
||||
}
|
||||
outln("=> {}", function_name);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
|||
for (size_t i = 0; i < NSIG; ++i) {
|
||||
if (i && !(i % 5))
|
||||
outln("");
|
||||
new_out("{:2}) {:10}", i, getsignalname(i));
|
||||
out("{:2}) {:10}", i, getsignalname(i));
|
||||
}
|
||||
outln("");
|
||||
return 0;
|
||||
|
|
|
@ -51,11 +51,11 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
|
|||
} else {
|
||||
root_indent_string = "";
|
||||
}
|
||||
new_out("{}|-- ", root_indent_string);
|
||||
out("{}|-- ", root_indent_string);
|
||||
}
|
||||
|
||||
String root_dir_name = AK::LexicalPath(root_path).basename();
|
||||
new_out("\033[34;1m{}\033[0m\n", root_dir_name);
|
||||
out("\033[34;1m{}\033[0m\n", root_dir_name);
|
||||
|
||||
if (depth >= max_depth) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue