fixed linux implementation and added test
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
#include "term.h"
|
#include "term.h"
|
||||||
#include "../includes/tart.h"
|
|
||||||
|
|
||||||
|
|
||||||
// if windows is defined.
|
// if windows is defined.
|
||||||
|
|
||||||
@@ -23,16 +21,19 @@ struct tart_vec2 term_current_size() {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
struct tart_vec2 term_current_size() {
|
struct tart_vec2 term_current_size() {
|
||||||
struct tart_vec2 ret;
|
struct tart_vec2 ret;
|
||||||
|
|
||||||
unsigned int rows = w.ws_row;
|
|
||||||
unsigned int cols = w.ws_col;
|
|
||||||
|
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
|
|
||||||
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
|
||||||
|
unsigned int rows = w.ws_col;
|
||||||
|
unsigned int cols = w.ws_row;
|
||||||
|
|
||||||
unsigned short max_short = 0XFFFF;
|
unsigned short max_short = 0XFFFF;
|
||||||
if(rows < max_short && cols < max_short) {
|
if(rows < max_short && cols < max_short) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "test_term.h"
|
#include "test_term.h"
|
||||||
void term_run(struct pickle_shelf* shelf) {
|
void term_run(struct pickle_shelf* shelf) {
|
||||||
@@ -8,11 +15,21 @@ void term_run(struct pickle_shelf* shelf) {
|
|||||||
CREATEJAR(Test_Term);
|
CREATEJAR(Test_Term);
|
||||||
|
|
||||||
PICKLE(Test_get_window_size) {
|
PICKLE(Test_get_window_size) {
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
|
|
||||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||||
int columns = (unsigned int)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
int columns = (unsigned int)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
||||||
int rows = (unsigned int)(csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
int rows = (unsigned int)(csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
||||||
|
#else
|
||||||
|
struct winsize w;
|
||||||
|
|
||||||
|
|
||||||
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
|
||||||
|
unsigned int rows = w.ws_row;
|
||||||
|
unsigned int columns = w.ws_col;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
std::cout << term_current_size().x << "term_current_size()\n";
|
std::cout << term_current_size().x << "term_current_size()\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user