Selaa lähdekoodia

neercs: adapt PTY to canvas size.

master
Sam Hocevar 12 vuotta sitten
vanhempi
commit
27d2ad5dd0
3 muutettua tiedostoa jossa 19 lisäystä ja 11 poistoa
  1. +11
    -6
      neercs/term/pty.cpp
  2. +3
    -3
      neercs/term/pty.h
  3. +5
    -2
      neercs/term/term.cpp

+ 11
- 6
neercs/term/pty.cpp Näytä tiedosto

@@ -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;


+ 3
- 3
neercs/term/pty.h Näytä tiedosto

@@ -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;


+ 5
- 2
neercs/term/term.cpp Näytä tiedosto

@@ -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 (;;)
{


Ladataan…
Peruuta
Tallenna