|
Post by alexfish on Aug 15, 2019 21:08:56 GMT 1
last pitch of the day
have sorted the bits as regards the table:
not perfect in terms of pure logic > well normal iterators of Size would be either bang on the nail as == or + 1 for both row to column
this method is constant in the output count through direct printing
but at the end the column count is + 1
so can now say row = row and col = col minus 1
example now looks like this
row0 col 0:<img> [18] row0 col 1:[19] News row1 col 1: row2 col 1:News and announcements row3 col 1:Moderator:[20] Pjot row0 col 2:95 row0 col 3:841 row0 col 4:[21] BaCon 3.9.1 released row1 col 4:by[22] Pjot row2 col 4:Jul 28,2019 7:05:15 GMT 1 Total Rows :3 Total cols :5
BR Alex
Time for zzzzzzzzzzzzzzzzz.
|
|
|
Post by alexfish on Aug 17, 2019 11:21:23 GMT 1
Hi All
now got the table working as per the above
using a vector array like
vector <string> test1[rowmax][colmax];
example data parsed :also where now passing the html to upper case + the split function uses the ;width= size of string;
example
string str ="<TR><TD>[18]<TD><SPAN>[19] News<BR><P>News and announcements<P>Moderator: [20] Pjot <TD>95<TD>841<TD>[21] BaCon 3.9.1 released <BR>by [22] Pjot <BR><SPAN>Jul 28, 2019 7:05:15 GMT 1";
and the output
|[18] |[19] News |95 |841 |[21] BaCon 3.9.1 released | | | | | |by [22] Pjot | | |News and announcements | | |Jul 28, 2019 7:05:15 GMT 1 | | |Moderator: [20] Pjot | | | |
here have not used the span method + do have a problem of a strange thing emanating from the array the array indicates there is something in it yet has a size of 0 : contrary to the test
the cell in question is below '|[19] News' so here have a bug fix which fixes this : now looking further since the bug fix adds an extra line
my first thought is if string > than then it is split an if have two end of lines like "\n\n"
I say this since the last colum has single "\n" and that on is correct:
@ vovchik
I will clean this model up & post it on as is basis on Sunday
BR Alex
|
|
|
Post by alexfish on Aug 18, 2019 14:51:06 GMT 1
Hi Vovchik
standard table output
Take single line of Table TR TD * transform to Span Rows & Colums
Like this form index page output first
================================================================================================================================================== ** Test Table ================================================================================================================================================== | [18] | [19]News | 95 | 841 | [21]BaCon 3.9.1 released | | | News and announcements | | | by [22]Pjot | | | Moderator: [20]Pjot | | | Jul 28, 2019 7:05:15 GMT 1 | ================================================================================================================================================== Table End ==================================================================================================================================================
The code
#include <string> #include <string.h> #include <vector> #include <iostream> #include <stdlib.h> #include <sstream> using namespace std;
#define LEFT 0 #define CENTER 1 #define RIGHT 2
#define Instr(arg1,arg2) arg1.find(arg2)+1 #define Asc (int) #define Chr (char) #define Len(arg) arg.size() #define Cstring(arg1) arg1.c_str() #define Mid(arg1,...) arg1.substr(__VA_ARGS__) #define Chop(arg1) Trim(arg1," \n\t"," \n\t") #define Left(arg1,arg2) arg1.substr(0,arg2) #define Right(arg1,arg2) arg1.substr(arg1.size()-arg2) #define ModInt(arg1,arg2) arg1 % arg2 #define Mod(arg1,arg2) ((long)(arg1) % (long)(arg2)) #define Upper(arg1) transform(arg1.begin(), arg1.end(),arg1.begin(), ::toupper) #define Lower(arg1) transform(arg1.begin(), arg1.end(),arg1.begin(), ::tolower) #ifndef IsDigit #define IsDigit(a) ( ( a >= '0' ) && ( a <= '9' ) ) #endif #define NL "\n"
string Replace (string tex,string rp,string tx);
string Replace (string tex,string rp,string tx){
while( (Instr(tex,rp)) ) {
tex.replace(Instr(tex,rp)-1,Len(rp),tx) ; }
return tex; } void H_Bar(int tabs,string txt){ string str2 (tabs, '='); ; string str (tabs, ' '); cout << str2 << NL;
int t; for (t = 0 ; t <= Len(txt)-1 ; t +=1 ){ str[t]=txt[t]; } cout << str << NL;
cout << str2 << NL; }
int Std_Table(string str,string f){ int it=0; ; int s=0; ; string df; //array vector [size] must be uint uint col=0; uint row=0; uint max=0;
vector <string> result1; while (s <= str.size()){ str = Mid(str,it); it = Instr(str,f) ; it = it +3; s += it; //Trim(df df = Mid(str,0,Instr(str,f)-1) ; result1.push_back(df); }
// =============================================================================
if(Instr(str,f)) {
df = Mid(str,0,Instr(str,f)-1) ;
str= Mid(str,Instr(str,f)+3) ;
}
// =============================================================================
if(Instr(str,f)) {
df = Mid(str,0,Instr(str,f)-1) ; str= Mid(str,Instr(str,f)+3) ;
result1.push_back(df); result1.push_back(str); }
// =============================================================================
for (int t = 0 ; t <= result1.size()-1 ; t +=1 ){ row=0;
if(Instr(result1[t],"\n")){ stringstream ff(result1[t]); string tt; while(getline(ff,tt,'\n')){
if(Len(tt)){ if( Len(tt)>max){ max=Len(tt); } row++; } // neeed end } } col++; }else{ if( Len(result1[t])>max){ max=Len(result1[t]); }
col++; }
}
// =============================================================================
vector <string> test2[col][row]; col=0; row=0;
for (int t = 0 ; t <= result1.size()-1 ; t +=1 ){ row=0;
if(Instr(result1[t],"\n")){ stringstream ff(result1[t]); string tt; while(getline(ff,tt,'\n')){ // test if info
if(Len(tt)){ test2[col][row].push_back(tt); row++; } } col++; }else{ test2[col][row].push_back(result1[t]); col++; }
}
// ============================================================================= // string will be maxx + 2 to ' foo ' max=max+2;
H_Bar((max*(col-1))+col,"** Test Table") ;
// transform the table from def <vector> [cols][rows] to read [row][cols] for (int t = 0 ; t <= row-1 ; t +=1 ){ string tLine; for (int s = 0 ; s <= col-1 ; s +=1 ){ if(test2[s][t].size()) {
string wik=Mid(test2[s][t][0]); string str (max, ' '); str.append("|");
for (int b = 0 ; b <= Len(wik)-1 ; b +=1 ){ str[b+1]=wik[b]; }
tLine.append(str);
}else{ string str (max, ' '); str.append("|"); tLine.append(str); }
}
tLine=Mid(tLine,Instr(tLine,"|")-1) ; cout << tLine << "\n"; } H_Bar((max*(col-1))+col," Table End") ;
} // ============================================================================= int main(){
string str ="<TR><TD>[18]<TD><SPAN>[19]News<BR><P>News and announcements<P>Moderator: [20]Pjot <TD>95<TD>841<TD>[21]BaCon 3.9.1 released <BR>by [22]Pjot <BR><SPAN>Jul 28, 2019 7:05:15 GMT 1"; //str=Replace(str,"<BR>","\n");
str=Replace(str,"<SPAN>","\n"); str=Replace(str,"<P>","\n"); str=Replace(str,"<BR>","\n");
Std_Table(str,"<TD>");
return 0; }
BR Alex
|
|
|
Post by vovchik on Aug 18, 2019 19:18:02 GMT 1
Dear Alex,
The table looks great. I am having trouble compiling on Mint 19.2 because of some g++ changes. I tried this define "#define _GLIBCXX_USE_CXX11_ABI 0/1" at the very top, but no cigar yet...still looking for a fix.
With kind regards, vovchik
|
|
|
Post by bigbass on Aug 19, 2019 13:00:53 GMT 1
Hello Alex and vovchik
thanks for posting some demo code example for tables
g++ and clang++ will now work and compile cleanly with the latest compilers
if you change all int to uint and add one return here is a patch for ubuntu 18.04 LTS
Joe
can do it manually or call it alexpatch and place it in the same directory of your original code called alex1.cxx
patch < alexpatch
terminal output patching file alex1.cxx
--- alex1.cxx 2019-08-19 06:52:01.824693153 -0500 +++ alex2.cxx 2019-08-19 06:48:19.062066612 -0500 @@ -47,7 +47,7 @@ string str (tabs, ' '); cout << str2 << NL; -int t; +uint t; for (t = 0 ; t <= Len(txt)-1 ; t +=1 ){ str[t]=txt[t]; } @@ -56,9 +56,9 @@ cout << str2 << NL; } -int Std_Table(string str,string f){ -int it=0; ; -int s=0; ; +uint Std_Table(string str,string f){ +uint it=0; ; +uint s=0; ; string df; //array vector [size] must be uint uint col=0; @@ -101,7 +101,7 @@ // ============================================================================= -for (int t = 0 ; t <= result1.size()-1 ; t +=1 ){ +for (uint t = 0 ; t <= result1.size()-1 ; t +=1 ){ row=0; if(Instr(result1[t],"\n")){ @@ -134,7 +134,7 @@ col=0; row=0; -for (int t = 0 ; t <= result1.size()-1 ; t +=1 ){ +for (uint t = 0 ; t <= result1.size()-1 ; t +=1 ){ row=0; if(Instr(result1[t],"\n")){ @@ -163,16 +163,16 @@ H_Bar((max*(col-1))+col,"** Test Table") ; // transform the table from def <vector> [cols][rows] to read [row][cols] -for (int t = 0 ; t <= row-1 ; t +=1 ){ +for (uint t = 0 ; t <= row-1 ; t +=1 ){ string tLine; -for (int s = 0 ; s <= col-1 ; s +=1 ){ +for (uint s = 0 ; s <= col-1 ; s +=1 ){ if(test2[s][t].size()) { string wik=Mid(test2[s][t][0]); string str (max, ' '); str.append("|"); -for (int b = 0 ; b <= Len(wik)-1 ; b +=1 ){ +for (uint b = 0 ; b <= Len(wik)-1 ; b +=1 ){ str[b+1]=wik[b]; } @@ -191,7 +191,7 @@ cout << tLine << "\n"; } H_Bar((max*(col-1))+col," Table End") ; - +return 0; } // ============================================================================= int main(){
|
|
|
Post by alexfish on Aug 19, 2019 14:12:47 GMT 1
Hi @ Vovchik & Joe
thatnks for the feedback
as mention the code = 'as is' an may seg fault if change the size of the strings
there will be an updated table with bug fixes to formatted as per this <iframe> size of frame <table> rows data <><> almost there , I have a problem with this forum when it has added
News
then can have the viewing
News -1 viewing
now looking further
further to this as regards the table output
test what you see here & compare with
BR Alex
|
|
|
Post by alexfish on Aug 19, 2019 18:04:51 GMT 1
End of day Results now got the bits working without segfaults as can see below , have algo to work out the column width to fit within frame width whilst this = columns all = same : some lines can not be folded hence what you see here are the columns pushing beyond the frame width ====================================================================================================================================================== TWO ====================================================================================================================================================== col widht = 30 34:--------------------------------------------: [33] [34]Troubleshooting area 394 2,891 [36]HUG to display their widg Problems, issues, tips & tricks ets in the web browser (broad Moderator: [35]Pjot wayd) by [37]bigbass Jul 5, 2019 17:16:51 GMT 1 So now at a stage to look at the Spanning RE: each column = different width BR Alex thought a Picture may help Attachments:
|
|
|
Post by alexfish on Aug 19, 2019 18:38:09 GMT 1
Now got the minimum column width using side by side vectors
now in position to test :: tomorrow I hope
the bits above reported min col widths
TWO ============== col widht = 30 5 83 4 6 113
BR Alex
|
|
|
Post by alexfish on Aug 19, 2019 19:23:52 GMT 1
Now have the Cigar from here can now sep the column text using spaces instead of at CHAR BR Alex col widht = 30 34:--------------------------------------------: [33] [34]Troubleshooting area 394 2,891 [36]HUG to display their widg Problems, issues, tips & tricks ets in the web browser (broad Moderator: [35]Pjot wayd) by [37]bigbass Jul 5, 2019 17:16:51 GMT 1 Once The Max width to fit within the frame now get this ====================================================================================================================================================== ONE ====================================================================================================================================================== col widht = 30 28:--------------------------------------------: [18] [19]News 95 841 [21]BaCon 3.9.1 released News and announcements by [22]Pjot Moderator: [20]Pjot Jul 28, 2019 7:05:15 GMT 1 ====================================================================================================================================================== TWO ====================================================================================================================================================== col widht = 30 34:--------------------------------------------: [33] [34]Troubleshooting area 394 2,891 [36]HUG to display their widg Problems, issues, tips & tricks ets in the web browser (broad Moderator: [35]Pjot wayd) by [37]bigbass Jul 5, 2019 17:16:51 GMT 1
Attachments:
|
|
|
Post by alexfish on Aug 19, 2019 20:12:43 GMT 1
Can adjust the span to suit
Example of same
=============================================================================================== ONE =============================================================================================== col widht = 30 28:--------------------------------------------: [18] [19]News 95 841 [21]BaCon 3.9.1 released News and announcements by [22]Pjot Moderator: [20]Pjot Jul 28, 2019 7:05:15 GMT 1 ================================================================================================ TWO ================================================================================================ col widht = 30 34:--------------------------------------------: [33] [34]Troubleshooting area 394 2,891 [36]HUG to display their widg Problems, issues, tips & tricks ets in the web browser (broad Moderator: [35]Pjot wayd) by [37]bigbass Jul 5, 2019 17:16:51 GMT 1
BR Alex
|
|
|
Post by alexfish on Aug 20, 2019 11:19:02 GMT 1
Hi All
+ Vovchik & Joe
@ Not sure what the problem is as regards compiling in std-g++
however if need to compile in g++11 have put example in this code
the below = getting spans from html table
Will fill in the 'IframeTable' Later
Also added more Basic like Syntax BR Alex
// g++ -std=c++11 tabtest2.cxx -o tabtest2 // or g++ -std=c++0x tabtest2.cxx -o tabtest2 #include <string> #include <vector> #include <iostream> #include <stdlib.h> #include <sstream> #include <algorithm> #include <stdio.h> // make life Easy using namespace std;
// helper macro functions if base usr 'lang = BASIC' // avoid bacon UPPER an lower API's
// make cout easy; #define nl << "\n"; #define Print cout << #define PrintNl cout << "\n"; #define TD_LEFT 0 #define TD_CENTER 1 #define TD_RIGHT 2
#define Instr(arg1,arg2) arg1.find(arg2)+1 #define Asc (int) #define Chr (char) #define Len(arg) arg.size() #define Cstring(arg1) arg1.c_str() #define Mid(arg1,...) arg1.substr(__VA_ARGS__) #define Chop(arg1) Trim(arg1," \n\t"," \n\t") #define Left(arg1,arg2) arg1.substr(0,arg2) #define Right(arg1,arg2) arg1.substr(arg1.size()-arg2) #define ModInt(arg1,arg2) (arg1 % arg2) #define IsOdd(arg1) (arg1 % 2) #define IsEven(arg1) !(arg1 % 2) #define Mod(arg1,arg2) ((long)(arg1) % (long)(arg2)) #define Upper(arg1) transform(arg1.begin(), arg1.end(),arg1.begin(), ::toupper) #define Lower(arg1) transform(arg1.begin(), arg1.end(),arg1.begin(), ::tolower)
#ifndef IsDigit #define IsDigit(a) ( ( a >= '0' ) && ( a <= '9' ) || ',' || '.') #endif // Clear the terminal #define ClearTerm cout << "\033[2J\033[0;0f" << endl;
#define F_BLINK cout << "\e[5m" << arg1 << "\e[0m"; #define F_BOLD(arg1) cout << "\e[1m" << arg1 << "\e[0m"; #define F_ITALICS cout << "\e[3m" << arg1 << "\e[0m"; #define F_STRIKE cout << "\e[9m" << arg1 << "\e[0m"; #define F_UNDERLINE cout << "\e[4m" << arg1 << "\e[0m"; #define F_NORMAL cout << "\e[0m" << arg1 ;
#define BoldText bold(); void bold(){ Print("\e[1m");
} #define UnderLineText underlinetext(); void underlinetext(){ Print("\e[4m");
}
#define NormalText normaltext(); void normaltext(){ Print("\e[0m");
}
#define ItalicText italictext(); void italictext(){ Print("\e[3m");
} #define BlinkText blinktext(); void blinktext(){ printf("\e[5m"); }
#define StrikeText striketext(); void striketext(){ Print("\e[9m"); } // Headers ===================================================================== // replace arg2 with arg3 :: none destructive string Replace (string tex,string rp,string tx); // get count use Relace :: destructive int StringGetCount (string tex,string rp,string tx); // header bar void Hbar(int tabs,string txt);
//============================================================================== string Replace (string tex,string rp,string tx){
while( (Instr(tex,rp)) ) {
tex.replace(Instr(tex,rp)-1,Len(rp),tx) ; }
return tex; } // =============================================================================
int StringGetCount (string tex,string rp,string tx){ int ptr=0; while( (Instr(tex,rp)) ) { tex.replace(Instr(tex,rp)-1,Len(rp),tx) ; ptr++; } return ptr; } // =============================================================================
void Hbar(string txt,char ct,int width){ string str2 (width, ct); NormalText Print str2 nl BoldText Print txt nl NormalText Print str2 nl } // =============================================================================
int GetColmns(string txt,string sep){ string textc(txt); uint colums=0; return(colums= StringGetCount(textc,sep,"__t_i_d_y__")); } // =============================================================================
void GetSpans(string txt, string sep, int ptr, vector<int> & cols){ int it=0; ; int s=0; ; string df; uint ctr=0; string str=Mid (txt,Instr(txt,sep)+Len(sep)-2) ; while (ctr !=ptr){ str = Mid(str,it); df = Mid(str,0,Instr(str,sep)-1) ; it = Instr(str,sep) ; it = it +Len(sep)-2; s += it; int sl=Len(df); if(sl<10) sl=10; cols[ctr]=sl; ctr++; } }
void IframeTable(){ // todo
} // =============================================================================
// Main ======================================================================== int main(){ int s=5; ClearTerm BlinkText F_BOLD ("Testing") PrintNl Hbar(" ** Get col widths ",'-',30); string str ="<TR><TD> [18]<TD><SPAN> [19]News <BR><P>News and announcements <P>Moderator: [20]Pjot <TD>95 <TD>841 <TD> [21]BaCon 3.9.1 released <BR>by [22]Pjot <BR><SPAN>Jul 28, 2019 7:05:15 GMT 1";
uint col = GetColmns(str,"TD"); vector <int> ColSpans;
uint ptr=0; while (ptr < col) { ColSpans.push_back(1); ptr++; } cout << "colums coun = " << col << "\n";
str=Replace(str,"<SPAN>","\n"); // bugfix "/n/n" str=Replace(str,"<BR><P>","\n"); str=Replace(str,"<P>","\n"); str=Replace(str,"<BR>","\n");
int max =0; GetSpans(str,"<TD>",col, ColSpans); for (uint t = 0;t < ColSpans.size();t++){ max+=ColSpans[t]; cout << "col " << t << " width = " << ColSpans[t] << "\n"; }
string str2(max,'='); cout << str2 << "\n"; cout << "max iframe size = " << max << " spanning column 1 max width = " << ColSpans[1] << "\n";
return 0; }
// End All That ================================================================
|
|
|
Post by vovchik on Aug 20, 2019 12:09:06 GMT 1
Dear Alex,
Perfect:
Testing ------------------------------ ** Get col widths ------------------------------ colums coun = 5 col 0 width = 10 col 1 width = 59 col 2 width = 10 col 3 width = 10 col 4 width = 70 =============================================================================================================================================================== max iframe size = 159 spanning column 1 max width = 59
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 20, 2019 13:48:55 GMT 1
Hi Vovchik + At All whilst in my continued search on how to get images into a terminal found some comments that one only needs to set esc seq to accept image encode to base64 ........'EH !' well I downloaded a bash script And tested in several terminal most failed ? but hi presto mlterm works + likes of png are not written like image2sixel with a BG the script is HEREBR Alex
|
|
|
Post by alexfish on Aug 20, 2019 20:07:10 GMT 1
Hi Vovchik Have worked out the esc sequences and the descriptor from the imgcat have not tested as of yet but the inside data is definitely base64 hence should be able to do it in bacon and or c + that give a route to get inline data from html and convert to image:: hope the below shows :: where File=name=anyname=;size=0; > File= name can be any name and size can be any size but can put Len(base64 data) esc]1337;File=name=anyname=;size=0;inline=1:base64 encoded data end_esc the start esc = printf "\033]" the end+esc = printf "\a" BR Alex
|
|
|
Post by alexfish on Aug 21, 2019 4:42:21 GMT 1
Hi All have tested mlterm render image using homebrew base64 encoders decoders compiled with -std=c++11 the bits static std::string base64_encode(const std::string &in) {
std::string out;
int val=0, valb=-6; for (unsigned char c : in) { val = (val<<8) + c; valb += 8; while (valb>=0) { out.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(val>>valb)&0x3F]); valb-=6; } } if (valb>-6) out.push_back("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[((val<<8)>>(valb+8))&0x3F]); while (out.size()%4) out.push_back('='); return out; }
static std::string base64_decode(const std::string &in) {
std::string out;
std::vector<int> T(256,-1); for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i;
int val=0, valb=-8; for (unsigned char c : in) { if (T[c] == -1) break; val = (val<<6) + T[c]; valb += 6; if (valb>=0) { out.push_back(char((val>>valb)&0xFF)); valb-=8; } } return out; }
and a bit of code from main string buf = Bload("eyes.png") string rts = base64_encode(buf)
cout << "bacon-eyes\n"; cout << "\033]"; cout << "1337;File=name=eyes=;size=1;inline=1:"; cout << rts; cout << "\a\n"; this post does not have Bload : buts is in previous posts will adde the above + a ifdef BLAGH so then can compile without c++11 if normal g++; can only say this is blindingly fast; rasperry PI time results real 0m0.023s user 0m0.020s sys 0m0.000s BR Alex the picky Attachments:
|
|