diff --git a/console b/console index e6089cc..68ae03d 100755 Binary files a/console and b/console differ diff --git a/main.c b/main.c index a18771a..5662f6d 100644 --- a/main.c +++ b/main.c @@ -6,20 +6,32 @@ int rows, cols; void clearInput() { - for (int i = 0; i < cols; i ++) { + for (int i = 0; i < cols; i ++) mvprintw(rows - 1, i, " "); - } + attron(A_BLINK); + mvprintw(rows - 1, 0, " "); + attroff(A_BLINK); } -void printContentIntoAFile(char (*content)[cols+1]) { - FILE* f = fopen("content.txt", "w"); - for (int i = 0; i < rows - 2; i ++) - fprintf(f, "%s\n", content[i]); - fclose(f); +//void printContentIntoAFile(char (*content)[cols+1]) { +// FILE* f = fopen("content.txt", "w"); +// for (int i = 0; i < rows - 2; i ++) +// fprintf(f, "%s\n", content[i]); +// fclose(f); +//} + +void printPrompt(char* prompt) { + mvprintw(rows - 1, 0, "%s", prompt); } -void printContent(char (*content)[cols+1]) { - for (int i = rows - 2; i > 1; i --) +void clearScreen() { + for (int i = 0; i < rows; i ++) + for (int j = 0; j < cols; j ++) + mvprintw(i, j, " "); +} + +void printContent(char (*content)[cols+1]) { + for (int i = rows - 2; i > 0; i --) mvprintw(i, 0, "%s", content[rows - 2 - i]); } @@ -29,44 +41,46 @@ void insertInStartContent(char (*content)[cols+1], char* toInsert) { strcpy(content[0], toInsert); } +//void printStringIntoAFile(char* string) { +// FILE* f = fopen("string.txt", "w"); +// fprintf(f, "%s\n", string); +// fclose(f); +//} + int main (int argc, char* argv[]) { initscr(); cbreak(); keypad(stdscr, TRUE); noecho(); - - char ch = ' '; - int len = 0; - char* cmd_string = malloc(cols); - char (*content)[cols] = malloc(sizeof(char[rows][cols+1])); - - for (int i = 0; i < rows; i ++) - memset(content[i],0,sizeof(content[i])); + start_color(); getmaxyx(stdscr, rows, cols); + char ch = ' '; + int len = 0; + char cmd_string[cols]; + + memset(cmd_string, '\0', cols); + char content[rows][cols]; + for (int i = 0; i < rows; i ++) + memset(&(content[i]),'\0', cols); + while (ch = getch()){ switch (ch) { case 10: { - FILE* f = fopen("test.txt","w"); - fprintf(f, "test: %s", cmd_string); - fclose(f); insertInStartContent(content, cmd_string); len = 0; - clearInput(rows, cols); - memset(cmd_string,0,cols * sizeof(char)); - refresh(); - printContentIntoAFile(content); + memset(cmd_string, '\0', cols); break; } default: - mvprintw(rows - 1 , len, "%c", ch); cmd_string[len] = ch; len ++; break; } + clearScreen(); printContent(content); - mvprintw(rows - 1, len, ""); + printPrompt(cmd_string); refresh(); } diff --git a/test.c b/test.c deleted file mode 100644 index 09c335e..0000000 --- a/test.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include - -int cols, rows; - -void insert (char (*content)[cols], char* toInsert) { - int i = rows; - for (i; i > 0; i --) { - strcpy(content[i], content[i - 1]); - } - strcpy(content[i], toInsert); -} - -int main () { - cols = 50; - rows = 3; - - char (*content)[cols] = malloc(sizeof(char[rows][cols+1])); - - strcpy(content[0], "Test string 1"); - strcpy(content[1], "Test string 2"); - - printf("Array before insert: \n"); - - for (int i = 0; i < 3; i ++) { - printf("%s\n", content[i]); - } - - insert(content, "test string 0"); - - printf("Array after insert: \n"); - - for (int i = 0; i < 3; i ++) { - printf("%s\n", content[i]); - } -}