Rain před 1 týdnem
revize
cae79bb885
4 změnil soubory, kde provedl 83 přidání a 0 odebrání
  1. 1 0
      .gitignore
  2. 8 0
      Makefile
  3. 1 0
      README.md
  4. 73 0
      src/main.cpp

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+target/

+ 8 - 0
Makefile

@@ -0,0 +1,8 @@
+APPNAME=minichannel
+
+build:
+	mkdir -p ./target/
+	g++ ./src/*.cpp -o ./target/$(APPNAME) -Wall -lncurses -lpanel -lmenu
+
+run: build
+	./target/$(APPNAME) 2> ./target/stdout

+ 1 - 0
README.md

@@ -0,0 +1 @@
+# minichannel

+ 73 - 0
src/main.cpp

@@ -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);
+    }
+}