49 #ifndef __SCREEN_PRINT_UTILS__ 50 #define __SCREEN_PRINT_UTILS__ 66 void print_to_screen(
const std::string &file_in,
const std::string &name);
75 if (FILE*
f = popen(
"tput cols",
"r"))
80 while ((n = fread(buffer, 1,
sizeof buffer,
f)) > 0)
82 std::stringstream ss(std::string(buffer, n));
99 inline std::string
separate_line(std::string &line, std::string::size_type indent, std::string::size_type cols_pos)
101 std::string sub_line;
102 std::string::size_type end_pos = 0;
103 std::string::size_type end_pos_b = line.find_last_of(
" ", cols_pos);
104 if (end_pos_b != std::string::npos)
105 end_pos_b = line.find_last_not_of(
" ", end_pos_b);
106 std::string::size_type end_pos_a = line.find_last_of(
"!.?;:,$#", cols_pos-1);
107 std::string::size_type end_pos_ab = line.find_last_of(
"/-+=()[]{}*@&^%\\", cols_pos);
108 if (end_pos_ab == cols_pos) end_pos_ab--;
110 if (end_pos_b != std::string::npos && end_pos_b > end_pos)
114 if (end_pos_ab != std::string::npos && end_pos_ab > end_pos)
116 end_pos = end_pos_ab;
118 if (end_pos_a != std::string::npos && end_pos_a > end_pos)
122 if (end_pos == 0 || end_pos == std::string::npos)
127 sub_line = line.substr(0, end_pos);
128 line = std::string(indent,
' ') + line.substr(line.find_first_not_of(
" ", end_pos));
std::string separate_line(std::string &line, std::string::size_type indent, std::string::size_type cols_pos)
TODO: see if we can use this one:
std::string format_for_screen(const std::string &input_string)
void print_to_screen(const std::string &file_in, const std::string &name)