gigaTerminal text editor | 
          
| git clone git://git.dimitrijedobrota.com/giga.git | 
| Log | Files | Refs | README | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | 
| commit | 259cdcf5504a5ce31ba2bc7fe44da5c5054a9f29 | 
| parent | aeb168838fddf35f0dcb33b5a7cf89951e13471f | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Fri, 28 Feb 2025 19:43:28 +0100 | 
Scroll up and down
| M | .clang-tidy | | | ++ | 
| M | CMakeLists.txt | | | + - | 
| M | source/main.cpp | | | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ----- | 
3 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/ .clang-tidy b/ .clang-tidy
          @@ -6,7 +6,9 @@ 
          Checks: "*,\
        
        
            -google-readability-todo,\
            -altera-*,\
            -boost-*,\
            -bugprone-easily-swappable-parameters,\
            -cppcoreguidelines-avoid-magic-numbers,\
            -cppcoreguidelines-avoid-do-while,\
            -abseil-string-find-str-contains,\
            -fuchsia-*,\
            fuchsia-multiple-inheritance,\
        
        diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              giga
              VERSION 0.1.1
              VERSION 0.1.2
              DESCRIPTION "Terminal text editor"
              HOMEPAGE_URL "https://git.dimitrijedobrota.com/giga.git"
              LANGUAGES CXX
        
        diff --git a/ source/main.cpp b/ source/main.cpp
          @@ -50,24 +50,75 @@ 
          public:
        
        
            {
              line_reset();
              for (auto line = display::hgt_t(0); line < hgt(); line++) {
                if (line.value() >= m_file.size()) {
              const auto linenum_width = get_linenum_width();
              for (auto i = display::hgt_t(0); i < hgt(); i++) {
                const auto line = i.value() + m_line_start;
                if (line >= m_file.size()) {
                  break;
                }
                line_left(m_file[line.value()]);
                line_left(get_linenum(line, linenum_width) + " " + m_file[line]);
              }
              Window::render();
              Window::render_border();
            }
            void input(display::event& evnt) override
            {
              using display::event;
              if (evnt.type() != event::Type::KEY) {
                return;
              }
              if (evnt.key() == 'j') {
                if (m_line_start + hgt().value() <= m_file.size()) {
                  m_line_start++;
                }
                evnt.type() = event::Type::NONE;
                render();
                return;
              }
              if (evnt.key() == 'k') {
                if (m_line_start > 0) {
                  m_line_start--;
                }
                evnt.type() = event::Type::NONE;
                render();
                return;
              }
            }
          private:
            static std::string get_linenum(std::size_t line, std::uint8_t width)
            {
              const auto line_str = std::to_string(line);
              return std::string(width - line_str.size(), ' ') + line_str;
            }
            std::uint8_t get_linenum_width() const
            {
              auto number = m_file.size();
              std::uint8_t digits = 0;
              do {
                digits++;
              } while ((number /= 10) > 0);
              return digits;
            }
            File m_file;
            std::size_t m_line_start = 0;
          };
          int main(const int argc, const char* argv[])
          {
            std::span args(argv, argv + argc);
            const std::span args(argv, argv + argc);
            if (args.size() < 2) {
              std::cout << "Usage: " << args[0] << " filename\n";
        
        
          @@ -81,7 +132,8 @@ 
          int main(const int argc, const char* argv[])
        
        
            while (true) {
              using display::event;
              const auto evnt = inst.get_event();
              auto evnt = inst.get_event();
              if (evnt.type() == event::Type::RESIZE) {
                std::cout << alec::erase_display_v<alec::Motion::WHOLE>;
                inst.render();
        
        
          @@ -91,6 +143,8 @@ 
          int main(const int argc, const char* argv[])
        
        
              if (evnt.type() == event::Type::KEY && evnt.key() == 'q') {
                break;
              }
              inst.input(evnt);
            }
            return 0;