display.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * BIBISH Is [a] Bible Interactive SHell, a front-end for the SWORD Project
  3. * inspired by Debian's bible package
  4. * Copyright (C) 2015 David "Judah's Shadow" Blue <yudahsshadow@gmx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation version 2.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. */
  20. #include <iostream>
  21. #include "display.h"
  22. #include "../back/types.h"
  23. void Display::clearScreen() {
  24. for (int i = 0; i <= this->screenSize; i++) {
  25. std::cout << std::endl;
  26. }
  27. }
  28. void Display::displayHeader() {
  29. std::cout << "Welcome to BIBISH" << std::endl;
  30. }
  31. void Display::displayPrompt() {
  32. std::cout << "Enter a command (? for help): ";
  33. }
  34. void Display::displaySpacer(int spacing) {
  35. for(int i = 1; i <= this->screenSize - (spacing + 2); i++) {
  36. std::cout << std::endl;
  37. }
  38. }
  39. void Display::displayHelp() {
  40. clearScreen();
  41. displayHeader();
  42. std::cout << "Valid Commands are:" << std::endl;
  43. std::cout << "show [reference]" << std::endl;
  44. std::cout << " Displays [reference] in the selected version";
  45. std::cout << std::endl;
  46. std::cout << "quit" << std::endl;
  47. std::cout << " Exits the program" << std::endl;
  48. std::cout << "list [type]" << std::endl;
  49. std::cout << " lists available modules of [type]" << std::endl;
  50. std::cout << " defaults to bible if no type is specified" << std::endl;
  51. std::cout << "select [module]" << std::endl;
  52. std::cout << " selects [module] to use for display with show command";
  53. std::cout << std::endl;
  54. std::cout << "?" << std::endl;
  55. std::cout << " Shows this message" << std::endl;
  56. displaySpacer(12);
  57. }
  58. void Display::setSize(uint size) {
  59. screenSize = size;
  60. }
  61. uint Display::getSize() {
  62. return this->screenSize;
  63. }
  64. void Display::displayPages(std::list<page> text) {
  65. std::string displayText = "";
  66. page currentPage;
  67. uint numLines = 0;
  68. uint numPages = 0;
  69. while(!text.empty()) {
  70. displayText = "";
  71. currentPage = text.front();
  72. displayText = currentPage.content;
  73. numLines = currentPage.lineCount;
  74. numPages = text.size();
  75. std::cout << displayText;
  76. this->displaySpacer(numLines);
  77. text.pop_front();
  78. if(numPages > 1) {
  79. std::string dummy = "";
  80. std::cout << "Press enter for next page";
  81. std::getline(std::cin,dummy);
  82. this->clearScreen();
  83. this->displayHeader();
  84. }
  85. }
  86. }
  87. void Display::displayPercentage(uint percent) {
  88. this->clearScreen();
  89. this->displayHeader();
  90. this->displaySpacer(0);
  91. std::cout << "Searching " << percent;
  92. std::cout << "% complete";
  93. std::flush(std::cout);
  94. }