Initial code commit. Doesn't really do much now. Just commiting what code I have.
new file: nms.c
This commit is contained in:
parent
f7b2544953
commit
077cc1d1bb
59
nms.c
Normal file
59
nms.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define SPACE 040
|
||||
#define NEWLINE 012
|
||||
|
||||
int getTermSizeRows(void);
|
||||
int getTermSizeCols(void);
|
||||
void clearTermWindow(int, int);
|
||||
|
||||
int main(void) {
|
||||
int termSizeRows = getTermSizeRows();
|
||||
int termSizeCols = getTermSizeCols();
|
||||
char inputBuffer[termSizeRows * termSizeCols];
|
||||
|
||||
clearTermWindow(termSizeRows, termSizeCols);
|
||||
|
||||
// Geting input
|
||||
int c;
|
||||
while ((c = getchar()) != EOF) {
|
||||
if (isspace(c))
|
||||
putchar(c);
|
||||
else
|
||||
putchar('x');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getTermSizeRows(void) {
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
|
||||
return w.ws_row;
|
||||
}
|
||||
|
||||
int getTermSizeCols(void) {
|
||||
struct winsize w;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
|
||||
return w.ws_col;
|
||||
}
|
||||
|
||||
void clearTermWindow(int pRows, int pCols) {
|
||||
int row, col;
|
||||
|
||||
printf("rows: %i, cols: %i\n", pRows, pCols);
|
||||
// Clearing window
|
||||
for (row = 1; row <= pRows; ++row) {
|
||||
for (col = 1; col <= pCols; ++col)
|
||||
printf("\033[%i;%iH%c", row, col, SPACE);
|
||||
printf("\033[%i;%iH%c", row, col, NEWLINE);
|
||||
}
|
||||
|
||||
// Position cursor at the top
|
||||
printf("\033[%i;%iH", 1, 1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user