diff --git a/src/process.cc b/src/process.cc index 0ab07f0..f831ec9 100644 --- a/src/process.cc +++ b/src/process.cc @@ -19,3 +19,7 @@ Process::~Process() { if(stderr_thread.joinable()) stderr_thread.join(); } + +bool Process::write(const std::string &data) { + return write(data.c_str(), data.size()); +} diff --git a/src/process.h b/src/process.h index 989f4f1..f567664 100644 --- a/src/process.h +++ b/src/process.h @@ -38,7 +38,9 @@ public: ///Wait until process is finished, and return exit_code. int get_exit_code(); ///Write to stdin. - bool write_stdin(const char *bytes, size_t n); + bool write(const char *bytes, size_t n); + ///Write to stdin. Convenience function using write(const char *, size_t). + bool write(const std::string &data); ///Close stdin. If the process takes parameters from stdin, use this to notify that all parameters have been sent. void close_stdin(); diff --git a/src/process_unix.cc b/src/process_unix.cc index 14e99ae..bdf9295 100644 --- a/src/process_unix.cc +++ b/src/process_unix.cc @@ -124,7 +124,7 @@ int Process::get_exit_code() { return exit_code; } -bool Process::write_stdin(const char *bytes, size_t n) { +bool Process::write(const char *bytes, size_t n) { stdin_mutex.lock(); if(stdin_fd) { if(::write(*stdin_fd, bytes, n)>=0) { diff --git a/src/process_win.cc b/src/process_win.cc index 3be6472..ea1c6bf 100644 --- a/src/process_win.cc +++ b/src/process_win.cc @@ -195,7 +195,7 @@ int Process::get_exit_code() { return static_cast(exit_code); } -bool Process::write_stdin(const char *bytes, size_t n) { +bool Process::write(const char *bytes, size_t n) { stdin_mutex.lock(); if(stdin_fd) { DWORD written; diff --git a/src/terminal.cc b/src/terminal.cc index b271279..539591f 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -115,7 +115,7 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c auto read_n=stdin_stream.gcount(); if(read_n==0) break; - if(!process.write_stdin(buffer, read_n)) { + if(!process.write(buffer, read_n)) { break; } } @@ -265,7 +265,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { } else if(event->keyval==GDK_KEY_Return) { stdin_buffer+='\n'; - processes.back()->write_stdin(stdin_buffer.c_str(), stdin_buffer.size()); + processes.back()->write(stdin_buffer); get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1)); stdin_buffer.clear(); }