| @@ -41,12 +41,11 @@ using namespace lol; | |||||
| #include "neercs.h" | #include "neercs.h" | ||||
| Pty::Pty(ivec2 size) | |||||
| Pty::Pty() | |||||
| : m_fd(-1), | : m_fd(-1), | ||||
| m_pid(-1), | m_pid(-1), | ||||
| m_unread_data(0), | 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 | #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | ||||
| int fd; | int fd; | ||||
| @@ -78,7 +77,7 @@ void Pty::Run(char const *command) | |||||
| } | } | ||||
| else if (pid == 0) | else if (pid == 0) | ||||
| { | { | ||||
| SetWindowSize(0, m_size); | |||||
| SetWindowSize(size, 0); | |||||
| /* putenv() eats the string, they need to be writable */ | /* putenv() eats the string, they need to be writable */ | ||||
| static char tmp1[] = "CACA_DRIVER=slang"; | static char tmp1[] = "CACA_DRIVER=slang"; | ||||
| @@ -175,9 +174,15 @@ void Pty::UnreadData(char *data, size_t len) | |||||
| m_unread_data = new_data; | 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 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; | m_size = size; | ||||
| struct winsize ws; | struct winsize ws; | ||||
| @@ -8,13 +8,13 @@ | |||||
| class Pty | class Pty | ||||
| { | { | ||||
| public: | public: | ||||
| Pty(ivec2 size); | |||||
| Pty(); | |||||
| ~Pty(); | ~Pty(); | ||||
| void Run(char const *command); | |||||
| void Run(char const *command, ivec2 size); | |||||
| size_t ReadData(char *data, size_t maxlen); | size_t ReadData(char *data, size_t maxlen); | ||||
| void UnreadData(char *data, size_t len); | void UnreadData(char *data, size_t len); | ||||
| void SetWindowSize(int64_t fd, ivec2 size); | |||||
| void SetWindowSize(ivec2 size, int64_t fd = -1); | |||||
| private: | private: | ||||
| int64_t m_fd; | int64_t m_fd; | ||||
| @@ -20,14 +20,14 @@ Term::Term(ivec2 size) | |||||
| m_caca = caca_create_canvas(size.x, size.y); | m_caca = caca_create_canvas(size.x, size.y); | ||||
| #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | #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"); | char const *shell = getenv("SHELL"); | ||||
| if (!shell) | if (!shell) | ||||
| shell = "/bin/sh"; | shell = "/bin/sh"; | ||||
| shell = "cacaclock"; | shell = "cacaclock"; | ||||
| shell = "cacafire"; | shell = "cacafire"; | ||||
| shell = "cacademo"; | shell = "cacademo"; | ||||
| m_pty->Run(shell); | |||||
| m_pty->Run(shell, size); | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -40,6 +40,9 @@ void Term::TickGame(float seconds) | |||||
| /* XXX: for now we draw fancy shit */ | /* XXX: for now we draw fancy shit */ | ||||
| m_time += seconds; | m_time += seconds; | ||||
| m_pty->SetWindowSize(ivec2(caca_get_canvas_width(m_caca), | |||||
| caca_get_canvas_height(m_caca))); | |||||
| size_t total = 0; | size_t total = 0; | ||||
| for (;;) | for (;;) | ||||
| { | { | ||||