From 27d2ad5dd08618c26629e5bcda4f0b5abda69ff8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 5 Sep 2012 20:08:36 +0000 Subject: [PATCH] neercs: adapt PTY to canvas size. --- neercs/term/pty.cpp | 17 +++++++++++------ neercs/term/pty.h | 6 +++--- neercs/term/term.cpp | 7 +++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/neercs/term/pty.cpp b/neercs/term/pty.cpp index 657252f..35d7c8b 100644 --- a/neercs/term/pty.cpp +++ b/neercs/term/pty.cpp @@ -41,12 +41,11 @@ using namespace lol; #include "neercs.h" -Pty::Pty(ivec2 size) +Pty::Pty() : m_fd(-1), m_pid(-1), m_unread_data(0), - m_unread_len(0), - m_size(size) + m_unread_len(0) { ; } @@ -61,7 +60,7 @@ Pty::~Pty() } } -void Pty::Run(char const *command) +void Pty::Run(char const *command, ivec2 size) { #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H int fd; @@ -78,7 +77,7 @@ void Pty::Run(char const *command) } else if (pid == 0) { - SetWindowSize(0, m_size); + SetWindowSize(size, 0); /* putenv() eats the string, they need to be writable */ static char tmp1[] = "CACA_DRIVER=slang"; @@ -175,9 +174,15 @@ void Pty::UnreadData(char *data, size_t len) m_unread_data = new_data; } -void Pty::SetWindowSize(int64_t fd, ivec2 size) +void Pty::SetWindowSize(ivec2 size, int64_t fd /* = -1 */) { #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H + if (m_size == size) + return; + + if (fd < 0) + fd = m_fd; + m_size = size; struct winsize ws; diff --git a/neercs/term/pty.h b/neercs/term/pty.h index edb147a..7215f10 100644 --- a/neercs/term/pty.h +++ b/neercs/term/pty.h @@ -8,13 +8,13 @@ class Pty { public: - Pty(ivec2 size); + Pty(); ~Pty(); - void Run(char const *command); + void Run(char const *command, ivec2 size); size_t ReadData(char *data, size_t maxlen); void UnreadData(char *data, size_t len); - void SetWindowSize(int64_t fd, ivec2 size); + void SetWindowSize(ivec2 size, int64_t fd = -1); private: int64_t m_fd; diff --git a/neercs/term/term.cpp b/neercs/term/term.cpp index 5a0a6b9..e5f869d 100644 --- a/neercs/term/term.cpp +++ b/neercs/term/term.cpp @@ -20,14 +20,14 @@ Term::Term(ivec2 size) m_caca = caca_create_canvas(size.x, size.y); #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H - m_pty = new Pty(size); + m_pty = new Pty(); char const *shell = getenv("SHELL"); if (!shell) shell = "/bin/sh"; shell = "cacaclock"; shell = "cacafire"; shell = "cacademo"; - m_pty->Run(shell); + m_pty->Run(shell, size); #endif } @@ -40,6 +40,9 @@ void Term::TickGame(float seconds) /* XXX: for now we draw fancy shit */ m_time += seconds; + m_pty->SetWindowSize(ivec2(caca_get_canvas_width(m_caca), + caca_get_canvas_height(m_caca))); + size_t total = 0; for (;;) {