<commit_before>#ifndef SEARCH_TERMINAL_H
#define SEARCH_TERMINAL_H

#include "filefinder.h"

class terminal{
 public:
  terminal(){
    // save and copy terminal settings
    tcgetattr( STDIN_FILENO, &oldt);
    newt = oldt;

    // set new terminal settings
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr( STDIN_FILENO, TCSANOW, &newt);

    //
    for(int i=0; i < options.number_of_result_lines; ++i){
      fprintf(stderr,"\n");
    }
    cursor_up(options.number_of_result_lines);
    save_cursor_pos();
    restore_cursor_pos();
  }

  ~terminal(){
    // restore terminal settings
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
  }

  void save_cursor_pos() const{
    fprintf(stderr,"\033[s");
  }

  void restore_cursor_pos() const{
    fprintf(stderr,"\033[u");
  }

  void erase_line() const{
    fprintf(stderr,"\033[K");
  }

  void cursor_left(int n = 1) const{
    fprintf(stderr,"\033[%dD",n);
  }

  void cursor_right(int n = 1) const{
    fprintf(stderr,"\033[%dC",n);
  }

  void cursor_up(int n = 1) const{
    fprintf(stderr,"\033[%dA",n);
  }

  void cursor_down(int n = 1) const{
    fprintf(stderr,"\033[%dB",n);
  }

  void print_search_line(std::string str, int pos) const{
    restore_cursor_pos();
    erase_line();
    fprintf(stderr,">%s", str.c_str());
    restore_cursor_pos();
    cursor_right(1+pos);
  }

  void print_result(const terminal& term,const std::vector<node>& result, std::size_t selected){
    term.restore_cursor_pos();
    for(int i=0; i < options.number_of_result_lines; ++i){
      fprintf(stderr,"\n");
      term.erase_line();
    }
    term.restore_cursor_pos();

    for(std::size_t i=1; i <= result.size(); ++i){
      fprintf(stderr,"\n");
      if(i-1==selected) fprintf(stderr,"\033[7m");
      fprintf(stderr,"%lu: %s%s",i,result[i-1].location.c_str(), result[i-1].filename.c_str());
      if(i-1==selected) fprintf(stderr,"\033[0m");
    }<commit_msg>cast std_t to unsigned long in printf.<commit_after>#ifndef SEARCH_TERMINAL_H
#define SEARCH_TERMINAL_H

#include "filefinder.h"

class terminal{
 public:
  terminal(){
    // save and copy terminal settings
    tcgetattr( STDIN_FILENO, &oldt);
    newt = oldt;

    // set new terminal settings
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr( STDIN_FILENO, TCSANOW, &newt);

    //
    for(int i=0; i < options.number_of_result_lines; ++i){
      fprintf(stderr,"\n");
    }
    cursor_up(options.number_of_result_lines);
    save_cursor_pos();
    restore_cursor_pos();
  }

  ~terminal(){
    // restore terminal settings
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
  }

  void save_cursor_pos() const{
    fprintf(stderr,"\033[s");
  }

  void restore_cursor_pos() const{
    fprintf(stderr,"\033[u");
  }

  void erase_line() const{
    fprintf(stderr,"\033[K");
  }

  void cursor_left(int n = 1) const{
    fprintf(stderr,"\033[%dD",n);
  }

  void cursor_right(int n = 1) const{
    fprintf(stderr,"\033[%dC",n);
  }

  void cursor_up(int n = 1) const{
    fprintf(stderr,"\033[%dA",n);
  }

  void cursor_down(int n = 1) const{
    fprintf(stderr,"\033[%dB",n);
  }

  void print_search_line(std::string str, int pos) const{
    restore_cursor_pos();
    erase_line();
    fprintf(stderr,">%s", str.c_str());
    restore_cursor_pos();
    cursor_right(1+pos);
  }

  void print_result(const terminal& term,const std::vector<node>& result, std::size_t selected){
    term.restore_cursor_pos();
    for(int i=0; i < options.number_of_result_lines; ++i){
      fprintf(stderr,"\n");
      term.erase_line();
    }
    term.restore_cursor_pos();

    for(std::size_t i=1; i <= result.size(); ++i){
      fprintf(stderr,"\n");
      if(i-1==selected) fprintf(stderr,"\033[7m");
      fprintf(stderr,"%lu: %s%s",(unsigned long)i,result[i-1].location.c_str(), result[i-1].filename.c_str());
      if(i-1==selected) fprintf(stderr,"\033[0m");
    }
{'fraction_non_alphanumeric': 0.1712293388429752, 'fraction_numerical': 0.021177685950413222, 'mean_word_length': 3.583431952662722, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1156702', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1473, 'n_words': 259}