From ccd32b461f3a44848b14d86406bd50c0b0d26fd0 Mon Sep 17 00:00:00 2001 From: eknauel Date: Fri, 27 May 2005 07:04:24 +0000 Subject: [PATCH] added bindings to ioctl() with TIOCGWINSZ and TIOCSWINSZ --- c/ncurses.c | 35 ++++++++++++++++++++++++++++++++--- scheme/ncurses-packages.scm | 7 +++++-- scheme/ncurses.scm | 12 ++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/c/ncurses.c b/c/ncurses.c index e8b8400..cf7fcf1 100755 --- a/c/ncurses.c +++ b/c/ncurses.c @@ -2,6 +2,8 @@ #include "scheme48.h" #include +#include + //Makros zum Ein- und Auspacken von Zeigern #define curses_enter_window(w) s48_enter_integer((long) w) #define curses_extract_window(w) (WINDOW*) s48_extract_integer(w) @@ -2080,7 +2082,35 @@ s48_value scsh_clear(void) return S48_UNSPECIFIC; } +s48_value scsh_get_term_window_size(s48_value fd) +{ + struct winsize size; + if (ioctl(s48_extract_fixnum(fd), TIOCGWINSZ, (char *) &size) < 0) + return S48_FALSE; + else + return s48_list_4(s48_enter_fixnum(size.ws_row), + s48_enter_fixnum(size.ws_col), + s48_enter_fixnum(size.ws_xpixel), + s48_enter_fixnum(size.ws_ypixel)); +} + +s48_value scsh_set_term_window_size(s48_value fd, s48_value row, + s48_value col, s48_value xpixel, + s48_value ypixel) +{ + struct winsize size; + + size.ws_row = (unsigned short) s48_extract_fixnum(row); + size.ws_col = (unsigned short) s48_extract_fixnum(col); + size.ws_xpixel = (unsigned short) s48_extract_fixnum(xpixel); + size.ws_ypixel = (unsigned short) s48_extract_fixnum(ypixel); + + if (ioctl(s48_extract_fixnum(fd), TIOCSWINSZ, (char *) &size) < 0) + return S48_TRUE; + else + return S48_FALSE; +} void s48_init_ncurses(void) { @@ -2284,8 +2314,7 @@ void s48_init_ncurses(void) S48_EXPORT_FUNCTION(scsh_printw); S48_EXPORT_FUNCTION(scsh_refresh); S48_EXPORT_FUNCTION(scsh_clear); - - - + S48_EXPORT_FUNCTION(scsh_get_term_window_size); + S48_EXPORT_FUNCTION(scsh_set_term_window_size); } diff --git a/scheme/ncurses-packages.scm b/scheme/ncurses-packages.scm index 08458bc..55e65ad 100644 --- a/scheme/ncurses-packages.scm +++ b/scheme/ncurses-packages.scm @@ -366,7 +366,10 @@ input print-command-buffer cursor-right-pos - make-buffer-welcome)) + make-buffer-welcome + + get-terminal-window-size + set-terminal-window-size!)) (define-structure ncurses ncurses-interface (open scheme-with-scsh @@ -375,7 +378,7 @@ define-record-types conditions signals - tty-debug +; tty-debug handle) (files ncurses ncurses-constants diff --git a/scheme/ncurses.scm b/scheme/ncurses.scm index 664dd6f..3536152 100755 --- a/scheme/ncurses.scm +++ b/scheme/ncurses.scm @@ -1595,4 +1595,16 @@ (wmove win y (- x 1)) (wrefresh win))))))) +(import-lambda-definition get-terminal-window-size/internal + (file-descriptor) + "scsh_get_term_window_size") + +(define (get-terminal-window-size file-descriptor) + (apply values + (get-terminal-window-size/internal file-descriptor))) + +(import-lambda-definition set-terminal-window-size! + (file-descriptor rows columns x-pixels y-pixels) + "scsh_set_term_window_size") + \ No newline at end of file