File tree Expand file tree Collapse file tree 2 files changed +7
-14
lines changed
Expand file tree Collapse file tree 2 files changed +7
-14
lines changed Original file line number Diff line number Diff line change 1313#include " terminal_pager.hpp"
1414
1515terminal_pager::terminal_pager ()
16- : m_grabbed( false ), m_rows(0 ), m_columns(0 ), m_start_row_index(0 )
16+ : m_rows(0 ), m_columns(0 ), m_start_row_index(0 )
1717{
1818 maybe_grab_cout ();
1919}
@@ -46,11 +46,14 @@ std::string terminal_pager::get_input() const
4646void terminal_pager::maybe_grab_cout ()
4747{
4848 // Unfortunately need to access _internal namespace of termcolor to check if a tty.
49- if (!m_grabbed && termcolor::_internal::is_atty (std::cout))
49+ if (termcolor::_internal::is_atty (std::cout))
5050 {
5151 // Should we do anything with cerr?
5252 m_cout_rdbuf = std::cout.rdbuf (&m_stringbuf);
53- m_grabbed = true ;
53+ }
54+ else
55+ {
56+ m_cout_rdbuf = std::cout.rdbuf ();
5457 }
5558}
5659
@@ -98,11 +101,7 @@ bool terminal_pager::process_input(const std::string& input)
98101
99102void terminal_pager::release_cout ()
100103{
101- if (m_grabbed)
102- {
103- std::cout.rdbuf (m_cout_rdbuf);
104- m_grabbed = false ;
105- }
104+ std::cout.rdbuf (m_cout_rdbuf);
106105}
107106
108107void terminal_pager::render_terminal () const
@@ -166,11 +165,6 @@ void terminal_pager::scroll(bool up, bool page)
166165
167166void terminal_pager::show ()
168167{
169- if (!m_grabbed)
170- {
171- return ;
172- }
173-
174168 release_cout ();
175169
176170 split_input_at_newlines (m_stringbuf.view ());
Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ class terminal_pager
5454 void update_terminal_size ();
5555
5656
57- bool m_grabbed;
5857 std::stringbuf m_stringbuf;
5958 std::streambuf* m_cout_rdbuf;
6059 std::vector<std::string> m_lines;
You can’t perform that action at this time.
0 commit comments