foreseen

A text-based gemini browser with prefetching
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

heading.cpp (1502B)


      1 #include "../include/heading.hpp"
      2 
      3 #include <cstdint>
      4 #include <stdexcept>
      5 
      6 #include "../include/shared.hpp"
      7 #include "../include/utils.hpp"
      8 
      9 Heading::Heading(std::string text) : actualText(text) {
     10     // TODO: Actually handle whitespace correctly here.
     11     if (text.substr(0, 3) == "###") {
     12         headingLevel = 3;
     13         toDraw = actualText.substr(3);
     14     }
     15 
     16     else if (text.substr(0, 2) == "##") {
     17         headingLevel = 2;
     18         toDraw = actualText.substr(2);
     19     } else if (text.substr(0, 1) == "#") {
     20         headingLevel = 1;
     21         toDraw = actualText.substr(1);
     22     }
     23 
     24     toDraw = stripLeadingWhiteSpace(toDraw);
     25 }
     26 
     27 std::string Heading::textToDraw() {
     28     switch (headingLevel) {
     29         case 3:
     30             return "### " + toDraw + "\n";
     31         case 2:
     32             return "## " + toDraw + "\n";
     33         case 1:
     34             return "# " + toDraw + "\n";
     35     }
     36     throw std::runtime_error("This is an invalid program state.");
     37 }
     38 uint8_t Heading::getColor() {
     39     switch (headingLevel) {
     40         case 3:
     41             return COLOR_H3;
     42         case 2:
     43             return COLOR_H2;
     44         case 1:
     45             return COLOR_H1;
     46     }
     47     throw std::runtime_error("This is an invalid program state.");
     48 }
     49 LineType Heading::type() {
     50     switch (headingLevel) {
     51         case 3:
     52             return H3;
     53         case 2:
     54             return H2;
     55         case 1:
     56             return H1;
     57     }
     58     throw std::runtime_error("This is an invalid program state.");
     59 }
     60 bool Heading::isBold() { return true; }