2023-02-13 10:35:41 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ncurses.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int rows, cols;
|
|
|
|
|
|
|
|
void clearInput() {
|
|
|
|
for (int i = 0; i < cols; i ++) {
|
|
|
|
mvprintw(rows - 1, i, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void printContent(char (*content)[cols+1]) {
|
|
|
|
|
|
|
|
for (int i = rows - 2; i > 1; i --) {
|
2023-02-13 11:08:57 +03:00
|
|
|
mvprintw(i, 0, "%s", content[rows - 2 - i]);
|
2023-02-13 10:35:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void insertInStartContent(char (*content)[cols+1], char* toInsert) {
|
|
|
|
for (int i = rows; i > 0; i --) {
|
|
|
|
strcpy(content[i], content[i - 1]);
|
|
|
|
}
|
2023-02-13 11:08:57 +03:00
|
|
|
strcpy(content[rows], toInsert);
|
2023-02-13 10:35:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char* argv[]) {
|
|
|
|
initscr();
|
2023-02-13 11:08:57 +03:00
|
|
|
cbreak();
|
2023-02-13 10:35:41 +03:00
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
|
|
|
|
noecho();
|
|
|
|
char ch = ' ';
|
|
|
|
int len = 0;
|
2023-02-13 11:08:57 +03:00
|
|
|
char* cmd_string = malloc(cols);
|
|
|
|
char (*content)[cols] = malloc(sizeof(char[rows][cols+1]));
|
2023-02-13 10:35:41 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < rows; i ++) {
|
|
|
|
strcpy(content[i], " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
getmaxyx(stdscr, rows, cols);
|
|
|
|
|
|
|
|
while (ch = getch()){
|
|
|
|
switch (ch) {
|
2023-02-13 11:08:57 +03:00
|
|
|
case 10: {
|
|
|
|
// char* toInsert = malloc(cols+1);
|
|
|
|
FILE* f = fopen("test.txt","w");
|
|
|
|
fprintf(f, "test: %s", cmd_string);
|
|
|
|
fclose(f);
|
|
|
|
insertInStartContent(content, cmd_string);
|
2023-02-13 10:35:41 +03:00
|
|
|
len = 0;
|
|
|
|
clearInput(rows, cols);
|
2023-02-13 11:08:57 +03:00
|
|
|
cmd_string = "";
|
2023-02-13 10:35:41 +03:00
|
|
|
refresh();
|
|
|
|
break;
|
2023-02-13 11:08:57 +03:00
|
|
|
}
|
2023-02-13 10:35:41 +03:00
|
|
|
default:
|
|
|
|
mvprintw(rows - 1 , len, "%c", ch);
|
2023-02-13 11:08:57 +03:00
|
|
|
cmd_string[len] = ch;
|
2023-02-13 10:35:41 +03:00
|
|
|
len ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printContent(content);
|
|
|
|
mvprintw(rows - 1, len, "");
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
endwin();
|
|
|
|
return 0;
|
|
|
|
}
|