Introduction
Introduction Statistics Contact Development Disclaimer Help
towards dynamic screen management - gramscii - A simple editor for ASCII box-an…
Log
Files
Refs
Tags
README
LICENSE
---
commit 0adbc2a776c36b736bb5acb7184ba559d9428bc4
parent 8f25f7b9abb68e2efbc732a69f09d795ad79433c
Author: KatolaZ <[email protected]>
Date: Fri, 26 Jul 2019 22:13:33 +0100
towards dynamic screen management
Diffstat:
M Makefile | 5 +++--
M TODO | 3 +--
M gramscii.c | 67 ++++++++++++++++++++---------…
3 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/Makefile b/Makefile
@@ -17,8 +17,9 @@ options:
@echo "-+-+-+-+-+-+-+-+-+-+-"
-gramscii: ${INC}
-
+gramscii: ${SRC} ${INC}
+ $(CC) $(CFLAGS) -o gramscii ${SRC}
+
clean:
@echo cleaning
@rm -f $(SRC:.c=)
diff --git a/TODO b/TODO
@@ -1,5 +1,5 @@
+ optimize redraws (redraw only the modified rectangle)
-- change screen management (i.e., dynamic array of lines)
++ change screen management (i.e., dynamic array of lines)
- add screen geometry option (-g 25x80?)
- read file at point
- read output of command (!)
@@ -48,4 +48,3 @@
* set different line styles (done for hl, vl, corner)
* add status bar
* implement box
-
diff --git a/gramscii.c b/gramscii.c
@@ -33,6 +33,13 @@
#include "arg.h"
+typedef struct{
+ int sz;
+ int lst;
+ char *s;
+} line_t;
+
+
#define MOVE 0x00
#define BOX 0x01
#define ARROW 0x02
@@ -71,9 +78,10 @@
#define MIN(x,y) (x) < (y) ? (x) : (y)
#define MAX(x,y) (x) > (y) ? (x) : (y)
-/** #define DEBUG 1 **/
+#define DEBUG 1
-char **screen;
+line_t *screen;
+int num_lines;
int WIDTH, HEIGHT;
int state;
@@ -113,7 +121,7 @@ struct termios t1, t2, t3;
void dump_lines(){
int i;
for (i=0; i<HEIGHT; i++){
- printf("%s\n", screen[i]);
+ printf("%s\n", screen[i].s);
}
}
@@ -179,7 +187,7 @@ void status_bar(){
else
printf(" *%s*", fname );
#ifdef DEBUG
- printf(" '%d' ", screen[y][x]);
+ printf(" '%d' ", screen[y].s[x]);
#endif
printf("\033[0m");
fflush(stdout);
@@ -232,13 +240,24 @@ void show_cursor(){
fflush(stdout);
}
-void set_cur(char c){
- screen[y][x] = c;
-}
-void set_xy(int x, int y, char c){
+void set_xy(int _x, int _y, char c){
/* FIXME: check if x and y are valid!!!! */
- screen[y][x] = c;
+ if (screen[_y].sz < _x + 2){
+ screen[_y].sz = (_x +2) * 2;
+ screen[_y].s = realloc(screen[_y].s, screen[_y].sz * sizeof(ch…
+ }
+ while (screen[_y].lst<_x){
+ screen[_y].s[screen[_y].lst] = BG;
+ screen[_y].lst += 1;
+ }
+ screen[_y].s[_x] = c;
+ if (_x == screen[_y].lst)
+ screen[_y].s[_x+1] = '\0';
+}
+
+void set_cur(char c){
+ set_xy(x, y, c);
}
void draw_xy(int x, int y, char c){
@@ -254,7 +273,7 @@ void update_current(){
if (silent)
return;
printf("\033[%d'%df",y+1,x+1);
- putchar(screen[y][x]);
+ putchar(screen[y].s[x]);
fflush(stdout);
}
@@ -282,7 +301,7 @@ void erase_box(int x1, int y1, char c){
void erase_screen(){
int i;
for(i=0;i<HEIGHT; i++)
- erase_line(screen[i]);
+ erase_line(screen[i].s);
}
void check_bound(){
@@ -311,7 +330,7 @@ void redraw(){
return;
printf("\033[2J\033[1;1H");
for (i=0;i<HEIGHT;i++){
- fprintf(stdout,"%s\n",screen[i]);
+ fprintf(stdout,"%s\n",screen[i].s);
}
status_bar();
show_cursor();
@@ -774,7 +793,7 @@ void write_file(FILE *fc){
return;
}
for (i=0; i<HEIGHT; i++){
- fprintf(fout, "%s\n", screen[i]);
+ fprintf(fout, "%s\n", screen[i].s);
}
fclose(fout);
modified = 0;
@@ -800,10 +819,10 @@ void load_file(FILE *fc){
get_string(fc, "Load file: ", newfname, 255);
if ((fin=fopen(newfname, "r")) != NULL){
i = 0;
- while((fgets(screen[i], WIDTH+2, fin)) != NULL && i<HEIGHT)
- screen[i++][WIDTH-1]='\0';
+ while((fgets(screen[i].s, WIDTH+2, fin)) != NULL && i<HEIGHT)
+ screen[i++].s[WIDTH-1]='\0';
for(;i<HEIGHT; i++){
- erase_line(screen[i]);
+ erase_line(screen[i].s);
}
fclose(fin);
}
@@ -872,24 +891,26 @@ void init_screen(){
WIDTH=80;
HEIGHT=24;
}
- screen = malloc(HEIGHT * sizeof(char *));
+ screen = malloc(HEIGHT * sizeof(line_t));
+ num_lines = HEIGHT;
if (screen == NULL){
perror("allocating screen");
exit(1);
}
for (i=0; i<HEIGHT; i++){
- screen[i] = malloc((WIDTH+1) * sizeof(char));
- if (screen[i] == NULL){
- perror("allocating screen[i]");
+ screen[i].sz = WIDTH+1;
+ screen[i].s = malloc((screen[i].sz) * sizeof(char));
+ if (screen[i].s == NULL){
+ perror("allocating screen[i].s");
exit(1);
}
- memset(screen[i], ' ', WIDTH * sizeof(char));
- screen[i][WIDTH]='\0';
+ memset(screen[i].s, BG, screen[i].sz);
+ screen[i].lst = WIDTH;
+ screen[i].s[screen[i].lst+1]='\0';
}
reset_styles();
}
-
void init(){
signal(SIGHUP, cleanup);
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.