├── Makefile ├── README.txt ├── Visicalc-Command-Structure-Chart.png ├── cursor.c ├── cursor.h ├── data.c ├── data.h ├── functions.c ├── functions.h ├── input.c ├── input.h ├── layout.c └── layout.h /Makefile: -------------------------------------------------------------------------------- 1 | cursor: cursor.o layout.o functions.o data.o 2 | gcc -o cursor cursor.o layout.o functions.o data.o -lncurses -lm 3 | 4 | layout.o: layout.c functions.c 5 | gcc -c layout.c -lncurses 6 | 7 | functions.o: functions.c functions.h 8 | gcc -c functions.c 9 | 10 | cursor.o: layout.c functions.c cursor.c cursor.h 11 | gcc -c cursor.c -lncurses 12 | 13 | data.o: data.h data.c 14 | gcc -c data.c -lncurses -lm 15 | 16 | clean: 17 | rm *.o 18 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | The original spreadsheet program VisiCalc (mostly) recreated in C from scratch! 2 | The VisiCalc manual can be found at http://toastytech.com/manuals/VisiCalc%201.1.pdf 3 | 4 | Download the Makefile, make and run for yourself! 5 | -------------------------------------------------------------------------------- /Visicalc-Command-Structure-Chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoffmoss0/VisiCalc/1d1a90444dd3f3d02971d9911e49d48e42cccf85/Visicalc-Command-Structure-Chart.png -------------------------------------------------------------------------------- /cursor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "data.h" 6 | #include "cursor.h" 7 | #include "layout.h" 8 | #include "functions.h" 9 | 10 | //These don't really need to be static, I'm just a slave to my java habits 11 | //Ok don't yell at me I just didn't feel like throwing all these values around 12 | static int col; //The column of the cursor 13 | static int row; //The row of the cursor 14 | static int x; //The on-screen position of the actual cursor 15 | static int y; // ----------------------------------------- 16 | static int max_x; //bounds of the screen 17 | static int max_y; //(how big it is) 18 | static int corner_row; //the row and column in the upper left corner 19 | static int corner_col; //--------------------------------------- 20 | static int entry_size; 21 | static cell (*table)[64]; 22 | 23 | ///Called by the driver file, sets up the layout and sets all various x and y values 24 | ///Calls input(), which handles all user input 25 | void start() { 26 | draw_size = 8; 27 | draw_screenyx(); 28 | //will need to be fixed once I implement column sizing 29 | draw_axes(1, 1); 30 | corner_row = 1; 31 | corner_col = 1; 32 | //draw_screenyx(); 33 | refresh(); 34 | //char cursor[9] = " "; 35 | //draw_axes(20, 20); 36 | 37 | move(4, 3); 38 | printw(" "); 39 | move(4, 3); 40 | x = 3; 41 | y = 4; 42 | row = 1; 43 | col = 1; 44 | getmaxyx(curscr, max_y, max_x); 45 | entry_size = max_x - 12; 46 | refresh(); 47 | cell *tab = init_table(); 48 | table = (cell (*)[64])tab; 49 | input(); 50 | 51 | char ch = getch(); 52 | endwin(); 53 | } 54 | 55 | 56 | void set_icon(int row, int col) { 57 | color_on(); 58 | char *letters = to_char(col - 1); 59 | //printw("%u", strlen(letters)); 60 | move(0, 1); 61 | if (col < 27) { 62 | printw(" "); 63 | } 64 | printw("%s", letters); 65 | free(letters); 66 | printw("%d ", row); //padding to make sure any other numbers are overwritten 67 | 68 | //TODO add the indicator for (label), (value), etc 69 | move(0, 6); 70 | if (table[row-1][col-1] != NULL) { 71 | printw("<"); 72 | if (table[row-1][col-1]->contents < 2) 73 | printw("V"); 74 | else 75 | printw("L"); 76 | printw(">"); 77 | } else { 78 | printw(" "); 79 | } 80 | //TODO replace this with the data entry for the next thing, clear the rest 81 | char *inside = get_raw(row, col, entry_size, &table); 82 | if (inside == NULL) { 83 | for (int i = 9; i < max_x; i++) { 84 | printw(" "); 85 | } 86 | } else { 87 | printw(" %s", inside); 88 | for (int i = 11; i < max_x; i++) { 89 | printw(" "); 90 | } 91 | } 92 | 93 | color_off(); 94 | } 95 | 96 | 97 | ///Gets entry when anything besides the arrow keys are typed 98 | ///Handles screen sizing automatically, will not scroll past size of screen 99 | void entry(int ch) { 100 | 101 | char *entry_line = calloc(entry_size, sizeof(char)); 102 | 103 | color_on(); 104 | int typed = 0; 105 | move(2, 0); 106 | if (ch >= 32 && ch <= 122) { 107 | color_off(); 108 | for (int i = 1; i < max_x; i++) { 109 | printw(" "); 110 | } 111 | move(2, 1); 112 | printw("%c", ch); 113 | entry_line[typed] = ch; 114 | typed++; 115 | } 116 | 117 | while((ch = getch()) != 10) { 118 | if (ch == 127) { 119 | if (typed > 0) { 120 | move(2, typed); 121 | printw(" "); 122 | move(2, typed); 123 | entry_line[typed] = 0; 124 | typed--; 125 | } 126 | } else if (ch == 27){ 127 | free(entry_line); 128 | return; 129 | } else { 130 | if (typed < entry_size && ch <= 122 && ch >= 32) { 131 | printw("%c", ch); 132 | entry_line[typed] = ch; 133 | typed++; 134 | } else if (ch == '\033') { 135 | //flushinp(); 136 | getch(); //clearing out arrow key notation 137 | getch(); 138 | } 139 | } 140 | } 141 | 142 | move(2, 0); 143 | for (int i = 0; i < max_x; i++) { 144 | printw(" "); 145 | } 146 | set_icon(row, col); 147 | 148 | move(y, x); 149 | set_data(entry_line, row, col, table); 150 | fill_in(y, x, row, col); 151 | set_icon(row, col); 152 | free(entry_line); 153 | } 154 | 155 | ///Draw the cursor at the new location with the data inside 156 | void fill_in(int y, int x, int row, int col) { 157 | color_on(); 158 | move(y, x); 159 | char *print = print_data(row, col, draw_size, table); 160 | printw("%s", print); 161 | free(print); 162 | move(y, x); 163 | } 164 | 165 | 166 | //Rewrite the cell that just had the cursor whlie keeping the data 167 | void refill(int y, int x, int row, int col) { 168 | color_off(); 169 | move(y, x); 170 | char *print = print_data(row, col, draw_size, table); 171 | printw("%s", print); 172 | free(print); 173 | move(y, x); 174 | color_on(); 175 | } 176 | 177 | void input() { 178 | int ch; 179 | while((ch = getch()) != '\0') { 180 | if (ch == '\033') { 181 | getch(); //Arrow keys are in the form of [[A, this clears out the second bracket 182 | int real = getch(); 183 | if (real == 'A') { //up 184 | if (row > 1 && row > corner_row) { 185 | refill(y, x, row, col); 186 | move(y-1, x); 187 | row--; 188 | y--; 189 | //printw(" "); 190 | fill_in(y, x, row, col); 191 | set_icon(row, col); //This should have been a one time thing 192 | move(y, x); //But it broke everything when I tried it 193 | } else if(corner_row > 1) { 194 | draw_axes(corner_row-1, corner_col); 195 | draw_cells(corner_row-1, corner_col, max_y, max_x, draw_size, &table); 196 | row--; 197 | corner_row--; 198 | set_icon(row, col); 199 | move(y, x); 200 | fill_in(y, x, row, col); 201 | } 202 | } else if(real == 'B') { //down 203 | if (y < max_y - 1) { 204 | refill(y, x, row, col); 205 | move(y+1, x); 206 | row++; 207 | y++; 208 | fill_in(y, x, row, col); 209 | set_icon(row, col); 210 | move(y, x); 211 | } else if (row < 254) { 212 | draw_axes(corner_row + 1, corner_col); 213 | draw_cells(corner_row + 1, corner_col, max_y, max_x, draw_size, &table); 214 | row++; 215 | corner_row++; 216 | fill_in(y, x, row, col); 217 | set_icon(row, col); 218 | move(y, x); 219 | //TODO 220 | } 221 | } else if (real == 'C') { //right 222 | if (x <= max_x - (2 * draw_size)) { 223 | refill(y, x, row, col); 224 | move(y, x+draw_size); 225 | col++; 226 | x+=draw_size; 227 | fill_in(y, x, row, col); 228 | set_icon(row, col); 229 | move(y, x); 230 | } else if(col < 63) { 231 | draw_axes(corner_row, corner_col + 1); 232 | draw_cells(corner_row, corner_col + 1, max_y, max_x, draw_size, &table); 233 | col++; 234 | corner_col++; 235 | set_icon(row, col); 236 | fill_in(y, x, row, col); 237 | move(y, x); 238 | } 239 | } else if (real == 'D') { //left 240 | if (x >= draw_size) { 241 | refill(y, x, row, col); 242 | move(y, x-draw_size); 243 | //printw(" "); 244 | col--; 245 | x-=draw_size; 246 | set_icon(row, col); 247 | fill_in(y, x, row, col); 248 | move(y, x); 249 | } else if(col > 1) { 250 | draw_axes(corner_row, corner_col - 1); 251 | draw_cells(corner_row, corner_col - 1, max_y, max_x, draw_size, &table); 252 | col--; 253 | corner_col--; 254 | set_icon(row, col); 255 | fill_in(y, x, row, col); 256 | move(y, x); 257 | } 258 | } 259 | } else if (ch <= 127) { 260 | entry(ch); 261 | //refill(y, x); 262 | } 263 | } 264 | } 265 | 266 | void main(char *argc, char **argv) { 267 | initscr(); 268 | refresh(); 269 | setup(); 270 | start(); 271 | } 272 | -------------------------------------------------------------------------------- /cursor.h: -------------------------------------------------------------------------------- 1 | #ifndef CURSOR 2 | #define CURSOR 3 | 4 | void start(); 5 | 6 | void fill_in(int y, int x, int row, int col); 7 | 8 | void refill(int y, int x, int row, int col); 9 | 10 | void input(); 11 | 12 | void entry(int ch); 13 | 14 | void set_icon(int row, int col); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /data.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "data.h" 8 | 9 | //static cell **table; 10 | static int count = 0; 11 | 12 | struct cell_s **init_table() { 13 | struct cell_s **tab = (struct cell_s **)calloc(256 * 64, sizeof(struct cell_s *)); 14 | //table = tab; 15 | return tab; 16 | } 17 | 18 | //should this be void? idk 19 | void set_data(char *input, int row, int col, cell table[256][64]) { 20 | if (input[0] == 34) { 21 | //Label 22 | //TODO make sure quotes are consistent 23 | if (table[row-1][col-1] == NULL) { 24 | cell new = (cell)malloc(sizeof(struct cell_s)); 25 | new->row = row; 26 | new->col = col; 27 | new->contents = 2; 28 | new->data = (data)malloc(sizeof(union data_s)); 29 | new->data->label = (char *)malloc(strlen(input)); 30 | strcpy(new->data->label, input+1); 31 | if(new->data->label[strlen(input)-2] == '"') 32 | new->data->label[strlen(input)-2] = '\0'; 33 | table[row-1][col-1] = new; 34 | } else { 35 | cell new = table[row-1][col-1]; 36 | if (new->contents == 2) { 37 | new->data->label = (char *)realloc(new->data->label, strlen(input)); 38 | } else { 39 | new->data->label = (char *)malloc(strlen(input)); 40 | new->contents = 2; 41 | } 42 | strcpy(new->data->label, input+1); 43 | if(new->data->label[strlen(input)-2] == '"') { 44 | new->data->label[strlen(input)-2] = '\0'; 45 | } 46 | } 47 | } else if (strchr(input, '.')) { 48 | //double 49 | double num = strtod(input, NULL); 50 | if (num == 0.0 && input[0] != '0') 51 | return; //Failed, didn't parse 0 52 | if (table[row-1][col-1] == NULL) { 53 | cell new = (cell)malloc(sizeof(struct cell_s)); 54 | new->row = row; 55 | new->col = col; 56 | new->contents = 1; 57 | new->data = (data)malloc(sizeof(union data_s)); 58 | new->data->value = num; 59 | table[row-1][col-1] = new; 60 | } else { 61 | cell new = table[row-1][col-1]; 62 | if (new->contents == 2) { 63 | free(new->data->label); 64 | } 65 | new->contents = 1; 66 | new->data->value = num; 67 | } 68 | } else { 69 | //long int (must be all numbers, no other symbols) 70 | long int num; 71 | if (input[0] >= 48 && input[0] <= 57) { 72 | num = strtol(input, NULL, 10); 73 | } else { 74 | return; 75 | } 76 | if (table[row-1][col-1] == NULL) { 77 | cell new = (cell)malloc(sizeof(struct cell_s)); 78 | new->row = row; 79 | new->col = col; 80 | new->contents = 0; 81 | new->data = (data)malloc(sizeof(union data_s)); 82 | new->data->num = num; 83 | table[row-1][col-1] = new; 84 | } else { 85 | cell new = table[row-1][col-1]; 86 | if (new->contents == 2) 87 | free(new->data->label); 88 | new->data->num = num; 89 | new->contents = 0; 90 | } 91 | } 92 | //Functions to come later, I have no idea how that will work 93 | } 94 | 95 | 96 | ///return the format in which the data of a cell at row and col should be displayed 97 | char *print_data(int row, int col, int draw_size, cell table[256][64]) { 98 | char *out = (char *)calloc(draw_size + 1, sizeof(char)); 99 | 100 | cell print = table[row-1][col-1]; 101 | 102 | if (print == NULL) { 103 | //Cell does not have any data 104 | for (int i = 0; i < draw_size; i++) { 105 | strcat(out, " "); 106 | } 107 | return out; 108 | } else if (print->contents == 2) { 109 | //string guaranteed to be in correct form with quotes on either side 110 | char make[draw_size+1]; 111 | strncat(make, print->data->label, draw_size); 112 | for (int i = 0; i < draw_size - strlen(make); i++) { 113 | strcat(out, " "); 114 | } 115 | strcat(out, make); 116 | return out; 117 | } else if(print->contents == 1) { 118 | //gotta display ">>>" if the number is too large, cut off decimal places 119 | if (print->data->value >= pow(10, draw_size)) { 120 | for (int i = 0; i < draw_size-3; i++) { 121 | strcat(out, " "); 122 | } 123 | strcat(out, ">>>"); 124 | return out; 125 | } 126 | else { 127 | char make[draw_size + 1]; 128 | snprintf(make, draw_size+1, "%'.15f", print->data->value); 129 | //remove trailing zeros 130 | int i = strlen(make)-1; 131 | while (i >= 0 && make[i] == '0') { 132 | make[i] = '\0'; //no harm in filling it up with null bytes 133 | i--; 134 | } 135 | //pad out to fit the length of the columns 136 | for (int i = 0; i < draw_size - strlen(make); i++) { 137 | strcat(out, " "); 138 | } 139 | strcat(out, make); 140 | return out; 141 | } 142 | } else if(print->contents == 0) { 143 | //int 144 | if(print->data->num > pow(10, draw_size)) { 145 | //too big to display 146 | for (int i = 0; i < draw_size-3; i++) { 147 | strcat(out, " "); 148 | } 149 | strcat(out, ">>>"); 150 | return out; 151 | } else { 152 | char create[draw_size+1]; 153 | snprintf(create, draw_size + 1, "%ld", print->data->num); 154 | for (int i = strlen(create); i < draw_size; i++) { 155 | strcat(out, " "); 156 | } 157 | strcat(out, create); 158 | return out; 159 | } 160 | } 161 | return NULL; 162 | } 163 | 164 | 165 | char *get_raw(int row, int col, int entry_size, cell (**table)[64]) { 166 | char *out = (char *)calloc(entry_size + 1, sizeof(char)); 167 | cell from = (*table)[row-1][col-1]; 168 | if (from == NULL) { 169 | return NULL; 170 | } 171 | 172 | if (from->contents == 2) { 173 | //label 174 | strncat(out, from->data->label, entry_size); 175 | return out; 176 | } else if (from->contents == 1) { 177 | 178 | snprintf(out, entry_size, "%'.15f", from->data->value); 179 | //get rid of trailing zeros 180 | int i = strlen(out) - 1; 181 | while(i >= 0 && out[i] == '0') { 182 | out[i] = '\0'; 183 | } 184 | return out; 185 | } else { 186 | //int 187 | snprintf(out, entry_size, "%ld", from->data->num); 188 | return out; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /data.h: -------------------------------------------------------------------------------- 1 | #ifndef DATA 2 | #define DATA 3 | 4 | struct cell_s { 5 | int row; 6 | int col; 7 | //do I really need this for the simplest version? 8 | int contents; //based on the number, contains an int, double, or string (label) 9 | union data_s *data; 10 | }; 11 | 12 | union data_s { 13 | long int num; 14 | double value; 15 | char *label; 16 | //maybe function pointer later? 17 | }; 18 | 19 | typedef struct cell_s *cell; 20 | 21 | typedef union data_s *data; 22 | 23 | 24 | cell *init_table(); 25 | 26 | void set_data(char *input, int row, int col, cell table[256][64]); 27 | 28 | char *print_data(int row, int col, int draw_size, cell table[256][64]); 29 | 30 | char *get_raw(int row, int col, int entry_size, cell (**table)[64]); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "functions.h" 7 | 8 | //I can't take credit for the implementation of this, 9 | //credit to caf on StackOverflow for this elagant solution 10 | int to_num(char c) { 11 | int n = -1; 12 | 13 | static const char *const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 14 | char *p = strchr(alphabet, toupper((unsigned char) c)); 15 | 16 | if (p != NULL) { 17 | n = p - alphabet; 18 | } 19 | return n; 20 | } 21 | 22 | char *to_char(int i) { 23 | char *out = calloc(3, sizeof(char)); 24 | static const char *const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 25 | if (i < 26) { 26 | strncpy(out, alphabet + i, 1); 27 | out[1] = '\0'; 28 | } else { 29 | int tens = (i / 26) - 1; 30 | strncpy(out, alphabet + tens, 1); 31 | int ones = i % 26; 32 | strncat(out, alphabet + ones, 1); 33 | } 34 | out[2] = '\0'; 35 | return out; 36 | } 37 | -------------------------------------------------------------------------------- /functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONS 2 | #define FuNCTIONS 3 | 4 | int to_num(char c); 5 | 6 | char *to_char(int i); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /input.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "input.h" 4 | #include "data.h" 5 | #include "layout.h" 6 | 7 | static int x_pos = 0; 8 | static int y_pos = 0; 9 | static int x_real = 4; 10 | static int y_real = 4; 11 | 12 | 13 | 14 | 15 | void draw_input() { 16 | 17 | } 18 | 19 | 20 | void parse_input() { 21 | char ch; 22 | int max_x, max_y; 23 | getmaxyx(curscr, max_y, max_x); 24 | while ((ch = getch()) != '\n') { 25 | if (ch == '\033') { 26 | getch(); 27 | int real = getch(); 28 | if (real == 'A') { //up 29 | if (y_pos == y_start) { 30 | //shift 31 | if (y_start != 0) 32 | draw_axes(y_start - 1, x); 33 | //draw cursor 34 | move(x_real, y_real); 35 | attron(COLOR_PAIR(2)); 36 | 37 | } else { 38 | attroff(COLOR_PAIR(2)); 39 | for (int i = 0; i < draw_size; i++) { 40 | printw(" "); 41 | } 42 | move(x_real, y_real) 43 | } 44 | } else if (real == 'B') { //down 45 | if (y_pos - y_start + 4 >= max_y) { 46 | //shift 47 | } else { 48 | 49 | } 50 | } else if (real == 'C') { //right 51 | if ( ((x_pos - x_start) * draw_size) + 3 ) { 52 | //shift 53 | } else { 54 | 55 | } 56 | } else if (real == 'D') { //left 57 | if (x_pos == x_start) { 58 | //shift 59 | } else { 60 | 61 | } 62 | } 63 | } else { 64 | 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /input.h: -------------------------------------------------------------------------------- 1 | #ifndef INPUT 2 | #define INPUT 3 | 4 | void draw_input(); 5 | 6 | void parse_input(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /layout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "layout.h" 6 | #include "functions.h" 7 | #include "data.h" 8 | 9 | 10 | static int draw_size; 11 | static int x_start; 12 | static int y_start; 13 | 14 | 15 | void color_on() { 16 | attroff(COLOR_PAIR(1)); 17 | attron(COLOR_PAIR(2)); 18 | } 19 | 20 | void color_off() { 21 | attroff(COLOR_PAIR(2)); 22 | attron(COLOR_PAIR(1)); 23 | } 24 | ///Draw the axes, with y as the starting row and x as the starting column (converted to letters) 25 | ///This function is a goddamn mess and I should never touch it once it works 26 | void draw_axes(int yn, int xn) { 27 | xn--; //don't 28 | yn--; //ask 29 | x_start = xn; 30 | y_start = yn; 31 | int max_x, max_y; 32 | getmaxyx(curscr, max_y, max_x); 33 | move(4, 0); 34 | int b = 4; 35 | attron(COLOR_PAIR(2)); 36 | for (int a = yn+1; a < max_y - 3 + yn; a++) { 37 | if (a >= 100) { 38 | printw("%d", a); 39 | } else if (a >= 10) { 40 | printw(" %d", a); 41 | } else { 42 | printw(" %d", a); 43 | } 44 | 45 | move(b + 1, 0); 46 | b++; 47 | } 48 | 49 | move(3, 3); 50 | 51 | int k = 0; 52 | while ( ((k+1) * draw_size) + 3 < max_x) { 53 | for (int j = 0; j < draw_size; j++) { 54 | if (k + xn < 26) { 55 | if (j != ((draw_size / 2)) ) 56 | printw(" "); 57 | else { 58 | char *letters = to_char(k + xn); 59 | printw("%s", letters); 60 | free(letters); 61 | } 62 | } else { 63 | if (j != (int) ((draw_size - 0.5) / 2)) { 64 | printw(" "); 65 | } else { 66 | char *letters = to_char(k + xn); 67 | printw("%s", letters); 68 | j++; 69 | free(letters); 70 | } 71 | } 72 | 73 | } 74 | k++; 75 | } 76 | //move(4, 4); 77 | //draw_cells(start_y, start_x); 78 | } 79 | 80 | ///Draws the data inside the cells 81 | void draw_cells(int row, int col, int max_y, int max_x, int draw_size, cell (**table)[64]) { 82 | //make sure to keep track of cursor position locally 83 | int draw = (max_x - 3) / draw_size; 84 | color_off(); 85 | for (int i = 0; i < (max_y - 4); i++) { 86 | move(4 + i, 3); 87 | for (int j = 0; j < draw; j++) { 88 | printw("%s", print_data(row+i, col+j, draw_size, *table)); 89 | //printw("AAAAAAAA"); 90 | } 91 | } 92 | } 93 | 94 | 95 | ///Initial setup for the screen, at some point I might make this work with 96 | ///the modular drawing functions. However, that day is not today 97 | int draw_screenyx() { 98 | //Do I really need these parameters? 99 | if (curscr == NULL) { 100 | fprintf(stderr, "Window has not yet been initialized\n"); 101 | return 0; 102 | } 103 | move(0, 0); 104 | start_color(); 105 | //Background: 36, 76, 122 106 | //Foreground: 143, 199, 240 107 | //init_color(COLOR_BLACK, 141, 297, 477); 108 | init_color(COLOR_BLACK, 187, 39, 141); 109 | init_color(COLOR_BLUE, 334, 627, 845); 110 | init_pair(2, COLOR_BLACK, COLOR_BLUE); //Light background 111 | init_pair(1, COLOR_BLUE, COLOR_BLACK); //Dark background 112 | attron(COLOR_PAIR(2)); 113 | 114 | printw(" A1 "); 115 | 116 | int max_x, max_y; 117 | getmaxyx(curscr, max_y, max_x); 118 | for (int x = 6; x < max_x; x++) { 119 | printw(" "); 120 | } 121 | move(1, 0); 122 | for (int x = 0; x < max_x; x++) { 123 | printw(" "); 124 | } 125 | attroff(COLOR_PAIR(2)); 126 | attron(COLOR_PAIR(1)); 127 | for (int x = 0; x < max_x; x++) { 128 | printw(" "); 129 | } 130 | attroff(COLOR_PAIR(1)); 131 | attron(COLOR_PAIR(2)); 132 | 133 | printw(" "); 134 | draw_axes(1, 1); 135 | refresh(); 136 | return 0; 137 | } 138 | 139 | void setup() { 140 | noecho(); 141 | curs_set(0); 142 | draw_size = 8; 143 | } 144 | 145 | /* 146 | int main(void) { 147 | draw_size = 8; 148 | initscr(); 149 | refresh(); 150 | noecho(); 151 | curs_set(0); 152 | draw_size = 8; 153 | 154 | //attron(COLOR_PAIR(1)); 155 | //printw("Works "); 156 | //attroff(COLOR_PAIR(1)); 157 | 158 | draw_screenyx(); 159 | refresh(); 160 | char cursor[9] = " "; 161 | draw_axes(20, 20); 162 | char ch = getch(); 163 | endwin(); 164 | return 0; 165 | } 166 | */ 167 | -------------------------------------------------------------------------------- /layout.h: -------------------------------------------------------------------------------- 1 | #include "data.h" 2 | #ifndef LAYOUT 3 | #define LAYOUT 4 | 5 | static int draw_size; 6 | 7 | int draw_screenyx(); 8 | 9 | void draw_axes(int y, int x); 10 | 11 | void draw_cells(int row, int col, int max_y, int max_x, int draw_size, cell (**table)[64]); 12 | 13 | void setup(); 14 | 15 | void color_on(); 16 | 17 | void color_off(); 18 | 19 | #endif 20 | --------------------------------------------------------------------------------