Based on Terminal lib from Simon Ford, some adds
Fork of TerminalPlus by
Diff: Terminal.cpp
- Revision:
- 7:80096ab72764
- Parent:
- 6:f8c90e147000
- Child:
- 8:e3c6d6322506
--- a/Terminal.cpp Wed Sep 16 00:08:12 2015 +0000 +++ b/Terminal.cpp Sat Sep 19 01:08:02 2015 +0000 @@ -1,4 +1,6 @@ -/* mbed Terminal Library, for ANSI/VT200 Terminals and ecape codes +/** mbed TerminalPlus Library, for ANSI/VT200 Terminals and ecape codes + * Copyright (c) 2015, Max Scordamaglia , https//developer.mbed.org/users/MaxScorda/ + * fork from Terminal Library * Copyright (c) 2007-2010, sford, http://mbed.org * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -114,29 +116,59 @@ void Terminal::eraseline() { - // Reset Screen + // Erase full line, cursor save this->printf("\033[2K"); } +void Terminal::resetattrib() +{ + // reset attrib + this->printf("\033[0m"); +} +void Terminal::bold() +{ + // font bold + this->printf("\033[1m"); +} + +void Terminal::underscore() +{ + // underscore + this->printf("\033[4m"); +} + +void Terminal::blink() +{ + // font blink + this->printf("\033[5m"); +} + +void Terminal::reverse() +{ + // font reverse + this->printf("\033[7m"); +} //************************************* void Terminal::formatPrintf(char sstr[], int xx, int yy, int padb) { - char i=0; //mettere lungo come stringa - int screenColumn=80; //per ora lo forziamo - locate(xx, yy); - - //this->printf("\033[%d;%dH", xx, yy); - this->printf(sstr); + int i=0; //mettere lungo come stringa + //string tempstr=string(sstr); + int screenColumn=78; //per ora lo forziamo - /* - //prosegui col pad - while ((padb>0) && (i<(screenColumn-xx-1))) { - this->printf(" "); //migliorare con stringa unica - i++; - padb--; - } - */ + locate(xx, yy); + this->printf(sstr); + if (yy!=23) this->printf("\033[1A"); // fa davvero cagare. Torna su col cursore per evitare il \n eccetto l'ultima riga. Servirebbe togliere il \n + while ((sstr[i]!='\n') && (i<(screenColumn-xx+1))) { + i++; + } + + //prosegui col pad + while ((padb>0) && (i<(screenColumn-xx-1))) { + this->printf(" "); //migliorare con stringa unica + i++; + padb--; + } } @@ -165,20 +197,20 @@ break; } //riga superiore - formatPrintf((char *) &B_TL ,x,y); - formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y); + formatPrintf(createStr(B_TL) ,x,y); + formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y); //for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y); - formatPrintf(&B_TR,x+w,y); + formatPrintf(createStr(B_TR),x+w,y); //corpo for(int i=y+1; i<y+h; i++) { - formatPrintf(&B_V,x,i); - formatPrintf(&B_V,x+w,i); + formatPrintf(createStr(B_V),x,i); + formatPrintf(createStr(B_V),x+w,i); } //riga inferiore - formatPrintf(&B_BL,x,y+h); - // for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y+h); - formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y+h); - formatPrintf(&B_BR,x+w,y+h); + formatPrintf(createStr(B_BL),x,y+h); + // for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y+h); + formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y+h); + formatPrintf(createStr(B_BR),x+w,y+h); } void Terminal::banner() @@ -186,6 +218,7 @@ cls(); frame(0, 0, 79, 22,1); forgcol(3); + bold(); formatPrintf("_____ Boot screen _____\n",27,1); formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2); forgcol(9); @@ -204,7 +237,50 @@ formatPrintf("Result\n",42,15); formatPrintf(string2char(padstr("\n",78,char(196))),1,18); //azzo funziona... formatPrintf("Serial Feedback \n",2,18); + resetattrib(); } + +void Terminal::bannerAdv() +{ + cls(); + frame(0, 0, 79, 22,1); + forgcol(3); + bold(); + formatPrintf("_____ Boot screen _____\n",27,1); + formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2); + forgcol(9); + + formatPrintf(string2char(padstr("\n",78,char(196))),1,3); //top 1/2 + formatPrintf("Funzione \n",2,4); + formatPrintf("Numero \n",32,4); + formatPrintf("Parametro \n",51,4); +//3-4 + formatPrintf("Status Led 1...... \n",2,6); + formatPrintf("Status Virtual Led \n",42,6); +//5-6 + formatPrintf("Other Commands.... \n",2,8); + formatPrintf("Real Out Serial... \n",42,8); +//7-8 + formatPrintf("Input string...... \n",2,10); + formatPrintf("Result............ \n",42,10); +//9-10 +//11-12 + formatPrintf(string2char(padstr("\n",78,char(196))),1,15); //bottom pot + + formatPrintf(string2char(padstr("\n",78,char(196))),1,19); //azzo funziona... + formatPrintf("Serial Feedback \n",2,20); + +// grigino + foreground(0x0f0f0f); + formatPrintf(string2char(padstr("\n",78,char(196))),1,5); //top 3/4 + formatPrintf(string2char(padstr("\n",78,char(196))),1,7); //top 5/6 + formatPrintf(string2char(padstr("\n",78,char(196))),1,9); //top 7/8 + formatPrintf(string2char(padstr("\n",78,char(196))),1,11); //top 9/10 + formatPrintf(string2char(padstr("\n",78,char(196))),1,13); //top 11/12 + + resetattrib(); +} + void Terminal::readypos() { formatPrintf("Command: > ",1,23); @@ -245,4 +321,15 @@ strcpy(cstr, sttde.c_str()); // delete [] cstr; return cstr; +} + +char* Terminal::createStr(char car) +{ + // unico modo in cui passo un varole ascii ad una funzione aggiungendo il ritorno a capo. + //se si potesse evitare sarebbe meglio + char *str = (char *) malloc(2 * sizeof(char)); + if(str == NULL) return NULL; + str[0] = car; + str[1] = '\0'; + return str; } \ No newline at end of file