首页 > 系统相关 >Fileheader 1.13.1 - ColorLinux

Fileheader 1.13.1 - ColorLinux

时间:2024-10-15 17:36:02浏览次数:1  
标签:__ info const 1.13 Fileheader color ColorLinux RED string

为了在控制台打印彩色内容而设计的头文件

早就想封了,今天实现一下

普通输出

这是第一版写的,因为觉得不好就弃用,但是并没有删,在某些场合可能会用的方便点

这一版定义了一个 color_print()

其定义为

#define color_print(x) printf("%s",((string)""+(x)+color.NONE).c_str())

可以看出来,你在 color_print() 函数中填入的应该是正常的字符串

当然你也可以像普通 printf 一样使用 color_print("12345") 来输出普通字符串,然而这并没有什么意义

因此,你可以在你要输出的字符串前面加上限定参数,譬如

color_print(color.RED+"12345");

这样控制台就会打印一个红色的字符串

所有诸如此类的字符串都在 color 结构体内,具体来说包含以下几个

    const string NONE

    const string BLACK
    const string L_BLACK
    const string RED
    const string L_RED
    const string GREEN
    const string L_GREEN
    const string BROWN
    const string YELLOW
    const string BLUE
    const string L_BLUE
    const string PURPLE
    const string L_PURPLE
    const string CYAN
    const string L_CYAN
    const string GRAY
    const string WHITE

    const string BOLD  //粗体
    const string UNDERLINE  //下划线
    const string BLINK   //闪烁
    const string REVERSE   //颜色反转
    const string HIDE   //隐藏
    const string CLEAR   //清屏

其中颜色标识的都是修改前景颜色的参数,带 L_颜色 的是高亮显示的颜色参数

这一版的特点

  • 可以拼接,比如 color_print(color.RED+"123"+color.GREEN+"45") 这样的用法
  • 只有一个限定参数,如果你使用 color_print(color.RED+color.UNDERLINE+"123"),程序会选择使用最后传入的限定参数,因此不会显示红色

printc

这一版个人觉得比较满意

程序定义了 printc(x,info),表示在 x 做限定参数的情况下输出 info,也就是说,x 是限定参数,info 是输出内容

#define printc(x,info) printf("%s",(__color_info.START()+(x)()+"m"+info+__color_info.NONE()).c_str())

关于限定参数的选取,你可以直接调用已经存在的 __color_info 中的内容,或者你嫌这个名字太长,也可以自行定义一个参数库

__color_t a;

然后你只需要从 a 中调用参数即可

可供选用的参数如下

    const __const_color_t START;
    const __const_color_t NONE;
    
    const color_t HIGHLIGHT; //高亮
    const color_t VAGUE;   //模糊,在 bash 下测试时,bash 对这个参数的行为是变暗
    const color_t ITALIC;  //斜体
    const color_t UNDERLINE; //下划线
    const color_t TWINKLE;  //高闪,bash 不处理这个参数
    const color_t FAST_TWINKLE;  //快速闪烁,base 不处理这个参数
    const color_t REVERSE_COLOR;  //颜色反转
    const color_t HIDE;    //隐藏

    struct{
        const color_t BLACK;
        const color_t RED;
        const color_t GREEN;
        const color_t YELLOW;
        const color_t BLUE;
        const color_t PERPLE;
        const color_t CRAY;
        const color_t WHITE;
    }FRONTCOLOR;

    struct{
        const color_t BLACK;
        const color_t RED;
        const color_t GREEN;
        const color_t YELLOW;
        const color_t BLUE;
        const color_t PERPLE;
        const color_t CRAY;
        const color_t WHITE;
    }BACKGROUND;

color_t 已经重载了加号,在你需要使用多个限定参数的时候,只需要使用加号将其拼接在一起即可

__color_t a;
printc(a.UNDERLINE+a.ITALIC+a.BACKGROUND.RED,"12345");

请注意参数可能会有冲突,比如选了两个背景颜色做限定参数,此时行为依控制台而定

源码

FileHeader

#ifndef COLORLINUX_H
#define COLORLINUX_H
#include<bits/stdc++.h>
using namespace std;
class color{
    public:

    const string NONE=                 "\e[0m";
    const string BLACK=                "\e[0;30m";
    const string L_BLACK=              "\e[1;30m";
    const string RED=                  "\e[0;31m";
    const string L_RED=                "\e[1;31m";
    const string GREEN=                "\e[0;32m";
    const string L_GREEN=              "\e[1;32m";
    const string BROWN=                "\e[0;33m";
    const string YELLOW=               "\e[1;33m";
    const string BLUE=                 "\e[0;34m";
    const string L_BLUE=               "\e[1;34m";
    const string PURPLE=               "\e[0;35m";
    const string L_PURPLE=             "\e[1;35m";
    const string CYAN=                 "\e[0;36m";
    const string L_CYAN=               "\e[1;36m";
    const string GRAY=                 "\e[0;37m";
    const string WHITE=                "\e[1;37m";

    const string BOLD=                 "\e[1m";
    const string UNDERLINE=            "\e[4m";
    const string BLINK=                "\e[5m";
    const string REVERSE=              "\e[7m";
    const string HIDE=                 "\e[8m";
    const string CLEAR=                "\e[2J";
}color;
class color_t{
    private:string x;
    public:
    color_t operator =(const std::string y){x=y;return *this;};
    color_t(const std::string y){x=y;}
    color_t operator +(const color_t&A)const{
        color_t ans=*this;ans.x=ans.x+";"+A.x;
        return ans;
    }
    const std::string operator()()const{return x;}
};
class __const_color_t{
    private:string x;
    public:
    __const_color_t operator =(const string y){x=y;return *this;};
    __const_color_t(const string y){x=y;}
    const string operator()()const{return x;}
};
class __color{
    public:
    const __const_color_t START=(string)"\e[";
    const __const_color_t NONE=(string)"\e[0m";
    
