#include "term.h" void redraw(struct terminal *term) { lcd.noCursor(); lcd.clear(); lcd.home(); for (byte i = 0; i < COLS * ROWS; i++) { if (i % COLS == 0) lcd.setCursor(i % COLS, i / COLS); lcd.write(term->contents[i]); } lcd.cursor(); } void scroll_up(struct terminal *term) { for (byte i = 0; i < COLS * (ROWS - 1); i++) term->contents[i] = term->contents[i + COLS]; for (byte i = COLS * (ROWS - 1); i < COLS * ROWS; i++) term->contents[i] = ' '; redraw(term); } /** * Special character meanings are defined here. */ void write(struct terminal *term, char ch) { switch (ch) { case '\r': term->x = 0; lcd.setCursor(term->x, term->y); break; case '\n': if (++term->y >= ROWS) { term->y--; scroll_up(term); } lcd.setCursor(term->x, term->y); break; case 0x7f: if (term->x != 0) { term->x--; term->contents[term->x + term->y * COLS] = 0x00; lcd.setCursor(term->x, term->y); lcd.write(' '); lcd.setCursor(term->x, term->y); } break; default: term->contents[term->x + term->y * COLS] = ch; lcd.write(ch); if (++term->x >= COLS) { term->x = 0; if (++term->y >= ROWS) { term->y--; scroll_up(term); } lcd.setCursor(term->x, term->y); } } }