Is there a command to display colors when giving hex value in terminal?











up vote
-1
down vote

favorite












How can I display colors in terminal to handle hexadecimal color values ?
It can be useful for theming, XResources etc.
For example :



$ command '#FF0000'
// display a red square


I use urxvt, i3wm in manjaro.










share|improve this question









New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
    – Stéphane Chazelas
    2 days ago










  • I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
    – Antharia Jack
    2 days ago












  • It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
    – mosvy
    2 days ago












  • Related: unix.stackexchange.com/a/269085/117549
    – Jeff Schaller
    2 days ago















up vote
-1
down vote

favorite












How can I display colors in terminal to handle hexadecimal color values ?
It can be useful for theming, XResources etc.
For example :



$ command '#FF0000'
// display a red square


I use urxvt, i3wm in manjaro.










share|improve this question









New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
    – Stéphane Chazelas
    2 days ago










  • I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
    – Antharia Jack
    2 days ago












  • It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
    – mosvy
    2 days ago












  • Related: unix.stackexchange.com/a/269085/117549
    – Jeff Schaller
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











How can I display colors in terminal to handle hexadecimal color values ?
It can be useful for theming, XResources etc.
For example :



$ command '#FF0000'
// display a red square


I use urxvt, i3wm in manjaro.










share|improve this question









New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











How can I display colors in terminal to handle hexadecimal color values ?
It can be useful for theming, XResources etc.
For example :



$ command '#FF0000'
// display a red square


I use urxvt, i3wm in manjaro.







command-line terminal colors






share|improve this question









New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Stéphane Chazelas

294k54553894




294k54553894






New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Antharia Jack

1




1




New contributor




Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Antharia Jack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
    – Stéphane Chazelas
    2 days ago










  • I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
    – Antharia Jack
    2 days ago












  • It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
    – mosvy
    2 days ago












  • Related: unix.stackexchange.com/a/269085/117549
    – Jeff Schaller
    2 days ago


















  • Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
    – Stéphane Chazelas
    2 days ago










  • I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
    – Antharia Jack
    2 days ago












  • It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
    – mosvy
    2 days ago












  • Related: unix.stackexchange.com/a/269085/117549
    – Jeff Schaller
    2 days ago
















Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
– Stéphane Chazelas
2 days ago




Do you want to display those colours in the terminal emulator window itself? Or starting a different X application (like xlogo -bg '#ff0000') is OK?
– Stéphane Chazelas
2 days ago












I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
– Antharia Jack
2 days ago






I tried. It's ok. But if I want to display several colors, for example with a file containing color values on each line, maybe i'll prefer some color display like neofetch or pywal. Thanks.
– Antharia Jack
2 days ago














It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
– mosvy
2 days ago






It's not clear what your question is about. Please add more info to it. Are you trying to set the fg to an arbitrary color? You can do it in xterms and alike with eg. e[38;2;213;117;37m. Similar for the bg: e[48;2;37;213;117m. Or you already know that but don't know how to parse and split hex specs in the shell? Are you trying to modify the palette (what std colors 1,2,3 stand for)? etc.
– mosvy
2 days ago














Related: unix.stackexchange.com/a/269085/117549
– Jeff Schaller
2 days ago




Related: unix.stackexchange.com/a/269085/117549
– Jeff Schaller
2 days ago










2 Answers
2






active

oldest

votes

















up vote
0
down vote













You could change the background colour of the terminal with:



printf 'e]11;%sa' '#ff0000'


Which seems to work with xterm, VTE-based terminals (like gnome-terminal), konsole and rxvt at least.



You can also change other colours than the background's if you prefer. Like change the colour 1 and display a rectangle in that colour with:



printf 'e]4;1;%sae[0;41m   n   ne[m' '#ff0000'


To display more than one colour:



show_colour() {
for i do
printf 'e]4;%d;%sae[0;48;5;%dm%se[mn' "$#" "$i" "$#" "$i"
shift
done
}

show_colour black purple green '#ff0000'


That does permanently change the palette for that emulator window though. Use tput oc to restore the default colours.



