Loading slc/trunk/src/history.cc +0 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,6 @@ void History::save(const string &filename) const { } fs.close(); } /*! Loading slc/trunk/src/screen.cc +37 −2 Original line number Diff line number Diff line #include <ctype.h> #include <signal.h> #include <math.h> #include "slc.hh" #include "screen.hh" Loading @@ -18,6 +19,7 @@ */ Screen::Screen() { // msg init msg_buffer_ = 0; // cmd init *cmd_buffer_ = 0; Loading Loading @@ -66,6 +68,7 @@ void Screen::create_windows() { if (msg_) delwin(msg_); msg_ = newwin(LINES - 3, COLS, 0, 0); msg_buffer_ = (char *) realloc(msg_buffer_, COLS -2 + 1); msg_draw(); // cmd window Loading Loading @@ -245,7 +248,7 @@ void Screen::msg_print(const string &s) { ** Draw the content of the cmd window */ void Screen::cmd_draw() { char print_buf[MAX_LINE_SIZE]; char print_buf[MAX_LINE_SIZE + 1]; // clean and redraw the cmd box werase(cmd_); Loading @@ -261,7 +264,7 @@ void Screen::cmd_draw() { // copy part of buffer in print buffer size_t minsize = (MAX_LINE_SIZE < COLS - 2) ? MAX_LINE_SIZE : COLS - 2; strncpy(print_buf, cmd_buffer_ + cmd_win_off_, minsize); print_buf[minsize - 1] = 0; print_buf[minsize] = 0; // print print buffer wattron(cmd_, A_BOLD); Loading @@ -270,6 +273,8 @@ void Screen::cmd_draw() { // move cursor to right pos wmove(cmd_, 1, 1 + cmd_buf_off_ - cmd_win_off_); // refresh screen wrefresh(cmd_); } Loading @@ -279,6 +284,36 @@ void Screen::cmd_draw() { void Screen::msg_draw() { werase(msg_); box(msg_, 0, 0); t_lines::const_iterator line; size_t free_lines = LINES - 5; for (line = msg_table_.begin(); line != msg_table_.end() && free_lines > 0; ++line) { size_t len = strlen((*line).c_str()); // print one line if (len <= (size_t) COLS - 2) mvwprintw(msg_, free_lines--, 1, "%s", (*line).c_str()); // print multi line else { // compute line count const size_t nline = 1 + (size_t) ceil(((double) ( len - (COLS - 2)) / (double) (COLS - 4))); // iterate for each line starting with the last for (size_t i = nline; i > 0 && free_lines > 0; --i) { // compute string offset for this line const size_t print_offset = (i == 1) ? 0 : COLS - 2 + ((i - 2) * (COLS - 4)); // copy line into a buffer strncpy(msg_buffer_, (*line).c_str() + print_offset, COLS - ((i == 1) ? 2 : 4)); msg_buffer_[COLS - ((i == 1) ? 2 : 4)] = 0; // print line into screen mvwprintw(msg_, free_lines--, 1, (i == 1) ? "%s" : "> %s", msg_buffer_); } } } // refresh screen wrefresh(msg_); } Loading slc/trunk/src/screen.hh +3 −2 Original line number Diff line number Diff line Loading @@ -2,14 +2,14 @@ # define SCREEN_HH_ # include <ncurses.h> # include <list> # include <deque> #define KEY_RETURN 10 #define KEY_EOF 4 class Screen { public: typedef std::list<string> t_lines; typedef std::deque<string> t_lines; public: Screen(); Loading Loading @@ -38,6 +38,7 @@ private: // msg window WINDOW *msg_; t_lines msg_table_; char *msg_buffer_; // cmd window WINDOW *cmd_; Loading Loading
slc/trunk/src/history.cc +0 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,6 @@ void History::save(const string &filename) const { } fs.close(); } /*! Loading
slc/trunk/src/screen.cc +37 −2 Original line number Diff line number Diff line #include <ctype.h> #include <signal.h> #include <math.h> #include "slc.hh" #include "screen.hh" Loading @@ -18,6 +19,7 @@ */ Screen::Screen() { // msg init msg_buffer_ = 0; // cmd init *cmd_buffer_ = 0; Loading Loading @@ -66,6 +68,7 @@ void Screen::create_windows() { if (msg_) delwin(msg_); msg_ = newwin(LINES - 3, COLS, 0, 0); msg_buffer_ = (char *) realloc(msg_buffer_, COLS -2 + 1); msg_draw(); // cmd window Loading Loading @@ -245,7 +248,7 @@ void Screen::msg_print(const string &s) { ** Draw the content of the cmd window */ void Screen::cmd_draw() { char print_buf[MAX_LINE_SIZE]; char print_buf[MAX_LINE_SIZE + 1]; // clean and redraw the cmd box werase(cmd_); Loading @@ -261,7 +264,7 @@ void Screen::cmd_draw() { // copy part of buffer in print buffer size_t minsize = (MAX_LINE_SIZE < COLS - 2) ? MAX_LINE_SIZE : COLS - 2; strncpy(print_buf, cmd_buffer_ + cmd_win_off_, minsize); print_buf[minsize - 1] = 0; print_buf[minsize] = 0; // print print buffer wattron(cmd_, A_BOLD); Loading @@ -270,6 +273,8 @@ void Screen::cmd_draw() { // move cursor to right pos wmove(cmd_, 1, 1 + cmd_buf_off_ - cmd_win_off_); // refresh screen wrefresh(cmd_); } Loading @@ -279,6 +284,36 @@ void Screen::cmd_draw() { void Screen::msg_draw() { werase(msg_); box(msg_, 0, 0); t_lines::const_iterator line; size_t free_lines = LINES - 5; for (line = msg_table_.begin(); line != msg_table_.end() && free_lines > 0; ++line) { size_t len = strlen((*line).c_str()); // print one line if (len <= (size_t) COLS - 2) mvwprintw(msg_, free_lines--, 1, "%s", (*line).c_str()); // print multi line else { // compute line count const size_t nline = 1 + (size_t) ceil(((double) ( len - (COLS - 2)) / (double) (COLS - 4))); // iterate for each line starting with the last for (size_t i = nline; i > 0 && free_lines > 0; --i) { // compute string offset for this line const size_t print_offset = (i == 1) ? 0 : COLS - 2 + ((i - 2) * (COLS - 4)); // copy line into a buffer strncpy(msg_buffer_, (*line).c_str() + print_offset, COLS - ((i == 1) ? 2 : 4)); msg_buffer_[COLS - ((i == 1) ? 2 : 4)] = 0; // print line into screen mvwprintw(msg_, free_lines--, 1, (i == 1) ? "%s" : "> %s", msg_buffer_); } } } // refresh screen wrefresh(msg_); } Loading
slc/trunk/src/screen.hh +3 −2 Original line number Diff line number Diff line Loading @@ -2,14 +2,14 @@ # define SCREEN_HH_ # include <ncurses.h> # include <list> # include <deque> #define KEY_RETURN 10 #define KEY_EOF 4 class Screen { public: typedef std::list<string> t_lines; typedef std::deque<string> t_lines; public: Screen(); Loading Loading @@ -38,6 +38,7 @@ private: // msg window WINDOW *msg_; t_lines msg_table_; char *msg_buffer_; // cmd window WINDOW *cmd_; Loading