Based on Terminal lib from Simon Ford, some adds
Fork of TerminalPlus by
Diff: Terminal.cpp
- Revision:
- 6:f8c90e147000
- Parent:
- 5:d045e3561533
- Child:
- 7:80096ab72764
diff -r d045e3561533 -r f8c90e147000 Terminal.cpp --- a/Terminal.cpp Mon Sep 14 21:33:00 2015 +0000 +++ b/Terminal.cpp Wed Sep 16 00:08:12 2015 +0000 @@ -20,8 +20,12 @@ * THE SOFTWARE. */ + +/* +Porre il terminate in VT100 e set di caratteri cp437 +*/ + #include "Terminal.h" - #include "mbed.h" Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {} @@ -55,6 +59,45 @@ this->printf("\033[%dm", c); } +void Terminal::forgcol(int color) +{ + /*colori da 0 a 7 + [ 3 0 m setaf 0 Set foreground to color #0 - black + [ 3 1 m setaf 1 Set foreground to color #1 - red + [ 3 2 m setaf 2 Set foreground to color #2 - green + [ 3 3 m setaf 3 Set foreground to color #3 - yellow + [ 3 4 m setaf 4 Set foreground to color #4 - blue + [ 3 5 m setaf 5 Set foreground to color #5 - magenta + [ 3 6 m setaf 6 Set foreground to color #6 - cyan + [ 3 7 m setaf 7 Set foreground to color #7 - white + [ 3 9 m setaf 9 Set default color as foreground color + */ + + if ((color<0) || (color>7)) color =7; //normalizza + color=color+30; + this->printf("\033[%dm", color); +} + +void Terminal::bckgcol(int color) +{ + /*colori da 0 a 7 + [ 4 0 m setab 0 Set background to color #0 - black + [ 4 1 m setab 1 Set background to color #1 - red + [ 4 2 m setab 2 Set background to color #2 - green + [ 4 3 m setab 3 Set background to color #3 - yellow + [ 4 4 m setab 4 Set background to color #4 - blue + [ 4 5 m setab 5 Set background to color #5 - magenta + [ 4 6 m setab 6 Set background to color #6 - cyan + [ 4 7 m setab 7 Set background to color #7 - white + [ 4 9 m setaf 9 Set default color as background color + */ + + if ((color<0) || (color>7)) color =0; //normalizza + color=color+40; + this->printf("\033[%dm", color); +} + + void Terminal::background(int colour) { // Set Attribute Mode <ESC>[{n}m @@ -86,14 +129,14 @@ //this->printf("\033[%d;%dH", xx, yy); this->printf(sstr); -/* - //prosegui col pad - while ((padb>0) && (i<(screenColumn-xx-1))) { - this->printf(" "); //migliorare con stringa unica - i++; - padb--; - } -*/ + /* + //prosegui col pad + while ((padb>0) && (i<(screenColumn-xx-1))) { + this->printf(" "); //migliorare con stringa unica + i++; + padb--; + } + */ } @@ -104,7 +147,7 @@ // BLOCK=219; SE SI VORRA' USARE IL FILL switch (boxtype) { case 0: //singolo - B_H =205; + B_H =196; B_V =186; B_TL =201; B_TR =187; @@ -122,35 +165,36 @@ break; } //riga superiore - this->printf("\033[%d;%dH", x, y); - this->printf((char *) B_TL); - for(int i=x+1; i<x+w; i++) this->printf((char *) B_H); - this->printf((char *) B_TR); + formatPrintf((char *) &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); //corpo for(int i=y+1; i<y+h; i++) { - this->printf("\033[%d;%dH", x, i); - this->printf((char *) B_V); - this->printf("\033[%d;%dH", x+w, i); - this->printf((char *) B_V); + formatPrintf(&B_V,x,i); + formatPrintf(&B_V,x+w,i); } //riga inferiore - this->printf("\033[%d;%dH", x, y+h); - this->printf((char *) B_BL); - for(int i=x+1; i<x+w; i++) this->printf((char *) B_H); - this->printf((char *) B_BR); + 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); } void Terminal::banner() { - cls(); - formatPrintf("_____ Boot screen _____\n",25,1); - formatPrintf("___ Nucleo Scorda IO Test ___\n",22,2); - // formatPrintf(fA.string2char(fA.padstr("-\n",78,'-')),1,5); //azzo funziona... + cls(); + frame(0, 0, 79, 22,1); + forgcol(3); + formatPrintf("_____ Boot screen _____\n",27,1); + formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2); + forgcol(9); + formatPrintf(string2char(padstr("\n",78,char(196))),1,5); //azzo funziona... formatPrintf("Parsing \n",2,5); formatPrintf("Funzione\n",2,7); formatPrintf("Numero\n",22,7); formatPrintf("Parametro\n",42,7); - // formatPrintf(fA.string2char(fA.padstr("-\n",78,'-')),1,10); //azzo funziona... + formatPrintf(string2char(padstr("\n",78,char(196))),1,10); //azzo funziona... formatPrintf("Status \n",2,10); formatPrintf("Led 1 \n",2,12); formatPrintf("Virtual Led \n",22,12); @@ -158,9 +202,47 @@ formatPrintf("Real Out Serial\n",62,12); formatPrintf("Input string\n",2,15); formatPrintf("Result\n",42,15); - // formatPrintf(fA.string2char(fA.padstr("-\n",78,'-')),1,18); //azzo funziona... - formatPrintf("Serial Input \n",2,18); + formatPrintf(string2char(padstr("\n",78,char(196))),1,18); //azzo funziona... + formatPrintf("Serial Feedback \n",2,18); +} +void Terminal::readypos() +{ + formatPrintf("Command: > ",1,23); } -void Terminal::readypos(){ - formatPrintf("Command: > ",2,23); - } \ No newline at end of file + + +//------------------------------------------------ +string Terminal::padstr(string sttde, int maxlen, char fillchar) +{ + bool flagEOS=false; + string ret=sttde; + if (ret.size()>0) { + //se ha EOS lo tolgo + if (ret.substr(ret.size()-1,1) == "\n") { + ret=ret.substr(0,ret.size()-1); + flagEOS=true; + } + //pad + if (maxlen> ret.size()) ret.insert(ret.size(), maxlen - ret.size(), fillchar); + //se aveva EOS, lo rimetto + if (flagEOS==true) ret=addEOS(ret); + } + return ret; +} + +string Terminal::addEOS(string sttde) +{ + string ret=sttde; + if (sttde.substr(sttde.size()-1,1) != "\n") ret=sttde+"\n"; + return ret; +} + +char* Terminal::string2char(string sttde) +{ + //ora aggiunge comunque l'EOS. Decidere se parametrizzare + sttde=addEOS(sttde); + char *cstr = new char[sttde.length() + 1]; + strcpy(cstr, sttde.c_str()); + // delete [] cstr; + return cstr; +} \ No newline at end of file