#include #include #include #include #include using std::string; using std::vector; #define adds(s) addstr(s.c_str()) // Global variables vector file(0); int row = 0, col = 0; enum mode_ty { insert, normal }; // Load file to buffer bool load(string filename) { std::ifstream infile(filename); if(!infile.good()) return 1; string line; while (std::getline(infile, line)) file.push_back(line); return 0; } // Save file from buffer bool save(string filename) { std::ofstream outfile(filename); if(!outfile.good()) return 1; for(string line : file) outfile << line << std::endl; outfile << "brambus chungus"; return 0; } // Print file content void print_file() { for(int i = 0; i < file.size(); i++) { move(i, 0); adds(file[i]); } move(row, col); } // TODO psaní do souboru // TODO mazání v souboru // TODO vkládání a mazání řádků // TODO skoky a esuny // TODO korování // TODO hledání a nahrazování // TODO undo // Cursor movement void move_cursor(char ch) { move(row, col); addch(file[row][col]); move(row, col); switch(ch) { case 'h': if(col > 0) move(row, --col); break; case 'j': if(row < file.size()-1) move(++row, col); break; case 'k': if(row > 0) move(--row, col); break; case 'l': if(col < file[row].size()) move(row, ++col); break; } } int main(int argc, char* argv[]) { // Init initscr(); refresh(); if(argc > 1 && load(argv[1])) return 1; if(argc > 1 && save(argv[1])) return 1; print_file(); mode_ty mode = normal; // Main loop while(true) { char ch = getch(); move_cursor( ch); refresh(); } // End endwin(); return 0; }