File tree Expand file tree Collapse file tree 4 files changed +42
-14
lines changed Expand file tree Collapse file tree 4 files changed +42
-14
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ set(GIT2CPP_SRC
6464 ${GIT2CPP_SOURCE_DIR} /utils/common.hpp
6565 ${GIT2CPP_SOURCE_DIR} /utils/git_exception.cpp
6666 ${GIT2CPP_SOURCE_DIR} /utils/git_exception.hpp
67+ ${GIT2CPP_SOURCE_DIR} /utils/output .cpp
6768 ${GIT2CPP_SOURCE_DIR} /utils/output .hpp
6869 ${GIT2CPP_SOURCE_DIR} /utils/terminal_pager.cpp
6970 ${GIT2CPP_SOURCE_DIR} /utils/terminal_pager.hpp
Original file line number Diff line number Diff line change 1+ #include " output.hpp"
2+
3+ // OS-specific libraries.
4+ #include < sys/ioctl.h>
5+
6+ alternative_buffer::alternative_buffer ()
7+ {
8+ tcgetattr (fileno (stdin), &m_previous_termios);
9+ auto new_termios = m_previous_termios;
10+ // Disable canonical mode (buffered I/O) and echo from stdin to stdout.
11+ new_termios.c_lflag &= (~ICANON & ~ECHO);
12+ tcsetattr (fileno (stdin), TCSANOW, &new_termios);
13+
14+ std::cout << ansi_code::enable_alternative_buffer;
15+ }
16+
17+ alternative_buffer::~alternative_buffer ()
18+ {
19+ std::cout << ansi_code::disable_alternative_buffer;
20+
21+ // Restore previous termios settings.
22+ tcsetattr (fileno (stdin), TCSANOW, &m_previous_termios);
23+ }
Original file line number Diff line number Diff line change 44#include " ansi_code.hpp"
55#include " common.hpp"
66
7+ // OS-specific libraries.
8+ #include < termios.h>
9+
710// Scope object to hide the cursor. This avoids
811// cursor twinkling when rewritting the same line
912// too frequently.
@@ -19,3 +22,16 @@ struct cursor_hider : noncopyable_nonmovable
1922 std::cout << ansi_code::show_cursor;
2023 }
2124};
25+
26+ // Scope object to use alternative output buffer for
27+ // fullscreen interactive terminal input/output.
28+ class alternative_buffer : noncopyable_nonmovable
29+ {
30+ public:
31+ alternative_buffer ();
32+
33+ ~alternative_buffer ();
34+
35+ private:
36+ struct termios m_previous_termios;
37+ };
Original file line number Diff line number Diff line change 66
77// OS-specific libraries.
88#include < sys/ioctl.h>
9- #include < termios.h>
109
1110#include < termcolor/termcolor.hpp>
1211
1312#include " ansi_code.hpp"
13+ #include " output.hpp"
1414#include " terminal_pager.hpp"
1515
1616terminal_pager::terminal_pager ()
@@ -181,14 +181,7 @@ void terminal_pager::show()
181181 return ;
182182 }
183183
184- struct termios old_termios;
185- tcgetattr (fileno (stdin), &old_termios);
186- auto new_termios = old_termios;
187- // Disable canonical mode (buffered I/O) and echo from stdin to stdout.
188- new_termios.c_lflag &= (~ICANON & ~ECHO);
189- tcsetattr (fileno (stdin), TCSANOW, &new_termios);
190-
191- std::cout << ansi_code::enable_alternative_buffer;
184+ alternative_buffer alt_buffer;
192185
193186 m_start_row_index = 0 ;
194187 render_terminal ();
@@ -199,11 +192,6 @@ void terminal_pager::show()
199192 stop = process_input (get_input ());
200193 } while (!stop);
201194
202- std::cout << ansi_code::disable_alternative_buffer;
203-
204- // Restore original termios settings.
205- tcsetattr (fileno (stdin), TCSANOW, &old_termios);
206-
207195 m_lines.clear ();
208196 m_start_row_index = 0 ;
209197}
You can’t perform that action at this time.
0 commit comments