32 const std::string m_ip_addr;
33 const std::string m_port;
34 const std::string m_connect_type;
35 std::string m_upper_screen;
36 std::string m_scroll_text;
37 const int m_num_scroll_lines;
40 simple_chat_screen(
const std::string& ip,
const std::string& port,
const std::string& type,
41 bool print_errors,
int num_lines = NUN_SCROLL_LINES) :
42 m_ip_addr(ip), m_port(port), m_connect_type(type), m_num_scroll_lines(num_lines) {
43 create_upper_screen(print_errors);
51 std::cout << (m_upper_screen + m_scroll_text + BOTTOM + PROMPT);
57 void insert_scroll_line(
const std::string& text,
const std::string& prefix) {
61 std::string new_scroll_line =
"| " + prefix +
62 text.substr(0, text.size() - 1);
64 BLANK_LINE.substr(new_scroll_line.length(), std::string::npos);
68 m_scroll_text.substr(m_scroll_text.find_first_of(
"\n") + 1, std::string::npos) +
73 using S =
const std::string;
76 "\n_____________________________________________________________________________\n";
80 "|___________________________________________________________________________|\n";
82 "| chops-net-ip chat network demo |\n";
88 "| connection type: ";
94 "| errors printed to console: ON |\n";
96 "| errors printed to console: OFF |\n";
98 "| Enter text to send at prompt. Enter 'quit' to exit. |\n";
102 "|---------------------------------------------------------------------------|\n";
108 void create_upper_screen(
bool print_err) {
109 std::string hdr_info = HDR_IP + (m_ip_addr ==
"" ?
"\"\"" : m_ip_addr) + HDR_PORT +
111 hdr_info += BLANK_LINE.substr(hdr_info.size(), std::string::npos);
113 TOP + BLANK_LINE + HDR_1 + DIVIDOR + BLANK_LINE + hdr_info + HDR_TYPE +
114 (m_connect_type == PARAM_ACCEPT ? ACCEPT_T : CONNECT_T) +
115 (print_err ? ERR_LOG_ON : ERR_LOG_OFF) +
116 DIVIDOR + BLANK_LINE + HDR_INSTR + DIVIDOR;
120 void create_scroll_text() {
121 int count = m_num_scroll_lines;
122 while (count-- > 0) {
123 m_scroll_text += BLANK_LINE;
130 void clear_screen() {