Overhaul to console structure, a bit
This commit is contained in:
+26
-26
@@ -79,29 +79,29 @@ namespace command {
|
||||
if (partial.has_value() && !name.starts_with(partial.value())) {
|
||||
continue;
|
||||
}
|
||||
Con_SafePrintf(" %s\n", name.c_str());
|
||||
console::safe_print(" %s\n", name.c_str());
|
||||
count++;
|
||||
}
|
||||
|
||||
Con_SafePrintf("%i commands", count);
|
||||
console::safe_print("%i commands", count);
|
||||
if (partial) {
|
||||
Con_SafePrintf(" beginning with \"%s\"", partial->c_str());
|
||||
console::safe_print(" beginning with \"%s\"", partial->c_str());
|
||||
}
|
||||
Con_SafePrintf("\n");
|
||||
console::safe_print("\n");
|
||||
}
|
||||
|
||||
void _unalias() {
|
||||
switch (argc()) {
|
||||
default:
|
||||
case 1:
|
||||
Con_Printf("unalias <name> : delete alias\n");
|
||||
console::info("unalias <name> : delete alias\n");
|
||||
break;
|
||||
case 2: {
|
||||
const auto name = argv(1).value();
|
||||
if (ALIASES.contains(name)) {
|
||||
ALIASES.erase(name);
|
||||
} else {
|
||||
Con_Printf("No alias named %s\n", name.c_str());
|
||||
console::info("No alias named %s\n", name.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -114,13 +114,13 @@ namespace command {
|
||||
//list all aliases
|
||||
auto count = 0;
|
||||
for (auto &[name, alias]: ALIASES) {
|
||||
Con_SafePrintf(" %s: %s", name.c_str(), alias.value.c_str());
|
||||
console::safe_print(" %s: %s", name.c_str(), alias.value.c_str());
|
||||
count++;
|
||||
}
|
||||
if (count != 0)
|
||||
Con_SafePrintf("%i alias command(s)\n", count);
|
||||
console::safe_print("%i alias command(s)\n", count);
|
||||
else
|
||||
Con_SafePrintf("no alias commands found\n");
|
||||
console::safe_print("no alias commands found\n");
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
@@ -128,14 +128,14 @@ namespace command {
|
||||
const auto lookup = argv(1).value();
|
||||
for (auto &[name, alias]: ALIASES)
|
||||
if (name.starts_with(lookup))
|
||||
Con_Printf(" %s: %s", name.c_str(), alias.value.c_str());
|
||||
console::info(" %s: %s", name.c_str(), alias.value.c_str());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
//set alias string
|
||||
const auto new_name = argv(1).value();
|
||||
if (new_name.length() >= MAX_ALIAS_LENGTH) {
|
||||
Con_Printf("Alias name is too long\n");
|
||||
console::info("Alias name is too long\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace command {
|
||||
|
||||
void _exec() {
|
||||
if (argc() != 2) {
|
||||
Con_Printf("exec <filename> : execute a script file\n");
|
||||
console::info("exec <filename> : execute a script file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,10 +225,10 @@ namespace command {
|
||||
f = default_cfg; /* see above.. */
|
||||
}
|
||||
if (f == nullptr) {
|
||||
Con_Printf("couldn't exec %s\n", argv(1)->c_str());
|
||||
console::info("couldn't exec %s\n", argv(1)->c_str());
|
||||
return;
|
||||
}
|
||||
Con_Printf("execing %s\n", argv(1)->c_str());
|
||||
console::info("execing %s\n", argv(1)->c_str());
|
||||
|
||||
buffer::insert_text(f);
|
||||
if (f != default_cfg) {
|
||||
@@ -238,8 +238,8 @@ namespace command {
|
||||
|
||||
void _echo() {
|
||||
for (auto i = 1; i < argc(); i++)
|
||||
Con_Printf("%s ", argv(i)->c_str());
|
||||
Con_Printf("\n");
|
||||
console::info("%s ", argv(i)->c_str());
|
||||
console::info("\n");
|
||||
}
|
||||
|
||||
char *tint_substring(const char *in, const char *substr, char *out, const size_t outsize) {
|
||||
@@ -266,14 +266,14 @@ namespace command {
|
||||
int hits = 0;
|
||||
const auto substr = argv(1);
|
||||
if (!substr.has_value()) {
|
||||
Con_SafePrintf("%s <substring> : search through commands and cvars for the given substring\n",
|
||||
console::safe_print("%s <substring> : search through commands and cvars for the given substring\n",
|
||||
argv(0).value().c_str());
|
||||
return;
|
||||
}
|
||||
for (const auto &name: REFS | std::views::keys) {
|
||||
if (q_strcasestr(name.c_str(), substr.value().c_str())) {
|
||||
hits++;
|
||||
Con_SafePrintf(
|
||||
console::safe_print(
|
||||
"%s\n", tint_substring(name.c_str(), substr.value().c_str(), tmpbuf, sizeof(tmpbuf)));
|
||||
}
|
||||
}
|
||||
@@ -281,13 +281,13 @@ namespace command {
|
||||
for (const auto &var: convar::get_variables()) {
|
||||
if (q_strcasestr(var->name.c_str(), substr.value().c_str())) {
|
||||
hits++;
|
||||
Con_SafePrintf("%s (current value: \"%s\")\n",
|
||||
console::safe_print("%s (current value: \"%s\")\n",
|
||||
tint_substring(var->name.c_str(), substr.value().c_str(), tmpbuf, sizeof(tmpbuf)),
|
||||
var->string);
|
||||
}
|
||||
}
|
||||
if (!hits)
|
||||
Con_SafePrintf("no cvars nor commands contain that substring\n");
|
||||
console::safe_print("no cvars nor commands contain that substring\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,14 +325,14 @@ namespace command {
|
||||
|
||||
// fail if the command is a variable name
|
||||
if (convar::variable_string(name).has_value()) {
|
||||
Con_Printf("Cmd_AddCommand: %s already defined as a var\n", name.c_str());
|
||||
console::info("Cmd_AddCommand: %s already defined as a var\n", name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// fail if the command already exists
|
||||
for (auto &[other_name, func]: std::ranges::views::values(REFS)) {
|
||||
if (name == other_name) {
|
||||
Con_Printf("Cmd_AddCommand: %s already defined\n", name.c_str());
|
||||
console::info("Cmd_AddCommand: %s already defined\n", name.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -433,12 +433,12 @@ namespace command {
|
||||
|
||||
// check cvars
|
||||
if (!Cvar_Command())
|
||||
Con_Printf("Unknown command \"%s\"\n", argv(0).value().c_str());
|
||||
console::info("Unknown command \"%s\"\n", argv(0).value().c_str());
|
||||
}
|
||||
|
||||
void forward_to_server() {
|
||||
if (cls.state != ca_connected) {
|
||||
Con_Printf("Can't \"%s\", not connected\n", argv(0).value_or("").c_str());
|
||||
console::info("Can't \"%s\", not connected\n", argv(0).value_or("").c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ namespace command::buffer {
|
||||
|
||||
void add_text(const std::string &text) {
|
||||
if (_buffer.length() + text.length() >= MAX_BUFFER_SIZE) {
|
||||
Con_Printf("command::buffer::add_text(): overflow\n");
|
||||
console::info("command::buffer::add_text(): overflow\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ namespace command::buffer {
|
||||
|
||||
void insert_text(const std::string &text) {
|
||||
if (_buffer.length() + text.length() >= MAX_BUFFER_SIZE) {
|
||||
Con_Printf("command::buffer::insert_text(): overflow\n");
|
||||
console::info("command::buffer::insert_text(): overflow\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user