Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. #include "hci1.h"
  2. #include <boost/filesystem.hpp>
  3. #include <boost/filesystem/fstream.hpp>
  4. #include "magic.h"
  5. #include "gitpp5.h"
  6.  
  7. const unsigned limit=10;
  8. const char spacebar=32;
  9. const char escape=0x1b;
  10.  
  11.  
  12. /////////////////////////////////CONFIG CLASSES/////////////////////////////////
  13.  
  14. class EDIT_CONFIG : public HCI_APPLICATION {
  15. public:
  16. EDIT_CONFIG(GITPP::CONFIG::ITEM &config)
  17. : HCI_APPLICATION(config.name()),
  18. _config(config)
  19. {
  20. }
  21.  
  22. private:
  23. void show() {
  24. std::string temp;
  25. std::cout << "Enter changes: ";
  26. std::cin >> temp;
  27. auto c = _repo.config();
  28. c.create(_config.name());
  29.  
  30. c[_config.name()] = temp;
  31. std::cout << _config.name();
  32. }
  33.  
  34. private:
  35. GITPP::REPO _repo;
  36. GITPP::CONFIG::ITEM _config;
  37. };
  38.  
  39. class CONFIG_MENU : public HCI_MENU {
  40. public:
  41. explicit CONFIG_MENU(HCI_APPLICATION& ctx)
  42. : HCI_MENU(ctx),
  43. _ctx(ctx) {}
  44.  
  45. ~CONFIG_MENU() override {
  46. clear();
  47. }
  48.  
  49. void populate() {
  50. purge();
  51.  
  52.  
  53. int configno = 0;
  54.  
  55. for(auto i : _repo.config()){
  56. add(char ('a'+configno), new EDIT_CONFIG(i));
  57. ++configno;
  58. }
  59.  
  60. add('q', &hci_quit);
  61. add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ///////////////////////needs changing
  62. }
  63.  
  64. public:
  65. void enter() {
  66. while(true) {
  67. try {
  68. HCI_MENU::enter();
  69. break;
  70. }
  71. catch(const HCI_LEAVE& e) {
  72. continue;
  73. }
  74. }
  75. }
  76. void show() {
  77. populate();
  78.  
  79. std::cout << "Configure Menu. Select an element to edit" << "\n" << std::endl;
  80. HCI_MENU::show();
  81. std::cout << "\n";
  82. }
  83.  
  84. private:
  85. HCI_APPLICATION& _ctx;
  86. GITPP::REPO _repo;
  87. };
  88.  
  89. class CONFIG : public HCI_APPLICATION {
  90. public:
  91. CONFIG()
  92. : HCI_APPLICATION("Configure repository"), _config(*this) {}
  93.  
  94. public:
  95. void show() override {
  96. while(true) {
  97. try {
  98. _config.enter();
  99. }
  100. catch(const HCI_ESCAPE& e) {
  101. break;
  102. }
  103. }
  104. }
  105.  
  106. private:
  107. CONFIG_MENU _config;
  108. };
  109.  
  110. class CONFIG_SHOWER : public HCI_MENU {
  111. public:
  112. explicit CONFIG_SHOWER(HCI_APPLICATION& ctx)
  113. : HCI_MENU(ctx),
  114. _ctx(ctx) {}
  115.  
  116. ~CONFIG_SHOWER() override {
  117. clear();
  118. }
  119.  
  120. void populate() {
  121. purge();
  122. for(auto i : _repo.config()){
  123. std::cout << i.name() << ": " << i.value() << std::endl;
  124. }
  125.  
  126. add('q', &hci_quit);
  127. add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ///////////////////////needs changing
  128. }
  129.  
  130. public:
  131. void enter() {
  132. while(true) {
  133. try {
  134. HCI_MENU::enter();
  135. break;
  136. }
  137. catch(const HCI_LEAVE& e) {
  138. continue;
  139. }
  140. }
  141. }
  142. void show() {
  143. populate();
  144.  
  145. std::cout << "Configure Menu. Choose " << "\n" << std::endl;
  146. HCI_MENU::show();
  147. std::cout << "\n";
  148. }
  149.  
  150. private:
  151. HCI_APPLICATION& _ctx;
  152. GITPP::REPO _repo;
  153. };
  154.  
  155. class LIST_CONFIG : public HCI_APPLICATION {
  156. public:
  157. LIST_CONFIG()
  158. : HCI_APPLICATION("Config List"), _config(*this) {}
  159.  
  160. public:
  161. void show() override {
  162. while(true) {
  163. try {
  164. _config.enter();
  165. }
  166. catch(const HCI_ESCAPE& e) {
  167. break;
  168. }
  169. }
  170. }
  171.  
  172. private:
  173. CONFIG_SHOWER _config;
  174. };
  175.  
  176. ///////////////////////////////CONFIG CLASSES END///////////////////////////////
  177.  
  178. /////////////////////////////////COMMIT CLASSES/////////////////////////////////
  179. class COMMIT_SHOWER : public HCI_MENU {
  180. public:
  181. explicit COMMIT_SHOWER(HCI_APPLICATION& ctx)
  182. : HCI_MENU(ctx),
  183. _ctx(ctx) {}
  184.  
  185. ~COMMIT_SHOWER() override {
  186. clear();
  187. }
  188.  
  189. void populate() {
  190. purge();
  191.  
  192. int counter = 1;
  193. for(auto i : _repo.commits()){
  194. std::cout << counter << ": " << i << " " << i.signature().name() << " " << i.message() << "\n";
  195. ++counter;
  196. }
  197.  
  198. add('q', &hci_quit);
  199. add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ////////////////////needs changing
  200. }
  201.  
  202. public:
  203. void enter() {
  204. while(true) {
  205. try {
  206. HCI_MENU::enter();
  207. break;
  208. }
  209. catch(const HCI_LEAVE& e) {
  210. continue;
  211. }
  212. }
  213. }
  214. void show() {
  215. populate();
  216.  
  217. std::cout << "Commit List " << "\n" << std::endl;
  218. HCI_MENU::show();
  219. std::cout << "\n";
  220. }
  221.  
  222. private:
  223. HCI_APPLICATION& _ctx;
  224. GITPP::REPO _repo;
  225. };
  226.  
  227. class LIST_COMMITS : public HCI_APPLICATION {
  228. public:
  229. LIST_COMMITS()
  230. : HCI_APPLICATION("Commit List"), _commit(*this) {}
  231.  
  232. public:
  233. void show() override {
  234. while(true) {
  235. try {
  236. _commit.enter();
  237. }
  238. catch(const HCI_ESCAPE& e) {
  239. break;
  240. }
  241. }
  242. }
  243.  
  244. private:
  245. COMMIT_SHOWER _commit;
  246. };
  247.  
  248.  
  249.  
  250. class MAIN_MENU : public HCI_MENU {
  251. public:
  252. explicit MAIN_MENU(HCI_APPLICATION& ctx)
  253. : HCI_MENU(ctx),
  254. _ctx(ctx) {}
  255.  
  256. ~MAIN_MENU() override {
  257. clear();
  258. }
  259.  
  260. void populate() {
  261. purge();
  262.  
  263. add('c', new LIST_CONFIG());
  264. add('e', new CONFIG()); //Creates new objects based on option.
  265. add('l', new LIST_COMMITS());
  266. add('q', &hci_quit);
  267. add(escape, &hci_quit); //Quits since there isn't a menu prior to menu.
  268. }
  269.  
  270. public:
  271. void enter() {
  272. while(true) {
  273. try {
  274. HCI_MENU::enter();
  275. break;
  276. }
  277. catch(const HCI_LEAVE& e) {
  278. continue;
  279. }
  280. }
  281. }
  282. void show() {
  283. populate();
  284.  
  285. std::cout << "Main menu" << "\n" << std::endl;
  286. HCI_MENU::show();
  287. std::cout << "\n";
  288. }
  289.  
  290. private:
  291. HCI_APPLICATION& _ctx;
  292. };
  293.  
  294. class MAIN : public HCI_APPLICATION {
  295. public:
  296. MAIN(int argc, char const *argv[])
  297. : HCI_APPLICATION("Main menu"), _main_menu(*this) {}
  298. public:
  299. void show() override {
  300. while(true) {
  301. try {
  302. _main_menu.enter();
  303. }
  304. catch(const HCI_ESCAPE& e) {
  305. break;
  306. }
  307. }
  308. }
  309.  
  310. private:
  311. MAIN_MENU _main_menu;
  312. };
  313.  
  314. ///////////////////////////////COMMIT CLASSES END///////////////////////////////
  315.  
  316. /////////////////////////////////CREATE CLASSES/////////////////////////////////
  317.  
  318. class CREATE_REPO : public HCI_APPLICATION {
  319. public:
  320. explicit CREATE_REPO() {}
  321.  
  322. ~CREATE_REPO() override {
  323. clear();
  324. }
  325.  
  326. public:
  327. void show() override {
  328. std::string base_path = ".";
  329. GITPP::REPO repo(GITPP::REPO::_create, base_path);
  330. }
  331. };
  332.  
  333. ///////////////////////////////CREATE CLASSES END///////////////////////////////
  334.  
  335. /////////////////////////////////SETUPS CLASSES/////////////////////////////////
  336.  
  337. class SETUP_MENU : public HCI_MENU {
  338. public:
  339. explicit SETUP_MENU(HCI_APPLICATION& ctx)
  340. : HCI_MENU(ctx),
  341. _ctx(ctx) {}
  342.  
  343. ~SETUP_MENU() override {
  344. clear();
  345. }
  346.  
  347. void populate() {
  348. purge();
  349. add('y', new CREATE_REPO());
  350. add('n', &hci_quit);
  351. add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. //////////////////needs changing
  352. }
  353.  
  354. public:
  355. void enter() {
  356. while(true) {
  357. try {
  358. HCI_MENU::enter();
  359. break;
  360. }
  361. catch(const HCI_LEAVE& e) {
  362. continue;
  363. }
  364. }
  365. }
  366. void show() {
  367. populate();
  368.  
  369. std::cout << "Setup Menu" << "\n" << std::endl;
  370. HCI_MENU::show();
  371. std::cout << "\n";
  372. }
  373.  
  374. private:
  375. HCI_APPLICATION& _ctx;
  376. };
  377.  
  378.  
  379. class SETUP : public HCI_APPLICATION {
  380. public:
  381. SETUP()
  382. : HCI_APPLICATION("Commit List"), _setup(*this) {}
  383.  
  384. public:
  385. void show() override {
  386. while(true) {
  387. try {
  388. _setup.enter();
  389. }
  390. catch(const HCI_ESCAPE& e) {
  391. break;
  392. }
  393. }
  394. }
  395.  
  396. private:
  397. SETUP_MENU _setup;
  398. };
  399.  
  400. ///////////////////////////////SETUPS CLASSES END///////////////////////////////
  401.  
  402.  
  403. // the program starts here.
  404. int main(int argc, char const *argv[]) {
  405. std::string base_path = ".";
  406.  
  407. try {
  408. GITPP::REPO repo(base_path); //Check for existing repo and store in repo object
  409. std::cout << ".git folder found" << std::endl; // let user know repo found
  410. MAIN caller(argc, argv); //Enters main menu.
  411. caller.exec();
  412. }
  413. catch(const GITPP::EXCEPTION_CANT_FIND& e){
  414. SETUP setup_caller;
  415. setup_caller.exec();
  416. }
  417.  
  418.  
  419. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement