· 6 years ago · Nov 25, 2019, 12:21 PM
1#include <array>
2#include <cmath>
3#include <iostream>
4#include <map>
5#include <string>
6#include <algorithm>
7#include <vector>
8
9#include "common.hpp"
10#include "display.hpp"
11#include "mail.hpp"
12
13#include "list.hpp"
14
15int main()
16{
17#if defined(__linux__)
18 ioctl(0, TIOCGWINSZ , &term);
19#elif defined(_WIN32)
20 CONSOLE_SCREEN_BUFFER_INFO csbi;
21 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
22 term.ws_col = csbi.srWindow.Right - csbi.srWindow.Left + 1;
23 term.ws_row = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
24 #error "platform not yet supported"
25#endif
26
27 bool searching = false;
28 std::map<std::string, List> inboxes;
29 inboxes["inbox"] = List{};
30 inboxes["sent"] = List{};
31
32 for (auto &[k, v] : inboxes)
33 for (int i = 0; i < term.ws_row - 10; ++i)
34 v.push({
35 random_string("words.txt", 1) + "@gmail.com",
36 random_string("words.txt", 1) + "@gmail.com",
37 {1, 1, 1970},
38 random_string("words.txt", 10),
39 random_string("words.txt", 100)
40 });
41
42
43 initwin();
44
45 std::string lookup = "/";
46
47 while (true)
48 {
49 //clear;
50 reset;
51 inboxes["sent"].print(searching, lookup);
52 if (searching) {
53 switch (char c = getchar()) {
54 case 127:
55 printf("\b ");
56 lookup.pop_back();
57 break;
58 case 13:
59 case 27:
60 searching = false;
61 break;
62 default:
63 lookup += c;
64 break;
65 }
66 //cursorto(0, term.ws_row);
67 //std::cout << lookup;
68 } else {
69 switch (getchar()) {
70 case '\033':
71 getchar();
72 switch(getchar()) {
73 case 'A': goto prev;
74 case 'B': goto next;
75 }
76 break;
77 case '/':
78 searching = true;
79 break;
80 case ctrlmask('c'):
81 case 'q':
82 endwin();
83 return 0;
84 case 'j':
85 case 'h':
86 next:
87 inboxes["sent"].move(1);
88 break;
89 case 't':
90 case 'k':
91 prev:
92 inboxes["sent"].move(-1);
93 break;
94 default:
95 break;
96 }
97 }
98 }
99}