From: MichaƂ Bartoszkiewicz <mbartoszkiewicz@gmail.com>
Date: Sat, 21 Dec 2013 10:44:49 +0000 (+0100)
Subject: Nie kolorujemy spacji
X-Git-Url: https://git.bzium.org/embe/choinka.git/commitdiff_plain/ce2e37059c21803606557e44fe872174fed3772c?ds=sidebyside

Nie kolorujemy spacji
---

diff --git a/choinka.c b/choinka.c
index c02dc72..b117972 100644
--- a/choinka.c
+++ b/choinka.c
@@ -5,6 +5,7 @@
 
 #define A_POGRUBIONY (1 << 0)
 
+#define KOLOR_BRAK -1
 #define KOLOR_CZARNY 0
 #define KOLOR_CZERWONY 1
 #define KOLOR_ZIELONY 2
@@ -29,6 +30,7 @@ static atrybut const bombki[] = {
 };
 static int const ile_b = sizeof bombki / sizeof *bombki;
 
+static atrybut const spacja = {0, KOLOR_BRAK};
 static atrybut const choinka = {0, KOLOR_ZIELONY};
 static atrybut const podstawa = {0, KOLOR_BRAZOWY};
 static atrybut const podpis = {A_POGRUBIONY, KOLOR_CZERWONY};
@@ -71,7 +73,9 @@ static void ustaw(atrybut const* attr)
   if ((attr->attr & A_POGRUBIONY) != 0) {
     putp(enter_bold_mode);
   }
-  putp(tparm(set_a_foreground, attr->kolor));
+  if (attr->kolor != KOLOR_BRAK) {
+    putp(tparm(set_a_foreground, attr->kolor));
+  }
 }
 
 int main()
@@ -86,6 +90,7 @@ int main()
     if (c >= 'a' && c <= 'z') akt = &podpis;
     if (c == '.') akt = &bombki[rand() % ile_b];
     if (c == '*') akt = &gwiazdka;
+    if (c == ' ' || c == '\n') akt = &spacja;
     if (c == ']') kolor = &choinka;
     ustaw(akt);
     putchar(c);