|
@@ -0,0 +1,73 @@
|
|
|
|
|
+#include <ncurses.h>
|
|
|
|
|
+#include <cstring>
|
|
|
|
|
+#include <csignal>
|
|
|
|
|
+#include <cstdlib>
|
|
|
|
|
+
|
|
|
|
|
+#include <string>
|
|
|
|
|
+#include <iostream>
|
|
|
|
|
+#include <format>
|
|
|
|
|
+
|
|
|
|
|
+using namespace std;
|
|
|
|
|
+
|
|
|
|
|
+#define INPUT_HEIGHT 3
|
|
|
|
|
+#define MAX_INPUT 256
|
|
|
|
|
+
|
|
|
|
|
+void quit() {
|
|
|
|
|
+ endwin();
|
|
|
|
|
+ std::exit(0);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int main() {
|
|
|
|
|
+ WINDOW *chat_win, *input_win;
|
|
|
|
|
+ int rows, cols;
|
|
|
|
|
+ string input;
|
|
|
|
|
+
|
|
|
|
|
+ initscr();
|
|
|
|
|
+ cbreak();
|
|
|
|
|
+ keypad(stdscr, TRUE);
|
|
|
|
|
+ curs_set(1);
|
|
|
|
|
+
|
|
|
|
|
+ getmaxyx(stdscr, rows, cols);
|
|
|
|
|
+
|
|
|
|
|
+ chat_win = newwin(rows - INPUT_HEIGHT, cols, 0, 0);
|
|
|
|
|
+ input_win = newwin(INPUT_HEIGHT, cols, rows - INPUT_HEIGHT, 0);
|
|
|
|
|
+
|
|
|
|
|
+ scrollok(chat_win, TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ box(input_win, 0, 0);
|
|
|
|
|
+ mvwprintw(input_win, 1, 1, "> ");
|
|
|
|
|
+ wrefresh(chat_win);
|
|
|
|
|
+ wrefresh(input_win);
|
|
|
|
|
+
|
|
|
|
|
+ string channel = "default";
|
|
|
|
|
+ string username = "";
|
|
|
|
|
+
|
|
|
|
|
+ cin >>
|
|
|
|
|
+
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ input.clear();
|
|
|
|
|
+
|
|
|
|
|
+ echo();
|
|
|
|
|
+ wmove(input_win, 1, 3);
|
|
|
|
|
+ wrefresh(input_win);
|
|
|
|
|
+ wgetnstr(input_win, input.data(), MAX_INPUT - 1);
|
|
|
|
|
+ noecho();
|
|
|
|
|
+
|
|
|
|
|
+ werase(input_win);
|
|
|
|
|
+ box(input_win, 0, 0);
|
|
|
|
|
+ mvwprintw(input_win, 1, 1, "> ");
|
|
|
|
|
+ wrefresh(input_win);
|
|
|
|
|
+
|
|
|
|
|
+ if (input[0] == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (strcmp(input.c_str(), "/quit") == 0) {
|
|
|
|
|
+ std::cerr << input << std::endl;
|
|
|
|
|
+ quit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wprintw(chat_win, "You: %s\n", input.c_str());
|
|
|
|
|
+ wrefresh(chat_win);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|