File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 22#include < cpp-terminal/input.hpp>
33#include < thread>
44#include " private/platform.hpp"
5+ #include < cpp-terminal/base.hpp>
6+
57
68int Term::read_key () {
79 int key{};
@@ -183,3 +185,22 @@ int Term::read_key0() {
183185 return c;
184186 }
185187}
188+
189+ // returns the whole input from STDIN as string
190+ std::string Term::read_stdin () {
191+ std::string file;
192+ char c;
193+ while (true ) {
194+ c = Private::read_raw_stdin ();
195+ if (c == 0x04 ) { // check for end of transmission signal
196+ return file;
197+ } else {
198+ file += c;
199+ }
200+ }
201+ }
202+ std::string Term::read_stdin_alone () {
203+ // temporarily enable raw mode
204+ Term::Terminal term (false , true , false , false );
205+ return Term::read_stdin ();
206+ }
Original file line number Diff line number Diff line change 11#pragma once
2+ #include < string>
23
34namespace Term {
45enum Key {
@@ -40,11 +41,24 @@ enum Key {
4041};
4142
4243// Waits for a key press, translates escape codes
44+ // if Term:Terminal is not enabling the keyboard it'll loop for infinity
4345int read_key ();
4446
4547// If there was a key press, returns the translated key from escape codes,
46- // otherwise returns 0. If the escape code is not supported, returns a
48+ // otherwise returns 0. If the escape code is not supported it returns a
4749// negative number.
50+ // if Term::Terminal is not enabling the keyboard it'll always return 0
4851int read_key0 ();
4952
53+ // returns the stdin as a string
54+ // waits until the EOT signal is send
55+ // if Term::Terminal is not enabling the keyboard this function will wait until
56+ // the user presses CTRL+D (which sends the EOT signal)
57+ std::string read_stdin ();
58+
59+ // returns stdin as a string, Term::Terminal is used to enable input to make the
60+ // function non-blocking, use Term::read_stdin() when Term::Terminal is already
61+ // created
62+ std::string read_stdin_alone ();
63+
5064} // namespace Term
You can’t perform that action at this time.
0 commit comments