{"id":2581,"date":"2025-07-17T18:14:13","date_gmt":"2025-07-17T17:14:13","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2581"},"modified":"2025-07-17T18:40:05","modified_gmt":"2025-07-17T17:40:05","slug":"utiliser-les-textes-en-couleurs","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/","title":{"rendered":"Utiliser les textes en couleurs"},"content":{"rendered":"\n<nav aria-label=\"Table des mati\u00e8res\" class=\"wp-block-table-of-contents\"><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#principe-les-codes-ansi\">Principe : les codes ANSI<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#exemple-de-code-couleur\">Exemple de code couleur :<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#couleurs-de-base-texte\">Couleurs de base (texte)<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#exemple-simple-avec-couleur\">Exemple simple avec couleur :<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#astuce-bonus-raccourcis-avec-define\">\ud83d\udca1 Astuce bonus : raccourcis avec #define<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#creer-un-fichier-header-couleurs-h\">Cr\u00e9er un fichier header couleurs.h<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#exemple-d-utilisation-dans-un-fichier-c\">Exemple d\u2019utilisation dans un fichier .c<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/utiliser-les-textes-en-couleurs\/#compatibilite\">\u26a0\ufe0f Compatibilit\u00e9<\/a><\/li><\/ol><\/nav>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"principe-les-codes-ansi\">Principe : les codes ANSI<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Les <strong>codes ANSI<\/strong> sont des s\u00e9quences sp\u00e9ciales envoy\u00e9es au terminal pour changer la <strong>couleur du texte<\/strong>, du <strong>fond<\/strong>, ou pour <strong>ajouter des effets<\/strong> (gras, clignotant, etc.).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exemple-de-code-couleur\">Exemple de code couleur :<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>printf(\"\\033&#91;31mTexte rouge\\033&#91;0m\\n\");<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\\033[<\/code> \u2192 d\u00e9but de la s\u00e9quence (\u00e9quivaut \u00e0 ESC)<\/li>\n\n\n\n<li><code>31m<\/code> \u2192 rouge<\/li>\n\n\n\n<li><code>0m<\/code> \u2192 r\u00e9initialise les couleurs<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"couleurs-de-base-texte\">Couleurs de base (texte)<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Code<\/th><th>Couleur<\/th><th>Exemple<\/th><\/tr><\/thead><tbody><tr><td>30<\/td><td>Noir<\/td><td><code>\\033[30m<\/code><\/td><\/tr><tr><td>31<\/td><td>Rouge<\/td><td><code>\\033[31m<\/code><\/td><\/tr><tr><td>32<\/td><td>Vert<\/td><td><code>\\033[32m<\/code><\/td><\/tr><tr><td>33<\/td><td>Jaune<\/td><td><code>\\033[33m<\/code><\/td><\/tr><tr><td>34<\/td><td>Bleu<\/td><td><code>\\033[34m<\/code><\/td><\/tr><tr><td>35<\/td><td>Magenta<\/td><td><code>\\033[35m<\/code><\/td><\/tr><tr><td>36<\/td><td>Cyan<\/td><td><code>\\033[36m<\/code><\/td><\/tr><tr><td>37<\/td><td>Blanc\/gris<\/td><td><code>\\033[37m<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exemple-simple-avec-couleur\">Exemple simple avec couleur :<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nint main() \n{\n    printf(\"\\033&#91;32m Succ\u00e8s !\\033&#91;0m\\n\");    \/* Vert *\/\n    printf(\"\\033&#91;31m Erreur !\\033&#91;0m\\n\");     \/* Rouge *\/\n    printf(\"\\033&#91;33m Attention !\\033&#91;0m\\n\");  \/* Jaune *\/\n    return EXIT_SUCCESS;\n}<\/code><\/pre>\n\n\n\n<pre>etudiant@ordi:~\/Works\/TP3_C\/color$ .\/colors\n<span style=\"color:#26A269\"> Succ\u00e8s !<\/span>\n<span style=\"color:#C01C28\"> Erreur !<\/span>\n<span style=\"color:#A2734C\"> Attention !<\/span>\n<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"astuce-bonus-raccourcis-avec-define\">\ud83d\udca1 Astuce bonus : raccourcis avec <code>#define<\/code><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#define RED     \"\\033&#91;31m\"\n#define GREEN   \"\\033&#91;32m\"\n#define YELLOW  \"\\033&#91;33m\"\n#define BLUE    \"\\033&#91;34m\"\n#define RESET   \"\\033&#91;0m\"\n\nprintf(GREEN \"Bravo !\" RESET \"\\n\");<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"creer-un-fichier-header-couleurs-h\">Cr\u00e9er un fichier header <code>couleurs.h<\/code><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">fichier couleurs.h , placer le dans le r\u00e9pertoire de votre code .<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\n\u251c\u2500\u2500 couleurs.h\n\u251c\u2500\u2500 test\n\u2514\u2500\u2500 test.c<\/code><\/pre>\n\n\n\n<pre><span style=\"color:#12488B\"><b>\/* couleurs.h *\/<\/b><\/span>\n\n<span style=\"color:#2AA1B3\"><b>#ifndef COULEURS_H<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>COULEURS_H<\/b><\/span>\n\n<span style=\"color:#12488B\"><b>\/* Texte en couleur *\/<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>RESET<\/b><\/span>     <span style=\"color:#A2734C\"><b>&quot;\\033[0m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>NOIR<\/b><\/span>      <span style=\"color:#A2734C\"><b>&quot;\\033[30m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>ROUGE<\/b><\/span>     <span style=\"color:#A2734C\"><b>&quot;\\033[31m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>VERT<\/b><\/span>      <span style=\"color:#A2734C\"><b>&quot;\\033[32m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>JAUNE<\/b><\/span>     <span style=\"color:#A2734C\"><b>&quot;\\033[33m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BLEU<\/b><\/span>      <span style=\"color:#A2734C\"><b>&quot;\\033[34m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>MAGENTA<\/b><\/span>   <span style=\"color:#A2734C\"><b>&quot;\\033[35m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>CYAN<\/b><\/span>      <span style=\"color:#A2734C\"><b>&quot;\\033[36m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BLANC<\/b><\/span>     <span style=\"color:#A2734C\"><b>&quot;\\033[37m&quot;<\/b><\/span>\n\n<span style=\"color:#12488B\"><b>\/* Texte gras *\/<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>GRAS<\/b><\/span>      <span style=\"color:#A2734C\"><b>&quot;\\033[1m&quot;<\/b><\/span>\n\n<span style=\"color:#12488B\"><b>\/* Fond color\u00e9 *\/<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BG_ROUGE<\/b><\/span>   <span style=\"color:#A2734C\"><b>&quot;\\033[41m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BG_VERT<\/b><\/span>    <span style=\"color:#A2734C\"><b>&quot;\\033[42m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BG_JAUNE<\/b><\/span>   <span style=\"color:#A2734C\"><b>&quot;\\033[43m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BG_BLEU<\/b><\/span>    <span style=\"color:#A2734C\"><b>&quot;\\033[44m&quot;<\/b><\/span>\n<span style=\"color:#2AA1B3\"><b>#define<\/b><\/span> <span style=\"color:#C01C28\"><b>BG_CYAN<\/b><\/span>    <span style=\"color:#A2734C\"><b>&quot;\\033[46m&quot;<\/b><\/span>\n\n<span style=\"color:#2AA1B3\"><b>#endif<\/b><\/span><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exemple-d-utilisation-dans-un-fichier-c\">Exemple d\u2019utilisation dans un fichier .c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include \"couleurs.h\"\n\nint main() \n{\n    printf(VERT \"Succ\u00e8s !\" RESET \"\\n\");\n    printf(ROUGE \"Erreur !\" RESET \"\\n\");\n    printf(BLEU GRAS \"Texte en bleu et en gras\" RESET \"\\n\");\n    return EXIT_SUCCESS;\n}<\/code><\/pre>\n\n\n\n<pre>etudiant@ordi:~\/Works\/TP3_C\/color$ .\/test \n<span style=\"color:#26A269\">Succ\u00e8s !<\/span>\n<span style=\"color:#C01C28\">Erreur !<\/span>\n<span style=\"color:#12488B\"><b>Texte en bleu et en gras<\/b><\/span>\netudiant@ordi:~\/Works\/TP3_C\/color$ \n<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"compatibilite\">\u26a0\ufe0f Compatibilit\u00e9<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2705 Fonctionne dans : Linux, macOS, Windows Terminal, Git Bash, VS Code, etc.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Principe : les codes ANSI Les codes ANSI sont des s\u00e9quences sp\u00e9ciales envoy\u00e9es au terminal pour changer la couleur du texte, du fond, ou pour ajouter des effets (gras, clignotant, etc.). Exemple de code couleur : Couleurs de base (texte) Code Couleur Exemple 30 Noir \\033[30m 31 Rouge \\033[31m 32 Vert \\033[32m 33 Jaune \\033[33m [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-2581","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Principe : les codes ANSI Les codes ANSI sont des s\u00e9quences sp\u00e9ciales envoy\u00e9es au terminal pour changer la couleur du texte, du fond, ou pour ajouter des effets (gras, clignotant, etc.). Exemple de code couleur : Couleurs de base (texte) Code Couleur Exemple 30 Noir \\033[30m 31 Rouge \\033[31m 32 Vert \\033[32m 33 Jaune \\033[33m\u2026","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=2581"}],"version-history":[{"count":8,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2581\/revisions"}],"predecessor-version":[{"id":2595,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2581\/revisions\/2595"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}