Based on Terminal lib from Simon Ford, some adds

Fork of TerminalPlus by Max Scordamaglia

Committer:
MaxScorda
Date:
Fri Oct 02 00:23:07 2015 +0000
Revision:
11:38e8a2260621
Parent:
10:60b9f0462d03
Child:
12:92f65f10a510
Screen update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MaxScorda 7:80096ab72764 1 /** mbed TerminalPlus Library, for ANSI/VT200 Terminals and ecape codes
MaxScorda 7:80096ab72764 2 * Copyright (c) 2015, Max Scordamaglia , https//developer.mbed.org/users/MaxScorda/
MaxScorda 7:80096ab72764 3 * fork from Terminal Library
simon 2:85184c13476c 4 * Copyright (c) 2007-2010, sford, http://mbed.org
simon 1:96ae39e58792 5 *
simon 1:96ae39e58792 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:96ae39e58792 7 * of this software and associated documentation files (the "Software"), to deal
simon 1:96ae39e58792 8 * in the Software without restriction, including without limitation the rights
simon 1:96ae39e58792 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:96ae39e58792 10 * copies of the Software, and to permit persons to whom the Software is
simon 1:96ae39e58792 11 * furnished to do so, subject to the following conditions:
simon 1:96ae39e58792 12 *
simon 1:96ae39e58792 13 * The above copyright notice and this permission notice shall be included in
simon 1:96ae39e58792 14 * all copies or substantial portions of the Software.
simon 1:96ae39e58792 15 *
simon 1:96ae39e58792 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:96ae39e58792 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:96ae39e58792 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:96ae39e58792 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:96ae39e58792 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:96ae39e58792 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:96ae39e58792 22 * THE SOFTWARE.
simon 0:2bf27af3c759 23 */
simon 0:2bf27af3c759 24
MaxScorda 6:f8c90e147000 25
MaxScorda 6:f8c90e147000 26 /*
MaxScorda 6:f8c90e147000 27 Porre il terminate in VT100 e set di caratteri cp437
MaxScorda 6:f8c90e147000 28 */
MaxScorda 6:f8c90e147000 29
simon 0:2bf27af3c759 30 #include "Terminal.h"
simon 0:2bf27af3c759 31 #include "mbed.h"
simon 0:2bf27af3c759 32
simon 0:2bf27af3c759 33 Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {}
simon 0:2bf27af3c759 34
MaxScorda 3:e72f2addfaf8 35 void Terminal::cls()
MaxScorda 3:e72f2addfaf8 36 {
simon 0:2bf27af3c759 37 this->printf("\033[2J");
simon 0:2bf27af3c759 38 }
simon 0:2bf27af3c759 39
MaxScorda 3:e72f2addfaf8 40 void Terminal::locate(int column, int row)
MaxScorda 3:e72f2addfaf8 41 {
simon 0:2bf27af3c759 42 // Cursor Home <ESC>[{ROW};{COLUMN}H
MaxScorda 3:e72f2addfaf8 43
MaxScorda 3:e72f2addfaf8 44 // this->printf("\033[%d;%dH%c", row + 1, column + 1); //original
MaxScorda 5:d045e3561533 45 this->printf("\033[%d;%dH", row+1 , column+1 );
simon 0:2bf27af3c759 46 }
simon 0:2bf27af3c759 47
MaxScorda 3:e72f2addfaf8 48 static int rgb888tobgr111(int colour)
MaxScorda 3:e72f2addfaf8 49 {
simon 0:2bf27af3c759 50 int r = (colour >> 23) & 1;
simon 0:2bf27af3c759 51 int g = (colour >> 15) & 1;
simon 0:2bf27af3c759 52 int b = (colour >> 7) & 1;
simon 0:2bf27af3c759 53 return (b << 2) | (g << 1) | (r << 0);
simon 0:2bf27af3c759 54 }
simon 0:2bf27af3c759 55
MaxScorda 3:e72f2addfaf8 56 void Terminal::foreground(int colour)
MaxScorda 3:e72f2addfaf8 57 {
simon 0:2bf27af3c759 58 // Set Attribute Mode <ESC>[{n}m
simon 0:2bf27af3c759 59 // Foreground Colours : 30 + bgr
simon 0:2bf27af3c759 60 int c = 30 + rgb888tobgr111(colour);
simon 0:2bf27af3c759 61 this->printf("\033[%dm", c);
simon 0:2bf27af3c759 62 }
simon 0:2bf27af3c759 63
MaxScorda 6:f8c90e147000 64 void Terminal::forgcol(int color)
MaxScorda 6:f8c90e147000 65 {
MaxScorda 6:f8c90e147000 66 /*colori da 0 a 7
MaxScorda 6:f8c90e147000 67 [ 3 0 m setaf 0 Set foreground to color #0 - black
MaxScorda 6:f8c90e147000 68 [ 3 1 m setaf 1 Set foreground to color #1 - red
MaxScorda 6:f8c90e147000 69 [ 3 2 m setaf 2 Set foreground to color #2 - green
MaxScorda 6:f8c90e147000 70 [ 3 3 m setaf 3 Set foreground to color #3 - yellow
MaxScorda 6:f8c90e147000 71 [ 3 4 m setaf 4 Set foreground to color #4 - blue
MaxScorda 6:f8c90e147000 72 [ 3 5 m setaf 5 Set foreground to color #5 - magenta
MaxScorda 6:f8c90e147000 73 [ 3 6 m setaf 6 Set foreground to color #6 - cyan
MaxScorda 6:f8c90e147000 74 [ 3 7 m setaf 7 Set foreground to color #7 - white
MaxScorda 6:f8c90e147000 75 [ 3 9 m setaf 9 Set default color as foreground color
MaxScorda 6:f8c90e147000 76 */
MaxScorda 6:f8c90e147000 77
MaxScorda 6:f8c90e147000 78 if ((color<0) || (color>7)) color =7; //normalizza
MaxScorda 6:f8c90e147000 79 color=color+30;
MaxScorda 6:f8c90e147000 80 this->printf("\033[%dm", color);
MaxScorda 6:f8c90e147000 81 }
MaxScorda 6:f8c90e147000 82
MaxScorda 6:f8c90e147000 83 void Terminal::bckgcol(int color)
MaxScorda 6:f8c90e147000 84 {
MaxScorda 6:f8c90e147000 85 /*colori da 0 a 7
MaxScorda 6:f8c90e147000 86 [ 4 0 m setab 0 Set background to color #0 - black
MaxScorda 6:f8c90e147000 87 [ 4 1 m setab 1 Set background to color #1 - red
MaxScorda 6:f8c90e147000 88 [ 4 2 m setab 2 Set background to color #2 - green
MaxScorda 6:f8c90e147000 89 [ 4 3 m setab 3 Set background to color #3 - yellow
MaxScorda 6:f8c90e147000 90 [ 4 4 m setab 4 Set background to color #4 - blue
MaxScorda 6:f8c90e147000 91 [ 4 5 m setab 5 Set background to color #5 - magenta
MaxScorda 6:f8c90e147000 92 [ 4 6 m setab 6 Set background to color #6 - cyan
MaxScorda 6:f8c90e147000 93 [ 4 7 m setab 7 Set background to color #7 - white
MaxScorda 6:f8c90e147000 94 [ 4 9 m setaf 9 Set default color as background color
MaxScorda 6:f8c90e147000 95 */
MaxScorda 6:f8c90e147000 96
MaxScorda 6:f8c90e147000 97 if ((color<0) || (color>7)) color =0; //normalizza
MaxScorda 6:f8c90e147000 98 color=color+40;
MaxScorda 6:f8c90e147000 99 this->printf("\033[%dm", color);
MaxScorda 6:f8c90e147000 100 }
MaxScorda 6:f8c90e147000 101
MaxScorda 6:f8c90e147000 102
MaxScorda 3:e72f2addfaf8 103 void Terminal::background(int colour)
MaxScorda 3:e72f2addfaf8 104 {
simon 0:2bf27af3c759 105 // Set Attribute Mode <ESC>[{n}m
simon 0:2bf27af3c759 106 // Background Colours : 40 + bgr
simon 0:2bf27af3c759 107 int c = 40 + rgb888tobgr111(colour);
simon 0:2bf27af3c759 108 this->printf("\033[%dm", c);
simon 0:2bf27af3c759 109 }
MaxScorda 3:e72f2addfaf8 110
MaxScorda 5:d045e3561533 111 void Terminal::reset()
MaxScorda 5:d045e3561533 112 {
MaxScorda 5:d045e3561533 113 // Reset Screen
MaxScorda 5:d045e3561533 114 this->printf("\033c");
MaxScorda 5:d045e3561533 115 }
MaxScorda 5:d045e3561533 116
MaxScorda 5:d045e3561533 117 void Terminal::eraseline()
MaxScorda 5:d045e3561533 118 {
MaxScorda 7:80096ab72764 119 // Erase full line, cursor save
MaxScorda 5:d045e3561533 120 this->printf("\033[2K");
MaxScorda 5:d045e3561533 121 }
MaxScorda 5:d045e3561533 122
MaxScorda 7:80096ab72764 123 void Terminal::resetattrib()
MaxScorda 7:80096ab72764 124 {
MaxScorda 7:80096ab72764 125 // reset attrib
MaxScorda 7:80096ab72764 126 this->printf("\033[0m");
MaxScorda 7:80096ab72764 127 }
MaxScorda 5:d045e3561533 128
MaxScorda 7:80096ab72764 129 void Terminal::bold()
MaxScorda 7:80096ab72764 130 {
MaxScorda 7:80096ab72764 131 // font bold
MaxScorda 7:80096ab72764 132 this->printf("\033[1m");
MaxScorda 7:80096ab72764 133 }
MaxScorda 7:80096ab72764 134
MaxScorda 7:80096ab72764 135 void Terminal::underscore()
MaxScorda 7:80096ab72764 136 {
MaxScorda 7:80096ab72764 137 // underscore
MaxScorda 7:80096ab72764 138 this->printf("\033[4m");
MaxScorda 7:80096ab72764 139 }
MaxScorda 7:80096ab72764 140
MaxScorda 7:80096ab72764 141 void Terminal::blink()
MaxScorda 7:80096ab72764 142 {
MaxScorda 7:80096ab72764 143 // font blink
MaxScorda 7:80096ab72764 144 this->printf("\033[5m");
MaxScorda 7:80096ab72764 145 }
MaxScorda 7:80096ab72764 146
MaxScorda 7:80096ab72764 147 void Terminal::reverse()
MaxScorda 7:80096ab72764 148 {
MaxScorda 7:80096ab72764 149 // font reverse
MaxScorda 7:80096ab72764 150 this->printf("\033[7m");
MaxScorda 7:80096ab72764 151 }
MaxScorda 5:d045e3561533 152 //*************************************
MaxScorda 8:e3c6d6322506 153 void Terminal::formatPrintf(char sstr[], int xx, int yy, int padb, bool boldf )
MaxScorda 5:d045e3561533 154 {
MaxScorda 7:80096ab72764 155 int i=0; //mettere lungo come stringa
MaxScorda 7:80096ab72764 156 //string tempstr=string(sstr);
MaxScorda 7:80096ab72764 157 int screenColumn=78; //per ora lo forziamo
MaxScorda 5:d045e3561533 158
MaxScorda 7:80096ab72764 159 locate(xx, yy);
MaxScorda 8:e3c6d6322506 160 if (boldf==1) bold();
MaxScorda 8:e3c6d6322506 161 this->puts(sstr);
MaxScorda 7:80096ab72764 162 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
MaxScorda 7:80096ab72764 163 while ((sstr[i]!='\n') && (i<(screenColumn-xx+1))) {
MaxScorda 7:80096ab72764 164 i++;
MaxScorda 7:80096ab72764 165 }
MaxScorda 7:80096ab72764 166
MaxScorda 7:80096ab72764 167 //prosegui col pad
MaxScorda 7:80096ab72764 168 while ((padb>0) && (i<(screenColumn-xx-1))) {
MaxScorda 7:80096ab72764 169 this->printf(" "); //migliorare con stringa unica
MaxScorda 7:80096ab72764 170 i++;
MaxScorda 7:80096ab72764 171 padb--;
MaxScorda 7:80096ab72764 172 }
MaxScorda 8:e3c6d6322506 173 if (boldf==1) resetattrib();
MaxScorda 5:d045e3561533 174 }
MaxScorda 5:d045e3561533 175
MaxScorda 5:d045e3561533 176
MaxScorda 4:ee2311717b80 177 void Terminal::frame(int x, int y, int w, int h, int boxtype)
MaxScorda 3:e72f2addfaf8 178 {
MaxScorda 4:ee2311717b80 179 char B_H=0, B_V=0, B_TL=0, B_TR=0, B_BL=0, B_BR=0 ;
MaxScorda 4:ee2311717b80 180 // draw frame
MaxScorda 4:ee2311717b80 181 // BLOCK=219; SE SI VORRA' USARE IL FILL
MaxScorda 3:e72f2addfaf8 182 switch (boxtype) {
MaxScorda 3:e72f2addfaf8 183 case 0: //singolo
MaxScorda 6:f8c90e147000 184 B_H =196;
MaxScorda 4:ee2311717b80 185 B_V =186;
MaxScorda 4:ee2311717b80 186 B_TL =201;
MaxScorda 4:ee2311717b80 187 B_TR =187;
MaxScorda 4:ee2311717b80 188 B_BL= 200;
MaxScorda 4:ee2311717b80 189 B_BR =188;
MaxScorda 3:e72f2addfaf8 190 break;
MaxScorda 3:e72f2addfaf8 191
MaxScorda 3:e72f2addfaf8 192 case 1: //doppio
MaxScorda 3:e72f2addfaf8 193 B_H =205;
MaxScorda 3:e72f2addfaf8 194 B_V =186;
MaxScorda 3:e72f2addfaf8 195 B_TL =201;
MaxScorda 3:e72f2addfaf8 196 B_TR =187;
MaxScorda 3:e72f2addfaf8 197 B_BL= 200;
MaxScorda 3:e72f2addfaf8 198 B_BR =188;
MaxScorda 3:e72f2addfaf8 199 break;
MaxScorda 3:e72f2addfaf8 200 }
MaxScorda 10:60b9f0462d03 201
MaxScorda 3:e72f2addfaf8 202 //riga superiore
MaxScorda 7:80096ab72764 203 formatPrintf(createStr(B_TL) ,x,y);
MaxScorda 7:80096ab72764 204 formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y);
MaxScorda 6:f8c90e147000 205 //for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y);
MaxScorda 7:80096ab72764 206 formatPrintf(createStr(B_TR),x+w,y);
MaxScorda 3:e72f2addfaf8 207 //corpo
MaxScorda 3:e72f2addfaf8 208 for(int i=y+1; i<y+h; i++) {
MaxScorda 7:80096ab72764 209 formatPrintf(createStr(B_V),x,i);
MaxScorda 7:80096ab72764 210 formatPrintf(createStr(B_V),x+w,i);
MaxScorda 3:e72f2addfaf8 211 }
MaxScorda 3:e72f2addfaf8 212 //riga inferiore
MaxScorda 7:80096ab72764 213 formatPrintf(createStr(B_BL),x,y+h);
MaxScorda 7:80096ab72764 214 // for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y+h);
MaxScorda 7:80096ab72764 215 formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y+h);
MaxScorda 7:80096ab72764 216 formatPrintf(createStr(B_BR),x+w,y+h);
MaxScorda 5:d045e3561533 217 }
MaxScorda 3:e72f2addfaf8 218
MaxScorda 7:80096ab72764 219 void Terminal::bannerAdv()
MaxScorda 7:80096ab72764 220 {
MaxScorda 9:82803dacf475 221 reset();
MaxScorda 7:80096ab72764 222 cls();
MaxScorda 7:80096ab72764 223 frame(0, 0, 79, 22,1);
MaxScorda 7:80096ab72764 224 forgcol(3);
MaxScorda 9:82803dacf475 225 bold();
MaxScorda 10:60b9f0462d03 226 formatPrintf("_____ Glass Project Console _____\n",22,1);
MaxScorda 7:80096ab72764 227 formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2);
MaxScorda 8:e3c6d6322506 228
MaxScorda 9:82803dacf475 229 resetattrib();
MaxScorda 8:e3c6d6322506 230 forgcol(7);
MaxScorda 10:60b9f0462d03 231 //3-4
MaxScorda 9:82803dacf475 232 formatPrintf(string2char(padstr("\n",78,char(196))),1,3,1); //top 1/2
MaxScorda 11:38e8a2260621 233 forgcol(6);
MaxScorda 10:60b9f0462d03 234 formatPrintf("Funzione \n",2,4); //p01
MaxScorda 10:60b9f0462d03 235 formatPrintf("Numero \n",32,4); //p02
MaxScorda 10:60b9f0462d03 236 formatPrintf("Parametro \n",51,4); //p03
MaxScorda 7:80096ab72764 237 //5-6
MaxScorda 11:38e8a2260621 238 formatPrintf("Pattern 0......... \n",2,6); //p11
MaxScorda 11:38e8a2260621 239 formatPrintf("Pattern 1......... \n",42,6); //p12
MaxScorda 7:80096ab72764 240 //7-8
MaxScorda 11:38e8a2260621 241 formatPrintf("Pattern 2......... \n",2,8); //p21
MaxScorda 11:38e8a2260621 242 formatPrintf("Random Act (r1o/f) \n",42,8); //p22
MaxScorda 7:80096ab72764 243 //9-10
MaxScorda 11:38e8a2260621 244 formatPrintf("Serial Real(sro/f) \n",2,10); //p31
MaxScorda 7:80096ab72764 245 //11-12
MaxScorda 11:38e8a2260621 246 formatPrintf("Note Pattern......\n",2,12,99); //p41
MaxScorda 10:60b9f0462d03 247 //13-14
MaxScorda 10:60b9f0462d03 248 formatPrintf("Input string...... \n",2,14); //p51
MaxScorda 10:60b9f0462d03 249 formatPrintf("Command Type...... \n",42,14); //p52
MaxScorda 10:60b9f0462d03 250 //15-16
MaxScorda 11:38e8a2260621 251 forgcol(7);
MaxScorda 11:38e8a2260621 252 formatPrintf("Serial Feedback \n",2,21);
MaxScorda 7:80096ab72764 253
MaxScorda 7:80096ab72764 254
MaxScorda 7:80096ab72764 255 // grigino
MaxScorda 11:38e8a2260621 256
MaxScorda 7:80096ab72764 257 formatPrintf(string2char(padstr("\n",78,char(196))),1,5); //top 3/4
MaxScorda 7:80096ab72764 258 formatPrintf(string2char(padstr("\n",78,char(196))),1,9); //top 7/8
MaxScorda 7:80096ab72764 259 formatPrintf(string2char(padstr("\n",78,char(196))),1,13); //top 11/12
MaxScorda 11:38e8a2260621 260 formatPrintf(string2char(padstr("\n",78,char(196))),1,15,1); //bottom pot
MaxScorda 11:38e8a2260621 261 formatPrintf(string2char(padstr("\n",78,char(196))),1,20); //azzo funziona...
MaxScorda 10:60b9f0462d03 262
MaxScorda 11:38e8a2260621 263 forgcol(2);
MaxScorda 11:38e8a2260621 264 formatPrintf("Pattern: da 031 a 252 - Traccia 0-2, Note 3-6, Len 1-2 \n",2,16); //help
MaxScorda 11:38e8a2260621 265 formatPrintf("Stato random: r1on-r1off \n",2,17); //help
MaxScorda 11:38e8a2260621 266 formatPrintf("Cambia Note: da n01 a n53 - Nota 0-5, Val 1-3 \n",2,18); //help
MaxScorda 11:38e8a2260621 267 forgcol(7);
MaxScorda 11:38e8a2260621 268 locate(0, 23);
MaxScorda 11:38e8a2260621 269 this->printf("Command: > ");
MaxScorda 11:38e8a2260621 270
MaxScorda 11:38e8a2260621 271 // extra da attivare forse domani
MaxScorda 11:38e8a2260621 272 // formatPrintf("Pattern \n",2,5);
MaxScorda 11:38e8a2260621 273 // formatPrintf(string2char(padstr("\n",78,char(196))),1,7); //top 5/6
MaxScorda 11:38e8a2260621 274 // formatPrintf(string2char(padstr("\n",78,char(196))),1,11); //top 9/10
MaxScorda 11:38e8a2260621 275 // formatPrintf("Serial \n",2,9);
MaxScorda 11:38e8a2260621 276 // formatPrintf("HELP \n",2,15); //help
MaxScorda 7:80096ab72764 277 }
MaxScorda 7:80096ab72764 278
MaxScorda 6:f8c90e147000 279 void Terminal::readypos()
MaxScorda 6:f8c90e147000 280 {
MaxScorda 11:38e8a2260621 281 locate(11, 23);
MaxScorda 11:38e8a2260621 282 //this->printf("Command: > ");
MaxScorda 3:e72f2addfaf8 283 }
MaxScorda 6:f8c90e147000 284
MaxScorda 6:f8c90e147000 285
MaxScorda 6:f8c90e147000 286 //------------------------------------------------
MaxScorda 6:f8c90e147000 287 string Terminal::padstr(string sttde, int maxlen, char fillchar)
MaxScorda 6:f8c90e147000 288 {
MaxScorda 6:f8c90e147000 289 bool flagEOS=false;
MaxScorda 6:f8c90e147000 290 string ret=sttde;
MaxScorda 6:f8c90e147000 291 if (ret.size()>0) {
MaxScorda 6:f8c90e147000 292 //se ha EOS lo tolgo
MaxScorda 6:f8c90e147000 293 if (ret.substr(ret.size()-1,1) == "\n") {
MaxScorda 6:f8c90e147000 294 ret=ret.substr(0,ret.size()-1);
MaxScorda 6:f8c90e147000 295 flagEOS=true;
MaxScorda 6:f8c90e147000 296 }
MaxScorda 6:f8c90e147000 297 //pad
MaxScorda 6:f8c90e147000 298 if (maxlen> ret.size()) ret.insert(ret.size(), maxlen - ret.size(), fillchar);
MaxScorda 6:f8c90e147000 299 //se aveva EOS, lo rimetto
MaxScorda 6:f8c90e147000 300 if (flagEOS==true) ret=addEOS(ret);
MaxScorda 6:f8c90e147000 301 }
MaxScorda 6:f8c90e147000 302 return ret;
MaxScorda 6:f8c90e147000 303 }
MaxScorda 6:f8c90e147000 304
MaxScorda 6:f8c90e147000 305 string Terminal::addEOS(string sttde)
MaxScorda 6:f8c90e147000 306 {
MaxScorda 6:f8c90e147000 307 string ret=sttde;
MaxScorda 6:f8c90e147000 308 if (sttde.substr(sttde.size()-1,1) != "\n") ret=sttde+"\n";
MaxScorda 6:f8c90e147000 309 return ret;
MaxScorda 6:f8c90e147000 310 }
MaxScorda 6:f8c90e147000 311
MaxScorda 6:f8c90e147000 312 char* Terminal::string2char(string sttde)
MaxScorda 6:f8c90e147000 313 {
MaxScorda 6:f8c90e147000 314 //ora aggiunge comunque l'EOS. Decidere se parametrizzare
MaxScorda 6:f8c90e147000 315 sttde=addEOS(sttde);
MaxScorda 6:f8c90e147000 316 char *cstr = new char[sttde.length() + 1];
MaxScorda 6:f8c90e147000 317 strcpy(cstr, sttde.c_str());
MaxScorda 6:f8c90e147000 318 // delete [] cstr;
MaxScorda 6:f8c90e147000 319 return cstr;
MaxScorda 7:80096ab72764 320 }
MaxScorda 7:80096ab72764 321
MaxScorda 7:80096ab72764 322 char* Terminal::createStr(char car)
MaxScorda 7:80096ab72764 323 {
MaxScorda 7:80096ab72764 324 // unico modo in cui passo un varole ascii ad una funzione aggiungendo il ritorno a capo.
MaxScorda 7:80096ab72764 325 //se si potesse evitare sarebbe meglio
MaxScorda 7:80096ab72764 326 char *str = (char *) malloc(2 * sizeof(char));
MaxScorda 7:80096ab72764 327 if(str == NULL) return NULL;
MaxScorda 7:80096ab72764 328 str[0] = car;
MaxScorda 7:80096ab72764 329 str[1] = '\0';
MaxScorda 7:80096ab72764 330 return str;
MaxScorda 6:f8c90e147000 331 }