-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Wednesday 4 November 2020

How to echo with different colors in the Windows command line







One of the most frequent requests we receive is to increase the number of colors that the Windows Console can support. We love nothing more than to deliver features you ask for!

But rather than just add a few more colors, or limit our console to a mere 256 colors, in Windows 10 Insiders Build #14931, 

we’ve updated the Windows Console to support full, glorious 24-bit RGB true color!

This is actually a little tricky to demo since most Windows apps only support 16 colors at most whereas the Linux world has broadly supported 256 color terminals for a while now, and 24-bit color is becoming more established.

Thanks to our ability to run Linux apps and scripts using our new Bash on Ubuntu on Windows environment atop the Windows Subsystem for Linux (WSL), we can use some Linux scripts and tools to demonstrate the Console’s new 24-bit color support:



We’ve not yet started work on improving the console properties page to support the Console’s new color rendering capabilities, and we’ve not modified the default Windows color mappings; we’ll be making improvements here, and on the many, MANY other features queued-up in our backlog in future builds.

Use ANSI Escape Sequences.

Windows before 10 - no native support for ANSI colors on the console

For Windows version below 10, the Windows command console doesn't support output coloring by default. You could install either CmderConEmuANSICON or Mintty (used by default in GitBash and Cygwin) to add coloring support to your Windows command console.

Windows 10 - Command Line Colors

Starting from Windows 10 the Windows console support ANSI Escape Sequences and some colors by default. The feature shipped with the Threshold 2 Update in Nov 2015.

MSDN Documentation

Update (05-2019): The ColorTool enables you to change the color scheme of the console. It's part of the Microsoft Terminal project.

Demo

enter image description here

Enjoy this code:

@echo off

title a game for youtube 

       explorer "https://thepythoncoding.blogspot.com/2020/11/how-to-echo-with-different-colors-in.html" 

SETLOCAL EnableDelayedExpansion

for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (

  set "DEL=%%a"

)

echo say the name of the colors, don't read

call :ColorText 0a "blue"

call :ColorText 0C "green"

call :ColorText 0b "red"

echo(

call :ColorText 19 "yellow" 

call :ColorText 2F "black"

call :ColorText 4e "white"

goto :Beginoffile

:ColorText

echo off

<nul set /p ".=%DEL%" > "%~2"

findstr /v /a:%1 /R "^$" "%~2" nul

del "%~2" > nul 2>&1

goto :eof

:Beginoffile


The Windows Console Team.





No comments:

Post a Comment

Thanks for your comments

Rank

seo