首页 新闻 赞助 找找看

如何在Linux中获取终端当前的背景色与前景色

0
悬赏园豆:200 [待解决问题]

请问在Linux中如何通过命令或者C/C++代码获取终端(Terminal,也称控制台Console)当前的背景色(background color)与前景色(foreground color)?

这是一个很有挑战性的问题。连微软的开发人员在 corefx 的实现中也没找到有效的方法,在 ConsolePal.Unix.cs 的实现代码中有这样的注释:

public static ConsoleColor ForegroundColor
        {
            get { throw new PlatformNotSupportedException(SR.PlatformNotSupported_GettingColor); } // no general mechanism for getting the current color
            set { ChangeColor(foreground: true, color:  value); }
        }

        public static ConsoleColor BackgroundColor
        {
            get { throw new PlatformNotSupportedException(SR.PlatformNotSupported_GettingColor); } // no general mechanism for getting the current color
            set { ChangeColor(foreground: false, color: value); }
        }

【相关资料】

How to determine the current color of the console output?

dudu的主页 dudu | 高人七级 | 园豆:31075
提问于:2015-07-07 08:10
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册