Newer
Older
libj / include / j / io / term.hpp
/**
 * @file   term.hpp
 * @brief  端末制御ヘッダファイル。
 * @copyright  20177777773  Nomura Kei
 * @depends
 *   j.hpp
 */
#ifndef J_IO_TERM_HPP
#define J_IO_TERM_HPP

#include <string>
#include <j.hpp>

// ASCII エスケープコードによる表示
namespace j
{
    namespace io
    {
        namespace Term
        {
            // 装飾
            constexpr std::string_view CLR = "\x1b[0m"; //!< 装飾無し
            constexpr std::string_view BLD = "\x1b[1m"; //!< 太字
            constexpr std::string_view LGT = "\x1b[2m"; //!< 細字
            constexpr std::string_view ITA = "\x1b[3m"; //!< イタリック
            constexpr std::string_view UND = "\x1b[4m"; //!< 下線
            constexpr std::string_view BLN = "\x1b[5m"; //!< 点滅
            constexpr std::string_view FBL = "\x1b[6m"; //!< 高速点滅
            constexpr std::string_view INV = "\x1b[7m"; //!< 反転表示
            constexpr std::string_view HID = "\x1b[8m"; //!< 非表示 (コピーは可能)
            constexpr std::string_view CAN = "\x1b[9m"; //!< 取り消し

            // 文字色
            namespace Color
            {
                constexpr std::string_view DEF = "\x1b[39m";   //!< デフォルト
                constexpr std::string_view BLK = "\x1b[30m";   //!< 黒
                constexpr std::string_view RED = "\x1b[31m";   //!< 赤
                constexpr std::string_view GRN = "\x1b[32m";   //!< 緑
                constexpr std::string_view YEL = "\x1b[33m";   //!< 黄
                constexpr std::string_view BLU = "\x1b[34m";   //!< 青
                constexpr std::string_view MAG = "\x1b[35m";   //!< 紫
                constexpr std::string_view CYN = "\x1b[36m";   //!< 水
                constexpr std::string_view WHT = "\x1b[37m";   //!< 白
                constexpr std::string_view H_BLK = "\x1b[90m"; //!< 黒(高輝度)
                constexpr std::string_view H_RED = "\x1b[91m"; //!< 赤(高輝度)
                constexpr std::string_view H_GRN = "\x1b[92m"; //!< 緑(高輝度)
                constexpr std::string_view H_YEL = "\x1b[93m"; //!< 黄(高輝度)
                constexpr std::string_view H_BLU = "\x1b[94m"; //!< 青(高輝度)
                constexpr std::string_view H_MAG = "\x1b[95m"; //!< 紫(高輝度)
                constexpr std::string_view H_CYN = "\x1b[96m"; //!< 水(高輝度)
                constexpr std::string_view H_WHT = "\x1b[97m"; //!< 白(高輝度)
            }

            // 背景色
            namespace BgColor
            {
                constexpr std::string_view DEF = "\x1b[49m";    //!< デフォルト
                constexpr std::string_view BLK = "\x1b[40m";    //!< 黒
                constexpr std::string_view RED = "\x1b[41m";    //!< 赤
                constexpr std::string_view GRN = "\x1b[42m";    //!< 緑
                constexpr std::string_view YEL = "\x1b[43m";    //!< 黄
                constexpr std::string_view BLU = "\x1b[44m";    //!< 青
                constexpr std::string_view MAG = "\x1b[45m";    //!< 紫
                constexpr std::string_view CYN = "\x1b[46m";    //!< 水
                constexpr std::string_view WHT = "\x1b[47m";    //!< 白
                constexpr std::string_view H_BLK = "\x1b[100m"; //!< 黒(高輝度)
                constexpr std::string_view H_RED = "\x1b[101m"; //!< 赤(高輝度)
                constexpr std::string_view H_GRN = "\x1b[102m"; //!< 緑(高輝度)
                constexpr std::string_view H_YEL = "\x1b[103m"; //!< 黄(高輝度)
                constexpr std::string_view H_BLU = "\x1b[104m"; //!< 青(高輝度)
                constexpr std::string_view H_MAG = "\x1b[105m"; //!< 紫(高輝度)
                constexpr std::string_view H_CYN = "\x1b[106m"; //!< 水(高輝度)
                constexpr std::string_view H_WHT = "\x1b[107m"; //!< 白(高輝度)
            }

            // カーソル移動
            namespace Cursor
            {
                constexpr std::string_view DEL_AFT = "\x1b[0J";      //!< カーソル以降を消去
                constexpr std::string_view DEL_BEF = "\x1b[1J";      //!< カーソル以前を消去
                constexpr std::string_view DEL = "\x1b[2J";          //!< 全体を消去
                constexpr std::string_view DEL_AFT_LINE = "\x1b[0K"; //!< カーソル行のカーソル以降を消去
                constexpr std::string_view DEL_BEF_LINE = "\x1b[1K"; //!< カーソル行のカーソル以前を消去
                constexpr std::string_view DEL_LINE = "\x1b[2K";     //!< カーソル行を消去

                std::string_view MAKE_ESC_SEQ(const char *code, int n, const char *delim = nullptr, int m = 0);

                inline std::string_view UP(int n) { return MAKE_ESC_SEQ("A", n); }                  //!< n 上に移動
                inline std::string_view DOWN(int n) { return MAKE_ESC_SEQ("B", n); }                //!< n 下に移動
                inline std::string_view RIGHT(int n) { return MAKE_ESC_SEQ("C", n); }               //!< n 右に移動
                inline std::string_view LEFT(int n) { return MAKE_ESC_SEQ("D", n); }                //!< n 左に移動
                inline std::string_view DOWN_LINE(int n) { return MAKE_ESC_SEQ("E", n); }           //!< n 行下に移動(行頭[1列目]に移動)
                inline std::string_view UP_LINE(int n) { return MAKE_ESC_SEQ("F", n); }             //!< n 行上に移動(行頭[1列目]に移動)
                inline std::string_view COL(int n) { return MAKE_ESC_SEQ("G", n); }                 //!< n 列に移動
                inline std::string_view MOVE(int n, int m) { return MAKE_ESC_SEQ("H", n, ";", m); } //!< n 行, m 列に移動
                inline std::string_view SCROLL(int n) { return MAKE_ESC_SEQ("S", n); }              //!< n 行分次にスクロール
                inline std::string_view SCROLL_R(int n) { return MAKE_ESC_SEQ("T", n); }            //!< n 行分前にスクロール
            }
        }
    }
}

#endif // J_IO_TERM_HPP