    const color_t HIGHLIGHT=(string)"1";
    const color_t VAGUE=(string)"2";
    const color_t ITALIC=(string)"3";
    const color_t UNDERLINE=(string)"4";
    const color_t TWINKLE=(string)"5";
    const color_t FAST_TWINKLE=(string)"6";
    const color_t REVERSE_COLOR=(string)"7";
    const color_t HIDE=(string)"8";

    struct{
        const color_t BLACK=(string)"30";
        const color_t RED=(string)"31";
        const color_t GREEN=(string)"32";
        const color_t YELLOW=(string)"33";
        const color_t BLUE=(string)"34";
        const color_t PERPLE=(string)"35";
        const color_t CRAY=(string)"36";
        const color_t WHITE=(string)"37";
    }FRONTCOLOR;

    struct{
        const color_t BLACK=(string)"40";
        const color_t RED=(string)"41";
        const color_t GREEN=(string)"42";
        const color_t YELLOW=(string)"43";
        const color_t BLUE=(string)"44";
        const color_t PERPLE=(string)"45";
        const color_t CRAY=(string)"46";
        const color_t WHITE=(string)"47";
    }BACKGROUND;
};
typedef __color __color_t;
__color_t __color_info;
#define color_print(x) printf("%s",((string)""+(x)+color.NONE).c_str())
#define printc(x,info) printf("%s",(__color_info.START()+(x)()+"m"+info+__color_info.NONE()).c_str())
#endif

标签:__,info,const,1.13,Fileheader,color,ColorLinux,RED,string
From: https://www.cnblogs.com/HaneDaCafe/p/18467949

相关文章

  • 随机组句小游戏-V1.13版本
    玩法:随机抽取地点人物事件,来组句2024/10/03进行微调.\(代码/Code:\)#include<bits/stdc++.h>#include<windows.h>#defineSM_printf("%c%c%c%c%c%c",-64,-18,-278,-59,-319,-40);usingnamespacestd;ints1,s2,s3,xz1,bool01;stringcopy_;stringplace[105]......
  • 1.13 - 动手学聚类算法
    1.基于距离的k-means聚类,需要人工提供聚簇数量K1.1通过肘方法确定最佳聚簇数量 importnumpyasnpimportmatplotlib.pyplotaspltfromsklearn.clusterimportKMeansfromsklearn.preprocessingimportStandardScalerfromsklearn.datasetsimportmake_blobs,lo......
  • rancher2.5.9部署flink1.13.1集群问题求教
    下面是我在rancher页面配置flink的yaml:apiVersion:batch/v1kind:Jobmetadata:name:flink-jobmanagernamespace:flink-resourcespec:template:metadata:labels:app:flinkcomponent:jobmanagerspec:restartPolicy:OnFailurecontainers:-name:jobmanagerima......
  • Ryujinx(Switch模拟器) v1.1.1361 汉化版
    Ryujinx是一款免费、开源的NintendoSwitch模拟器,它可以在电脑上模拟NintendoSwitch游戏机的运行环境,让玩家们能够在PC上畅玩Switch游戏。Ryujinx支持大部分NintendoSwitch游戏,包括TheLegendofZelda:BreathoftheWild、SuperMarioOdyssey等知名游戏,而且还......
  • vscode注释插件koroFileHeader使用, vue 文件注释插件
    使用文档https://github.com/OBKoro1/koro1FileHeader/wiki/安装和快速上手git地址https://github.com/OBKoro1/koro1FileHeader安装测试搜索setting.json用户输入如下配置//头部注释"fileheader.customMade":{//Author字段是文件的创建者可以在specialO......
  • Ryujinx(Switch模拟器) v1.1.1353 中文版
    Ryujinx是一款免费、开源的NintendoSwitch模拟器,它可以在电脑上模拟NintendoSwitch游戏机的运行环境,让玩家们能够在PC上畅玩Switch游戏。Ryujinx支持大部分NintendoSwitch游戏,包括TheLegendofZelda:BreathoftheWild、SuperMarioOdyssey等知名游戏,而且还......
  • 暗黑破坏神2版本1.13c的D2BS-kolbot(带踢桶功能)正式发布
    1、注意事项,尤其是自动开荒,请看其中的中文说明,特别提示:(1)得到act1的佣兵后,请手动更换一下,最好都是选冰属性并给其gamble一张弓(2)大约10级左右,角色就可以gamble到belt,请手动为之(3)进入act2后,立即手动更换佣兵,并gamble一把长柄(4)大约20级后就可以gamble到pike,这会大大增强佣兵大箱......
  • httpsok-v1.13.0支持七牛云证书自动部署
    ......
  • httpsok-v1.13.0支持nginx证书部署管理
    ......
  • Minio使用(Minio帮助类 3.1.13版本 )
    目录一、安装部署二、注册成window服务三、C#文件上传下载四、minio文件操作帮助类一、安装部署1、下载安装包:MinIO|高性能,对Kubernetes友好的对象存储2、放到磁盘中,后面会以这个文件进行服务器安装3、磁盘新建一个目录用于存放上传文件,比如我创建的为:Data4、......