[INTERPRETER]

* NEW: Stream.IsTerm is a new property that returns if a stream is a terminal.
* NEW: Stream.Term.Resize() is a new method that resizes a terminal.


git-svn-id: svn://localhost/gambas/trunk@7669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2016-03-26 13:09:20 +00:00
parent 159f039e02
commit 83f7f6677e
3 changed files with 41 additions and 1 deletions

View File

@ -31,6 +31,7 @@
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <pty.h>
#include "gb_common.h" #include "gb_common.h"
#include "gb_list.h" #include "gb_list.h"
@ -48,6 +49,7 @@
#include "gbx_c_file.h" #include "gbx_c_file.h"
#define STREAM_FD STREAM_handle(CSTREAM_stream(THIS_STREAM))
CFILE *CFILE_in, *CFILE_out, *CFILE_err; CFILE *CFILE_in, *CFILE_out, *CFILE_err;
@ -716,7 +718,7 @@ END_METHOD
BEGIN_PROPERTY(Stream_Handle) BEGIN_PROPERTY(Stream_Handle)
GB_ReturnInteger(STREAM_handle(CSTREAM_stream(THIS_STREAM))); GB_ReturnInteger(STREAM_FD);
END_PROPERTY END_PROPERTY
@ -829,6 +831,12 @@ BEGIN_METHOD_VOID(Stream_Cancel)
END_METHOD END_METHOD
BEGIN_PROPERTY(Stream_IsTerm)
GB_ReturnBoolean(isatty(STREAM_FD));
END_PROPERTY
BEGIN_METHOD_VOID(StreamLines_next) BEGIN_METHOD_VOID(StreamLines_next)
char *str; char *str;
@ -844,6 +852,24 @@ BEGIN_METHOD_VOID(StreamLines_next)
END_METHOD END_METHOD
BEGIN_PROPERTY(StreamTerm_Name)
GB_ReturnNewZeroString(ttyname(STREAM_FD));
END_PROPERTY
BEGIN_METHOD(StreamTerm_Resize, GB_INTEGER width; GB_INTEGER height)
struct winsize winSize = { 0 };
winSize.ws_row = (unsigned short)Max(1, Min(65535, VARG(height)));
winSize.ws_col = (unsigned short)Max(1, Min(65535, VARG(width)));
if (ioctl(STREAM_FD, TIOCSWINSZ, (char *)&winSize))
THROW_SYSTEM(errno, NULL);
END_METHOD
#endif #endif
GB_DESC NATIVE_StreamLines[] = GB_DESC NATIVE_StreamLines[] =
@ -855,6 +881,16 @@ GB_DESC NATIVE_StreamLines[] =
GB_END_DECLARE GB_END_DECLARE
}; };
GB_DESC NATIVE_StreamTerm[] =
{
GB_DECLARE(".Stream.Term", 0), GB_VIRTUAL_CLASS(),
GB_PROPERTY_READ("Name", "s", StreamTerm_Name),
GB_METHOD("Resize", NULL, StreamTerm_Resize, "(Width)i(Height)i"),
GB_END_DECLARE
};
GB_DESC NATIVE_Stream[] = GB_DESC NATIVE_Stream[] =
{ {
GB_DECLARE("Stream", sizeof(CSTREAM)), GB_DECLARE("Stream", sizeof(CSTREAM)),
@ -870,8 +906,10 @@ GB_DESC NATIVE_Stream[] =
GB_PROPERTY("Blocking", "b", Stream_Blocking), GB_PROPERTY("Blocking", "b", Stream_Blocking),
GB_PROPERTY("Tag", "v", Stream_Tag), GB_PROPERTY("Tag", "v", Stream_Tag),
GB_METHOD("ReadLine", "s", Stream_ReadLine, "[(Escape)s]"), GB_METHOD("ReadLine", "s", Stream_ReadLine, "[(Escape)s]"),
GB_PROPERTY_READ("IsTerm", "b", Stream_IsTerm),
GB_PROPERTY_SELF("Lines", ".Stream.Lines"), GB_PROPERTY_SELF("Lines", ".Stream.Lines"),
GB_PROPERTY_SELF("Term", ".Stream.Term"),
GB_METHOD("Begin", NULL, Stream_Begin, NULL), GB_METHOD("Begin", NULL, Stream_Begin, NULL),
GB_METHOD("Send", NULL, Stream_End, NULL), GB_METHOD("Send", NULL, Stream_End, NULL),

View File

@ -56,6 +56,7 @@ typedef
#ifndef __GBX_C_FILE_C #ifndef __GBX_C_FILE_C
extern GB_DESC NATIVE_StreamLines[]; extern GB_DESC NATIVE_StreamLines[];
extern GB_DESC NATIVE_StreamTerm[];
extern GB_DESC NATIVE_Stream[]; extern GB_DESC NATIVE_Stream[];
extern GB_DESC NATIVE_File[]; extern GB_DESC NATIVE_File[];
extern GB_DESC NATIVE_Stat[]; extern GB_DESC NATIVE_Stat[];

View File

@ -101,6 +101,7 @@ static const CLASS_INIT init_list[] =
{ NATIVE_Collection, &CLASS_Collection, CQA_COLLECTION }, { NATIVE_Collection, &CLASS_Collection, CQA_COLLECTION },
{ NATIVE_Error, NULL }, { NATIVE_Error, NULL },
{ NATIVE_StreamLines, NULL }, { NATIVE_StreamLines, NULL },
{ NATIVE_StreamTerm, NULL },
{ NATIVE_Stream, &CLASS_Stream }, { NATIVE_Stream, &CLASS_Stream },
{ NATIVE_StatPerm, NULL }, { NATIVE_StatPerm, NULL },
{ NATIVE_Stat, &CLASS_Stat }, { NATIVE_Stat, &CLASS_Stat },