projects
/
apps
/
madtty.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
resize works in fact :P
[apps/madtty.git]
/
demo
/
boxshell.c
diff --git
a/demo/boxshell.c
b/demo/boxshell.c
index
44a9d9c
..
c8ef22a
100644
(file)
--- a/
demo/boxshell.c
+++ b/
demo/boxshell.c
@@
-6,10
+6,13
@@
*/
#include <ncurses.h>
*/
#include <ncurses.h>
-#include <stdio.h>
+
#include <signal.h>
#include <signal.h>
+#include <stdio.h>
#include <string.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/time.h>
+#include <termios.h>
#include <time.h>
#include <madtty/madtty.h>
#include <time.h>
#include <madtty/madtty.h>
@@
-18,45
+21,31
@@
static unsigned char getout = 0;
static int screen_w, screen_h;
static WINDOW *term_win;
static int screen_w, screen_h;
static WINDOW *term_win;
-void
sigchld(int signo __attribute__((unused))
)
+void
handler(int signo
)
{
{
- getout = 1;
+ switch (signo) {
+ case SIGCHLD:
+ getout = 1;
+ break;
+ case SIGWINCH:
+ break;
+ }
}
}
-int main(
int argc, char *argv[]
)
+int main(
void
)
{
{
- struct timeval next = { 0, 0 };
madtty_t *rt;
madtty_t *rt;
- int i, j, ch, w, h, pos;
- char buf[BUFSIZ];
-
- signal(SIGCHLD, sigchld);
-
- w = 80;
- h = 40;
- if (argc > 1) {
- char *p = argv[1];
- w = strtol(p, &p, 10);
- if (*p++ == 'x')
- h = strtol(p, &p, 10);
- }
+ int dirty = 0;
+
+ signal(SIGCHLD, handler);
+ signal(SIGWINCH, handler);
madtty_initialize();
getmaxyx(stdscr, screen_h, screen_w);
madtty_initialize();
getmaxyx(stdscr, screen_h, screen_w);
- /* paint the screen blue */
- attrset(COLOR_PAIR(004));
- for (i = 0; i < screen_h; i++)
- for (j = 0; j < screen_w; j++)
- addch(' ');
- refresh();
-
/* create a window with a frame */
/* create a window with a frame */
- term_win = newwin(h, w, 2, 3);
- mvwprintw(term_win, 0, 27, " Term In a Box ");
- wrefresh(term_win);
-
- rt = madtty_create(h, w);
+ term_win = newwin(screen_h - 2, screen_w - 2, 1, 1);
+ rt = madtty_create(screen_h - 2, screen_w - 2);
{
const char *path = getenv("SHELL") ?: "/bin/sh";
const char *args[] = { path, "--login", NULL};
{
const char *path = getenv("SHELL") ?: "/bin/sh";
const char *args[] = { path, "--login", NULL};
@@
-66,44
+55,42
@@
int main(int argc, char *argv[])
/* keep reading keypresses from the user and passing them to the terminal;
* also, redraw the terminal to the window at each iteration */
/* keep reading keypresses from the user and passing them to the terminal;
* also, redraw the terminal to the window at each iteration */
- ch = '\0';
- pos = 0;
while (!getout) {
fd_set rfds;
while (!getout) {
fd_set rfds;
- struct timeval tv = { 0 , 1000 }, t;
+ struct timeval tv = { 0, 1000 * 1000 / 50 };
+ int ch;
FD_ZERO(&rfds);
FD_SET(rt->pty, &rfds);
if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) {
FD_ZERO(&rfds);
FD_SET(rt->pty, &rfds);
if (select(rt->pty + 1, &rfds, NULL, NULL, &tv) > 0) {
- int nb;
-
- nb = madtty_read(rt, buf + pos, sizeof(buf) - pos);
- if (nb <= 0)
- continue;
- pos += nb;
-
- nb = madtty_inject(rt, buf, pos);
- if (nb <= 0)
- continue;
- memmove(buf, buf + nb, pos - nb);
- pos -= nb;
+ if (FD_ISSET(rt->pty, &rfds)) {
+ madtty_process(rt);
+ dirty = 1;
+ }
}
while ((ch = getch()) != ERR) {
}
while ((ch = getch()) != ERR) {
+#if 0
+ if (ch == KEY_F(1)) {
+ struct winsize ws = {
+ .ws_row = --rt->rows,
+ .ws_col = --rt->cols,
+ };
+
+ erase();
+ ioctl(rt->pty, TIOCSWINSZ, &ws);
+ wresize(term_win, rt->rows, rt->cols);
+ }
+#endif
madtty_keypress(rt, ch); /* pass the keypress for handling */
madtty_keypress(rt, ch); /* pass the keypress for handling */
+ dirty = 1;
}
}
- gettimeofday(&t, NULL);
- if (timercmp(&t, &next, >=)) {
+ if (dirty) {
madtty_draw(rt, term_win, 0, 0);
wrefresh(term_win);
madtty_draw(rt, term_win, 0, 0);
wrefresh(term_win);
- gettimeofday(&next, NULL);
- next.tv_usec += 1000 * 1000 / 50;
- if (next.tv_usec > 1000 * 1000) {
- next.tv_usec -= 1000 * 1000;
- next.tv_sec++;
- }
+ dirty = 0;
}
}
}
}