summaryrefslogtreecommitdiff
path: root/gramscii.c
diff options
context:
space:
mode:
Diffstat (limited to 'gramscii.c')
-rw-r--r--gramscii.c63
1 files changed, 51 insertions, 12 deletions
diff --git a/gramscii.c b/gramscii.c
index 2cc7213..1d75b34 100644
--- a/gramscii.c
+++ b/gramscii.c
@@ -23,6 +23,8 @@
#define DIR_D 0x04
#define DIR_L 0x08
+#define DIR_HOR (DIR_R | DIR_L)
+#define DIR_VER (DIR_D | DIR_U)
#define WIDTH 100
#define HEIGHT 25
@@ -54,12 +56,20 @@ char corner;
char hlines[] = {"-~=#@._ "};
char vlines[] = {"|H#@:;i "};
char corners[] = {"+'H#@.\""};
+char st_marks[] = {"+o-|<>^v"};
+char end_marks[] = {">+o-|<^v"};
+
int hlines_sz= sizeof(hlines) -1;
int vlines_sz= sizeof(vlines) -1;
int corners_sz = sizeof(corners) -1;
-int cur_hl, cur_vl, cur_corn;
+int stmarks_sz = sizeof(st_marks) - 1;
+int endmarks_sz = sizeof(st_marks) - 1;
+
+int cur_hl, cur_vl, cur_corn, cur_start, cur_end;
char line_h;
char line_v;
+char mark_st;
+char mark_end;
struct termios t1, t2;
@@ -99,8 +109,11 @@ void init_screen(){
cur_corn = 0;
corner = corners[0];
cur_hl = cur_vl = 0;
+ cur_start = cur_end = 0;
line_h = hlines[cur_hl];
line_v = vlines[cur_vl];
+ mark_st = st_marks[cur_start];
+ mark_end = end_marks[cur_end];
}
char* state_str(){
@@ -123,8 +136,8 @@ char* state_str(){
void status_bar(){
printf("\033[%d;1f\033[7m", HEIGHT+1);
- printf(" x: %3d y: %3d -- mode: %4s hl: %c vl: %c cn: %c %10s",
- x, y, state_str(), line_h, line_v, corner, "");
+ printf(" x: %3d y: %3d -- mode: %4s hl: %c vl: %c cn: %c <: %c >: %c %10s",
+ x, y, state_str(), line_h, line_v, corner, mark_st, mark_end, "");
printf("\033[0m");
}
@@ -297,12 +310,9 @@ int progr_y(int dir){
}
-/* FIXME: fix pointer position */
-/* FIXME: set initial and final markers */
-/* FIXME: draw "corner" as first char after change of dir */
void draw_arrow(int x, int y, char *a, int a_len, int fix){
- int i, j;
+ int i, j, cur_dir;
char line;
void (*f)(int, int, char);
@@ -312,20 +322,31 @@ void draw_arrow(int x, int y, char *a, int a_len, int fix){
else
f = draw_xy;
+ f(x,y,mark_st);
if (!a_len){
- f(x,y,corner);
+ show_cursor();
return;
}
- line = (a[0] & DIR_L) || (a[0] & DIR_R) ? line_h : line_v;
- f(x,y,line);
+ cur_dir=DIR_N;
for (i=0; i<a_len; i+=2){
+ if (i>0) {
+ /* If we are switching between horizontal and vertical, put a "corner" */
+ if (((cur_dir & DIR_HOR) && (a[i] & DIR_VER)) ||
+ ((cur_dir & DIR_VER) && (a[i] & DIR_HOR))){
+ f(x,y,corner);
+ show_cursor();
+ }
+ }
for(j=0; j<a[i+1]; j++){
line = (a[i] & DIR_L) || (a[i] & DIR_R) ? line_h : line_v;
x += progr_x(a[i]);
y += progr_y(a[i]);
f(x, y, line);
}
+ /* f(x,y,mark_end);*/
+ cur_dir = a[i];
}
+ f(x,y,mark_end);
show_cursor();
}
@@ -345,7 +366,7 @@ void get_arrow(){
redraw();
step = 1;
- //draw_arrow(x,y,NOFIX);
+ draw_arrow(x,y, arrow, 0, NOFIX);
while((c=getchar())!=EOF && c != 27 && c!= 'a'){
switch(c){
case 'H': step = 5;
@@ -417,6 +438,18 @@ void toggle_vline(){
}
+void toggle_st_mark(){
+
+ cur_start = (cur_start + 1 ) % stmarks_sz;
+ mark_st = st_marks[cur_start];
+}
+
+void toggle_end_mark(){
+
+ cur_end = (cur_end+ 1 ) % endmarks_sz;
+ mark_end = end_marks[cur_end];
+}
+
void commands(){
char c;
@@ -467,9 +500,15 @@ void commands(){
case '|':
toggle_vline();
break;
- case '+':
+ case '+':
toggle_corner();
break;
+ case '<':
+ toggle_st_mark();
+ break;
+ case '>':
+ toggle_end_mark();
+ break;
case 'Q':
case 'q':
cleanup(0);