diff --git a/neercs/term/pty.cpp b/neercs/term/pty.cpp index fb73936..530e942 100644 --- a/neercs/term/pty.cpp +++ b/neercs/term/pty.cpp @@ -44,6 +44,7 @@ using namespace lol; Pty::Pty() : m_fd(-1), m_pid(-1), + m_eof(false), m_unread_data(0), m_unread_len(0) { @@ -104,6 +105,11 @@ void Pty::Run(char const *command, ivec2 size) #endif } +bool Pty::IsEof() const +{ + return m_eof; +} + size_t Pty::ReadData(char *data, size_t maxlen) { #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H @@ -141,14 +147,19 @@ size_t Pty::ReadData(char *data, size_t maxlen) if (ret < 0) { Log::Error("cannot read from PTY\n"); + m_eof = true; return 0; } - - if (ret) + else if (ret) { if (FD_ISSET((int)m_fd, &fdset)) { ssize_t nr = read((int)m_fd, data, maxlen); + + /* Data available but zero-length read: EOF */ + if (nr <= 0) + m_eof = true; + if (nr >= 0) return nr; } diff --git a/neercs/term/pty.h b/neercs/term/pty.h index 9add5ac..02fc78b 100644 --- a/neercs/term/pty.h +++ b/neercs/term/pty.h @@ -12,6 +12,7 @@ public: ~Pty(); void Run(char const *command, ivec2 size); + bool IsEof() const; size_t ReadData(char *data, size_t maxlen); void UnreadData(char *data, size_t len); @@ -22,6 +23,7 @@ public: private: int64_t m_fd; int64_t m_pid; + bool m_eof; char const *m_argv[2]; char *m_unread_data; size_t m_unread_len; diff --git a/neercs/term/term.cpp b/neercs/term/term.cpp index 439f23e..57e6b09 100644 --- a/neercs/term/term.cpp +++ b/neercs/term/term.cpp @@ -113,13 +113,18 @@ void Term::TickGame(float seconds) } } - /* This is the real terminal code */ - /* XXX: for now we draw fancy shit */ m_time += seconds; + if (m_pty->IsEof()) + { + /* FIXME: we could do more interesting things hereā€¦ */ + Ticker::Shutdown(); + } + m_pty->SetWindowSize(ivec2(caca_get_canvas_width(m_caca), caca_get_canvas_height(m_caca))); + /* This is the real terminal code */ size_t total = 0; for (;;) { @@ -248,4 +253,4 @@ void Term::DrawFancyShit() caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL"); caca_put_str(m_caca, 0, 3, "LOL"); caca_put_str(m_caca, 0, 4, "root@lol:~/"); -} \ No newline at end of file +} diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp index 9b4384e..98802fa 100644 --- a/neercs/video/render.cpp +++ b/neercs/video/render.cpp @@ -726,10 +726,6 @@ void Render::Pause() void Render::TickDraw(float seconds) { /* keyboard manager */ - if (Input::WasReleased(Key::Escape)) - { - Ticker::Shutdown(); - } if (Input::WasPressed(Key::F1)) { g_setup = !g_setup;