Other option could be to run:



xlogo -bg '#ff0000'


Or



rxvt -bg '#ff0000'





share|improve this answer























  • Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
    – Antharia Jack
    2 days ago


















up vote
0
down vote













An alternative:



show_colour() {
perl -e 'foreach $a(@ARGV){print "e[48;2;".join(";",unpack("C*",pack("H*",$a)))."m e[49m "};print "n"' "$@"
}


Example usage:



$ show_colour "FF0088" "61E931" "1256E2"


This prints spaces with the given RGB background colours. Note that you must not use # in the RGB code. I leave stripping that if present as an exercise for the reader. ☺



This does not alter the terminal emulator's palette.



Caveat: Your terminal emulator must understand direct colour SGR control sequences. Many do, but you'll find that rxvt-unicode does not.






share|improve this answer





















  • Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
    – egmont
    2 days ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Antharia Jack is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482755%2fis-there-a-command-to-display-colors-when-giving-hex-value-in-terminal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You could change the background colour of the terminal with:



printf 'e]11;%sa' '#ff0000'


Which seems to work with xterm, VTE-based terminals (like gnome-terminal), konsole and rxvt at least.



You can also change other colours than the background's if you prefer. Like change the colour 1 and display a rectangle in that colour with:



printf 'e]4;1;%sae[0;41m   n   ne[m' '#ff0000'


To display more than one colour:



show_colour() {
for i do
printf 'e]4;%d;%sae[0;48;5;%dm%se[mn' "$#" "$i" "$#" "$i"
shift
done
}

show_colour black purple green '#ff0000'


That does permanently change the palette for that emulator window though. Use tput oc to restore the default colours.



Other option could be to run:



xlogo -bg '#ff0000'


Or



rxvt -bg '#ff0000'





share|improve this answer























  • Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
    – Antharia Jack
    2 days ago















up vote
0
down vote













You could change the background colour of the terminal with:



printf 'e]11;%sa' '#ff0000'


Which seems to work with xterm, VTE-based terminals (like gnome-terminal), konsole and rxvt at least.



You can also change other colours than the background's if you prefer. Like change the colour 1 and display a rectangle in that colour with:



printf 'e]4;1;%sae[0;41m   n   ne[m' '#ff0000'


To display more than one colour:



show_colour() {
for i do
printf 'e]4;%d;%sae[0;48;5;%dm%se[mn' "$#" "$i" "$#" "$i"
shift
done
}

show_colour black purple green '#ff0000'


That does permanently change the palette for that emulator window though. Use tput oc to restore the default colours.



Other option could be to run:



xlogo -bg '#ff0000'


Or



rxvt -bg '#ff0000'





share|improve this answer























  • Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
    – Antharia Jack
    2 days ago













up vote
0
down vote










up vote
0
down vote









You could change the background colour of the terminal with:



printf 'e]11;%sa' '#ff0000'


Which seems to work with xterm, VTE-based terminals (like gnome-terminal), konsole and rxvt at least.



You can also change other colours than the background's if you prefer. Like change the colour 1 and display a rectangle in that colour with:



printf 'e]4;1;%sae[0;41m   n   ne[m' '#ff0000'


To display more than one colour:



show_colour() {
for i do
printf 'e]4;%d;%sae[0;48;5;%dm%se[mn' "$#" "$i" "$#" "$i"
shift
done
}

show_colour black purple green '#ff0000'


That does permanently change the palette for that emulator window though. Use tput oc to restore the default colours.



Other option could be to run:



xlogo -bg '#ff0000'


Or



rxvt -bg '#ff0000'





share|improve this answer














You could change the background colour of the terminal with:



printf 'e]11;%sa' '#ff0000'


Which seems to work with xterm, VTE-based terminals (like gnome-terminal), konsole and rxvt at least.



You can also change other colours than the background's if you prefer. Like change the colour 1 and display a rectangle in that colour with:



printf 'e]4;1;%sae[0;41m   n   ne[m' '#ff0000'


To display more than one colour:



