Browse Source

Minor cleanup of process*

merge-requests/365/head
eidheim 10 years ago
parent
commit
e2c501db17
  1. 4
      src/process.cc
  2. 4
      src/process.h
  3. 2
      src/process_unix.cc
  4. 2
      src/process_win.cc
  5. 4
      src/terminal.cc

4
src/process.cc

@ -19,3 +19,7 @@ Process::~Process() {
if(stderr_thread.joinable()) if(stderr_thread.joinable())
stderr_thread.join(); stderr_thread.join();
} }
bool Process::write(const std::string &data) {
return write(data.c_str(), data.size());
}

4
src/process.h

@ -38,7 +38,9 @@ public:
///Wait until process is finished, and return exit_code. ///Wait until process is finished, and return exit_code.
int get_exit_code(); int get_exit_code();
///Write to stdin. ///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. ///Close stdin. If the process takes parameters from stdin, use this to notify that all parameters have been sent.
void close_stdin(); void close_stdin();

2
src/process_unix.cc

@ -124,7 +124,7 @@ int Process::get_exit_code() {
return 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(); stdin_mutex.lock();
if(stdin_fd) { if(stdin_fd) {
if(::write(*stdin_fd, bytes, n)>=0) { if(::write(*stdin_fd, bytes, n)>=0) {

2
src/process_win.cc

@ -195,7 +195,7 @@ int Process::get_exit_code() {
return static_cast<int>(exit_code); return static_cast<int>(exit_code);
} }
bool Process::write_stdin(const char *bytes, size_t n) { bool Process::write(const char *bytes, size_t n) {
stdin_mutex.lock(); stdin_mutex.lock();
if(stdin_fd) { if(stdin_fd) {
DWORD written; DWORD written;

4
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(); auto read_n=stdin_stream.gcount();
if(read_n==0) if(read_n==0)
break; break;
if(!process.write_stdin(buffer, read_n)) { if(!process.write(buffer, read_n)) {
break; break;
} }
} }
@ -265,7 +265,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) {
} }
else if(event->keyval==GDK_KEY_Return) { else if(event->keyval==GDK_KEY_Return) {
stdin_buffer+='\n'; 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)); get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1));
stdin_buffer.clear(); stdin_buffer.clear();
} }

Loading…
Cancel
Save