summaryrefslogtreecommitdiff
path: root/gramscii.c
diff options
context:
space:
mode:
Diffstat (limited to 'gramscii.c')
-rw-r--r--gramscii.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/gramscii.c b/gramscii.c
index 5e5a9b1..1223a76 100644
--- a/gramscii.c
+++ b/gramscii.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <signal.h>
#include <string.h>
+#include <sys/ioctl.h>
#define MOVE 0x00
#define BOX 0x01
@@ -27,8 +28,6 @@
#define DIR_HOR (DIR_R | DIR_L)
#define DIR_VER (DIR_D | DIR_U)
-#define WIDTH 100
-#define HEIGHT 25
#define NOFIX 0x0
#define FIX 0x1
@@ -52,7 +51,8 @@
#define MIN(x,y) (x) < (y) ? (x) : (y)
#define MAX(x,y) (x) > (y) ? (x) : (y)
-char screen[HEIGHT][WIDTH+1];
+char **screen;
+int WIDTH, HEIGHT;
int state;
int dir;
@@ -121,7 +121,7 @@ char* state_str(){
void status_bar(){
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf("%100s", " ");
+ printf("%*s", WIDTH-1, "");
printf("\033[%d;1f\033[7m", HEIGHT+1);
printf(" x:%3d y:%3d -- MODE:%4s HL:%c VL:%c CN:%c SP:%c EP:%c %10s",
x, y, state_str(), line_h, line_v, corner, mark_st, mark_end, "");
@@ -132,12 +132,12 @@ void status_bar(){
printf("\033[0m");
}
-char get_key(char *s){
+char get_key(char *msg){
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf("%100s", " ");
+ printf("%*s", WIDTH, "");
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf("%s ", s);
+ printf("%s", msg);
printf("\033[0m");
return getchar();
}
@@ -145,7 +145,7 @@ char get_key(char *s){
void get_string(char *msg, char *s, int sz){
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf("%100s", " ");
+ printf("%*s", WIDTH, "");
printf("\033[%d;1f\033[7m", HEIGHT+1);
/* We must activate echo now */
t3 = t2;
@@ -235,14 +235,6 @@ void reset_styles(){
}
-void init_screen(){
- int i;
- for(i=0; i<HEIGHT; i++){
- memset(screen[i], ' ', WIDTH);
- screen[i][WIDTH]='\0';
- }
- reset_styles();
-}
void redraw(){
int i;
@@ -738,6 +730,28 @@ vis_exit:
/*** Initialisation ***/
+void init_screen(){
+ int i;
+ struct winsize wsz;
+
+ if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz)){
+ WIDTH=wsz.ws_col;
+ HEIGHT=wsz.ws_row - 1;
+ }
+ else {
+ WIDTH=8;
+ HEIGHT=24;
+ }
+ screen = malloc(HEIGHT * sizeof(char *));
+ for (i=0; i<HEIGHT; i++){
+ screen[i] = malloc((WIDTH+1) * sizeof(char));
+ memset(screen[i], 32, WIDTH);
+ screen[WIDTH]='\0';
+ }
+ reset_styles();
+}
+
+
void init(){
signal(SIGHUP, cleanup);
@@ -751,8 +765,8 @@ void init(){
tcsetattr(0, TCSANOW, &t2);
init_screen();
- x = WIDTH/2;
- y = HEIGHT/2;
+ x = 0;
+ y = 0;
modified = 0;
fname[0] = '\0';
redraw();