summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/admin/ladmin.cpp22
-rw-r--r--src/char/char.cpp9
-rw-r--r--src/io/tty.cpp21
-rw-r--r--src/io/tty.hpp38
-rw-r--r--src/login/login.cpp11
-rw-r--r--src/map/map.cpp7
6 files changed, 82 insertions, 26 deletions
diff --git a/src/admin/ladmin.cpp b/src/admin/ladmin.cpp
index 2c9382c..d875205 100644
--- a/src/admin/ladmin.cpp
+++ b/src/admin/ladmin.cpp
@@ -13,6 +13,7 @@
#include "../io/cxxstdio.hpp"
#include "../io/read.hpp"
+#include "../io/tty.hpp"
#include "../io/write.hpp"
#include "../common/config_parse.hpp"
@@ -990,7 +991,7 @@ void delaccount(ZString param)
char confirm;
do
{
- PRINTF("\033[1;36m ** Are you really sure to DELETE account [%s]? (y/n) > \033[0m", name);
+ PRINTF(SGR_BOLD SGR_CYAN " ** Are you really sure to DELETE account [%s]? (y/n) > " SGR_RESET, name);
fflush(stdout);
int seek = getchar();
confirm = seek;
@@ -1763,17 +1764,10 @@ void prompt(void)
// while we don't wait new packets
while (bytes_to_read == 0)
{
- // for help with the console colors look here:
- // http://www.edoceo.com/liberum/?doc=PRINTF-with-color
- // some code explanation (used here):
- // \033[2J : clear screen and go up/left (0, 0 position)
- // \033[K : clear line from actual position to end of the line
- // \033[0m : reset color parameter
- // \033[1m : use bold for font
Iprintf("\n");
- Iprintf("\033[32mTo list the commands, type 'enter'.\033[0m\n");
- Iprintf("\033[0;36mLadmin-> \033[0m");
- Iprintf("\033[1m");
+ Iprintf(SGR_GREEN "To list the commands, type 'enter'." SGR_RESET "\n");
+ Iprintf(SGR_CYAN "Ladmin-> " SGR_RESET);
+ Iprintf(SGR_BOLD);
fflush(stdout);
// get command and parameter
@@ -1782,7 +1776,7 @@ void prompt(void)
FString buf;
cin->getline(buf);
- Iprintf("\033[0m");
+ Iprintf(SGR_RESET);
fflush(stdout);
if (!cin->is_open())
@@ -2835,7 +2829,7 @@ void term_func(void)
{
delete_session(login_session);
- Iprintf("\033[0m----End of Ladmin (normal end with closing of all files).\n");
+ Iprintf(SGR_RESET "----End of Ladmin (normal end with closing of all files).\n");
LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n");
already_exit_function = 1;
@@ -2896,7 +2890,7 @@ int do_init(int argc, ZString *argv)
version.vend);
LADMIN_LOG("Ladmin is ready.\n");
- Iprintf("Ladmin is \033[1;32mready\033[0m.\n\n");
+ Iprintf("Ladmin is " SGR_BOLD SGR_GREEN "ready" SGR_RESET ".\n\n");
Connect_login_server();
diff --git a/src/char/char.cpp b/src/char/char.cpp
index fe9bf9a..15ea46b 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -23,6 +23,7 @@
#include "../io/cxxstdio.hpp"
#include "../io/lock.hpp"
#include "../io/read.hpp"
+#include "../io/tty.hpp"
#include "../common/config_parse.hpp"
#include "../common/core.hpp"
@@ -2057,8 +2058,8 @@ int lan_ip_check(IP4Address addr)
{
bool lancheck = lan_subnet.covers(addr);
- PRINTF("LAN test (result): %s source\033[0m.\n",
- (lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
+ PRINTF("LAN test (result): %s.\n",
+ (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET);
return lancheck;
}
@@ -2625,7 +2626,7 @@ bool lan_check()
PRINTF("LAN test of LAN IP of the map-server: ");
if (!lan_ip_check(lan_map_ip))
{
- PRINTF("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
+ PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network." SGR_RESET "\n");
return false;
}
}
@@ -2894,7 +2895,7 @@ int do_init(int argc, ZString *argv)
CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n",
char_port);
- PRINTF("The char-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The char-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n",
char_port);
return 0;
diff --git a/src/io/tty.cpp b/src/io/tty.cpp
new file mode 100644
index 0000000..d2e084e
--- /dev/null
+++ b/src/io/tty.cpp
@@ -0,0 +1,21 @@
+#include "tty.hpp"
+// io/tty.cpp - terminal escape sequences
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/* Nothing to see here, move along */
diff --git a/src/io/tty.hpp b/src/io/tty.hpp
new file mode 100644
index 0000000..86616f1
--- /dev/null
+++ b/src/io/tty.hpp
@@ -0,0 +1,38 @@
+#ifndef TMWA_IO_TTY_HPP
+#define TMWA_IO_TTY_HPP
+// io/tty.hpp - terminal escape sequences
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# include "../sanity.hpp"
+
+
+# define SGR_BLACK "\e[30m"
+# define SGR_RED "\e[31m"
+# define SGR_GREEN "\e[32m"
+# define SGR_YELLOW "\e[33m"
+# define SGR_BLUE "\e[34m"
+# define SGR_MAGENTA "\e[35m"
+# define SGR_CYAN "\e[36m"
+# define SGR_WHITE "\e[37m"
+
+# define SGR_BOLD "\e[1m"
+
+# define SGR_RESET "\e[0m"
+
+#endif //TMWA_IO_TTY_HPP
diff --git a/src/login/login.cpp b/src/login/login.cpp
index ba247b6..b1d37dc 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -23,6 +23,7 @@
#include "../io/cxxstdio.hpp"
#include "../io/lock.hpp"
#include "../io/read.hpp"
+#include "../io/tty.hpp"
#include "../common/config_parse.hpp"
#include "../common/core.hpp"
@@ -537,7 +538,7 @@ int mmo_auth_init(void)
{
// no account file -> no account -> no login, including char-server (ERROR)
// not anymore! :-)
- PRINTF("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n",
+ PRINTF(SGR_BOLD SGR_RED "mmo_auth_init: Accounts file [%s] not found." SGR_RESET "\n",
account_filename);
return 0;
}
@@ -2693,8 +2694,8 @@ bool lan_ip_check(IP4Address p)
{
bool lancheck = lan_subnet.covers(p);
- PRINTF("LAN test (result): %s source\033[0m.\n",
- (lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
+ PRINTF("LAN test (result): %s.\n",
+ (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET);
return lancheck;
}
@@ -3193,7 +3194,7 @@ bool lan_check()
PRINTF("LAN test of LAN IP of the char-server: ");
if (!lan_ip_check(lan_char_ip))
{
- PRINTF("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n");
+ PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network" SGR_RESET "\n");
LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
return false;
}
@@ -3897,7 +3898,7 @@ int do_init(int argc, ZString *argv)
LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n",
login_port);
- PRINTF("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The login-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n",
login_port);
return 0;
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 2600412..8a1d8eb 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -16,8 +16,9 @@
#include "../strings/vstring.hpp"
#include "../io/cxxstdio.hpp"
-#include "../io/write.hpp"
#include "../io/read.hpp"
+#include "../io/tty.hpp"
+#include "../io/write.hpp"
#include "../common/config_parse.hpp"
#include "../common/core.hpp"
@@ -1733,9 +1734,9 @@ int do_init(int argc, ZString *argv)
npc_event_do_oninit(); // npcのOnInitイベント実行
if (battle_config.pk_mode == 1)
- PRINTF("The server is running in \033[1;31mPK Mode\033[0m.\n");
+ PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n");
- PRINTF("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n",
clif_getport());
return 0;