Skip to content

Commit

Permalink
FEAT: implemented QUERY action on INPUT port to get information about…
Browse files Browse the repository at this point in the history
… console's size
  • Loading branch information
Oldes committed Nov 21, 2018
1 parent fba3b10 commit e33bb61
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/boot/sysobj.r
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ standard: context [
none
]

console-info: context [
buffer-size: none
window-size: none
]

extension: context [
lib-base: ; handle to DLL
lib-file: ; file name loaded
Expand Down
10 changes: 10 additions & 0 deletions src/core/p-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
if (IS_OPEN(req)) return R_TRUE;
return R_FALSE;

case A_QUERY:
if (OS_DO_DEVICE(req, RDC_QUERY) < 0) return R_NONE;
REBVAL *spec = Get_System(SYS_STANDARD, STD_CONSOLE_INFO);
if (!IS_OBJECT(spec)) Trap_Arg(spec);
REBSER *obj = CLONE_OBJECT(VAL_OBJ_FRAME(spec));
SET_OBJECT(D_RET, obj);
SET_PAIR(OFV(obj, STD_CONSOLE_INFO_BUFFER_SIZE), req->console.buffer_cols, req->console.buffer_rows);
SET_PAIR(OFV(obj, STD_CONSOLE_INFO_WINDOW_SIZE), req->console.window_cols, req->console.window_rows);
break;

default:
Trap_Action(REB_PORT, action);
}
Expand Down
6 changes: 6 additions & 0 deletions src/include/reb-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ struct rebol_devreq {
u32 remote_port; // remote port
void *host_info; // for DNS usage
} net;
struct {
u32 buffer_rows;
u32 buffer_cols;
u32 window_rows;
u32 window_cols;
} console;
};
};
#pragma pack()
Expand Down
18 changes: 17 additions & 1 deletion src/os/posix/dev-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>

#include "reb-host.h"

Expand Down Expand Up @@ -260,6 +261,21 @@ static void Close_Stdio(void)
return DR_DONE;
}

/***********************************************************************
**
*/ DEVICE_CMD Query_IO(REBREQ *req)
/*
** Resolve port information. Currently just size of console.
**
***********************************************************************/
{
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
req->console.window_rows =
req->console.buffer_rows = w.ws_row;
req->console.window_cols = w.ws_col;
return DR_DONE;
}

/***********************************************************************
**
Expand Down Expand Up @@ -302,7 +318,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
Write_IO,
0, // poll
0, // connect
0, // query
Query_IO,
0, // modify
Open_Echo, // CREATE used for opening echo file
};
Expand Down
18 changes: 17 additions & 1 deletion src/os/win32/dev-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@ static void close_stdio(void)
return DR_DONE;
}

/***********************************************************************
**
*/ DEVICE_CMD Query_IO(REBREQ *req)
/*
** Resolve console port information. Currently just size of console.
**
***********************************************************************/
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(Std_Out, &csbiInfo);
req->console.buffer_rows = csbiInfo.dwSize.Y;
req->console.buffer_cols = csbiInfo.dwSize.X;
req->console.window_rows = csbiInfo.srWindow.Bottom - csbiInfo.srWindow.Top + 1;
req->console.window_cols = csbiInfo.srWindow.Right - csbiInfo.srWindow.Left + 1;
return DR_DONE;
}

/***********************************************************************
**
Expand Down Expand Up @@ -482,7 +498,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
Write_IO,
0, // poll
0, // connect
0, // query
Query_IO,
0, // modify
Open_Echo, // CREATE used for opening echo file
};
Expand Down

0 comments on commit e33bb61

Please sign in to comment.