Skip to content

Commit

Permalink
remove linux only code
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperGY committed May 3, 2023
1 parent 62ead7e commit e292c07
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 93 deletions.
Binary file modified bin/libtermDisplay.a
Binary file not shown.
Binary file modified bin/out
Binary file not shown.
Binary file modified obj/helpers.o
Binary file not shown.
Binary file modified obj/initialization.o
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main(void)
return -1;
}

while (getch(0) != 'q')
while (1)
{
td_drawPoint(0, 0, '*', TD_COLOR_WHITE, TD_COLOR_DEFAULT);
td_drawPoint(40, 27, '*', TD_COLOR_WHITE, TD_COLOR_DEFAULT);
Expand Down
45 changes: 1 addition & 44 deletions src/termDisplay/helpers.c
Original file line number Diff line number Diff line change
@@ -1,44 +1 @@
#include "termDisplay.h"

char basic_getch()
{
char ch;

struct termios old;
struct termios new;

tcgetattr(0, &old);
new = old;
new.c_lflag &= ~ICANON;
new.c_lflag &= ~ECHO;
tcsetattr(0, TCSANOW, &new);
ch = (char)getchar();
tcsetattr(0, TCSANOW, &old);

return ch;
}

// returns NULL if there was no character
// max wait time is in milliseconds
char getch(unsigned int max_wait_time)
{
char ch = NULL;

fd_set rfds;
struct timeval tv;

FD_ZERO(&rfds);
FD_SET(0, &rfds);

tv.tv_sec = 0;
tv.tv_usec = max_wait_time *10;

int has_input = select(1, &rfds, NULL, NULL, &tv);

if (has_input == 1)
{
ch = basic_getch();
}

return ch;
}
#include "termDisplay.h"
10 changes: 0 additions & 10 deletions src/termDisplay/initialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ int **TD_FG_COLOR_BUFFER = NULL;
int **TD_BG_COLOR_BUFFER = NULL;
char *TD_PRINT_BUFFER = NULL;

struct termios old_settings;
struct termios new_settings;

/**
* @brief Initializes the character buffer if it hasn't already been initialized
*
Expand Down Expand Up @@ -101,12 +98,6 @@ int td_initialize(int width, int height)
return 0;
}

tcgetattr(0, &old_settings);
new_settings = old_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
tcsetattr(0, TCSANOW, &new_settings);

printf("\x1b[?25l\x1b[H\x1b[2J");

return 1;
Expand All @@ -128,7 +119,6 @@ void td_terminate(int clear)
}

printf("\x1b[?25h");
tcsetattr(0, TCSANOW, &old_settings);
return;
}

Expand Down
38 changes: 0 additions & 38 deletions src/termDisplay/termDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <math.h>
#include <string.h>

#include <termios.h>
#include <sys/select.h>

/**
* @brief Width of the buffers
*/
Expand Down Expand Up @@ -63,17 +60,6 @@ extern int TD_COLOR_WHITE;
*/
extern int TD_FG_TO_BG_OFFSET;

/**
* @brief Saved terminal settings
*
*/
extern struct termios old_settings;

/**
* @brief TD terminal settings
*/
extern struct termios new_settings;

/**
* Initialization Functions
*
Expand Down Expand Up @@ -228,30 +214,6 @@ void td_drawTextHorizontal(int x, int y, const char *str, int fgColor, int bgCol
*/
void td_drawTextVertical(int x, int y, const char *str, int fgColor, int bgColor);

#ifdef __cplusplus
}
#endif


/**
* Helper Functions
*
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief An unbuffered character input function to remove the need
* to press enter to input a character
*
* @param max_wait_time the amount of time in milliseconds to wait for input, use zero if you dont want to wait
*
* @warning Linux only!!!
* @return returns the pressed character, or NULL if there is no pressed character or there is an error
*/
char getch(unsigned int max_wait_time);

#ifdef __cplusplus
}
#endif

0 comments on commit e292c07

Please sign in to comment.