2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module zsq_show_threads_tty
is aliced
;
29 // ////////////////////////////////////////////////////////////////////////// //
30 void main (string
[] args
) {
31 ChiroTimerEnabled
= true;
32 chiroParseCommonCLIArgs(args
);
34 // here, i don't have any threads at all
35 //chiroSwitchToSingleThread();
37 bool speedTest
= false;
38 bool showLast
= false;
39 bool allowThreads
= true;
40 int monthes
= 6; // last 6 monthes
42 writeln("opening message support db...");
45 if (args
.length
> 1 && args
[1] == "list") {
46 string
[] folderlist
= chiroGetTagList();
47 foreach (string
fld; folderlist
) writeln(" ", fld);
51 string tagname
= "/dmars_ng/general";
54 for (usize aidx
= 1; aidx
< args
.length
; ) {
55 string arg
= args
[aidx
++];
56 if (args
.length
== 0) continue;
57 if (arg
== "speed") { speedTest
= true; continue; }
58 if (arg
== "last") { showLast
= true; continue; }
59 if (arg
== "threads") { allowThreads
= true; continue; }
60 if (arg
== "nothreads") { allowThreads
= false; continue; }
62 string
[] folderlist
= chiroGetTagList();
63 foreach (string
fld; folderlist
) writeln(" ", fld);
68 if (aidx
>= args
.length
) throw new Exception("\"limit\" requires an argument");
70 monthes
= args
[aidx
++].to
!int;
73 if (tagset
) throw new Exception("tag already selected");
76 while (tagname
.length
> 1 && tagname
[$-1] == '/') tagname
= tagname
[0..$-1];
79 writeln("collecting messages...");
81 Timer ctm
= Timer(true);
83 chiroCreateTreePaneTable(tagname
, monthes
, allowThreads
);
85 chiroCreateTreePaneTable(chiroGetTagUid(tagname
), monthes
, allowThreads
);
90 foreach (auto row
; dbView
.statement(`SELECT max(rowid) AS ncount FROM treepane;`).range
) ncount
= row
.ncount
!uint;
91 writeln("collect time (", ncount
, " messages): ", ctm
);
93 if (speedTest
) return;
95 // 128 spaces for slicing
96 immutable string padstr
= ` `;
97 // 128 dots for slicing
98 immutable string paddot
= `................................................................................................................................`;
102 //if (pgstart > ncount) pgstart = 0;
103 if (showLast
&& ncount
> pgsize
) pgstart
= ncount
-pgsize
+2;
105 auto count
= chiroGetPaneTablePage(pgstart
, pgsize
,
106 delegate (uint pgofs
, /* offset from the page start, from zero and up to `limit` */
107 uint iid
, /* item id, never zero */
108 uint uid
, /* msguid, never zero */
109 uint parentuid
, /* parent msguid, may be zero */
110 uint level
, /* threading level, from zero */
111 int appearance
, /* flags, etc. */
112 SQ3Text date
, /* string representation of receiving date and time */
113 SQ3Text subj
, /* message subject, can be empty string */
114 SQ3Text fromName
, /* message sender name, can be empty string */
115 SQ3Text fromMail
) /* message sender email, can be empty string */
118 writef("%3s | ", pgofs
);
119 writef("%6s | ", iid
);
120 writef("%6s | ", uid
);
121 writef("%6s | ", parentuid
);
123 //foreach (; 0..level) write(".");
124 if (level
> paddot
.length
) level
= cast(uint)paddot
.length
;
125 write(paddot
[0..level
]);
126 subj
= subj
.recodeToKOI8
;
127 auto nlen
= 64-level
;
129 if (subj
.length
> nlen
) {
131 write(subj
[0..nlen
-3], "...");
133 write(subj
[0..nlen
]);
139 //foreach (; subj.length..cast(usize)nlen) write(" ");
140 if (subj
.length
< cast(usize
)nlen
) write(padstr
[0..cast(usize
)nlen
-subj
.length
]);
141 enum MaxNameLen
= 32;
142 fromName
= fromName
.recodeToKOI8
;
143 if (fromName
.length
> MaxNameLen
) {
144 write(" | ", fromName
[0..MaxNameLen
-3], "...");
146 write(" | ", fromName
);
147 //foreach (; fromName.length..MaxNameLen) write(" ");
148 write(padstr
[0..cast(usize
)MaxNameLen
-fromName
.length
]);
150 if (fromMail
.length
> MaxNameLen
) {
151 writeln(" | <", fromMail
[0..MaxNameLen
-3], "...");
153 writeln(" | <", fromMail
, ">");
158 writeln("render time for ", count
, " items: ", ctm
);
160 // this is not necessary, but meh...
161 //chiroReleaseTreePaneTable();
163 writeln("closing the db");