show_colour() {
for i do
printf 'e]4;%d;%sae[0;48;5;%dm%se[mn' "$#" "$i" "$#" "$i"
shift
done
}

show_colour black purple green '#ff0000'


That does permanently change the palette for that emulator window though. Use tput oc to restore the default colours.



Other option could be to run:



xlogo -bg '#ff0000'


Or



rxvt -bg '#ff0000'






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Stéphane Chazelas

294k54553894




294k54553894












  • Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
    – Antharia Jack
    2 days ago


















  • Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
    – Antharia Jack
    2 days ago
















Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
– Antharia Jack
2 days ago




Change background color of urxvt is ok. But something like neofetch colorscheme display will be great : ostechnix.com/wp-content/uploads/2016/06/neofetch.png
– Antharia Jack
2 days ago












up vote
0
down vote













An alternative:



show_colour() {
perl -e 'foreach $a(@ARGV){print "e[48;2;".join(";",unpack("C*",pack("H*",$a)))."m e[49m "};print "n"' "$@"
}


Example usage:



$ show_colour "FF0088" "61E931" "1256E2"


This prints spaces with the given RGB background colours. Note that you must not use # in the RGB code. I leave stripping that if present as an exercise for the reader. ☺



This does not alter the terminal emulator's palette.



Caveat: Your terminal emulator must understand direct colour SGR control sequences. Many do, but you'll find that rxvt-unicode does not.






share|improve this answer





















  • Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
    – egmont
    2 days ago

















up vote
0
down vote













An alternative:



show_colour() {
perl -e 'foreach $a(@ARGV){print "e[48;2;".join(";",unpack("C*",pack("H*",$a)))."m e[49m "};print "n"' "$@"
}


Example usage:



$ show_colour "FF0088" "61E931" "1256E2"


This prints spaces with the given RGB background colours. Note that you must not use # in the RGB code. I leave stripping that if present as an exercise for the reader. ☺



This does not alter the terminal emulator's palette.



Caveat: Your terminal emulator must understand direct colour SGR control sequences. Many do, but you'll find that rxvt-unicode does not.






share|improve this answer





















  • Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
    – egmont
    2 days ago















up vote
0
down vote










up vote
0
down vote









An alternative:



show_colour() {
perl -e 'foreach $a(@ARGV){print "e[48;2;".join(";",unpack("C*",pack("H*",$a)))."m e[49m "};print "n"' "$@"
}


Example usage:



$ show_colour "FF0088" "61E931" "1256E2"


This prints spaces with the given RGB background colours. Note that you must not use # in the RGB code. I leave stripping that if present as an exercise for the reader. ☺



This does not alter the terminal emulator's palette.



Caveat: Your terminal emulator must understand direct colour SGR control sequences. Many do, but you'll find that rxvt-unicode does not.






share|improve this answer












An alternative:



show_colour() {
perl -e 'foreach $a(@ARGV){print "e[48;2;".join(";",unpack("C*",pack("H*",$a)))."m e[49m "};print "n"' "$@"
}


Example usage:



$ show_colour "FF0088" "61E931" "1256E2"


This prints spaces with the given RGB background colours. Note that you must not use # in the RGB code. I leave stripping that if present as an exercise for the reader. ☺



This does not alter the terminal emulator's palette.



Caveat: Your terminal emulator must understand direct colour SGR control sequences. Many do, but you'll find that rxvt-unicode does not.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









JdeBP

31.5k466147




31.5k466147












  • Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
    – egmont
    2 days ago




















  • Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
    – egmont
    2 days ago


















Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
– egmont
2 days ago






Note that the standard parameter string for truecolor escape sequences, as per ITU-T T.416, is "48:2:color-space-id:red:green:blue". Omitting color-space-id (and shifting the remaining parameters to the left) and/or using semicolons are common misinterpretations of the standard.
– egmont
2 days ago












Antharia Jack is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Antharia Jack is a new contributor. Be nice, and check out our Code of Conduct.













Antharia Jack is a new contributor. Be nice, and check out our Code of Conduct.












Antharia Jack is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482755%2fis-there-a-command-to-display-colors-when-giving-hex-value-in-terminal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt