5 Commity 76cbfe4aa7 ... b878a15b93

Autor SHA1 Wiadomość Data
  David Blue b878a15b93 Fix up the display during searches. 6 lat temu
  David Blue 463b82aca8 I was apparently just pushing search back as the argument, if provided when parsing the search command. That is fixed now to currently just send the rest of the command as one big string blob to pass as the search terms. 6 lat temu
  David Blue 3b4672e4d9 First steps to making search non-hardcoded! Providing an argument as a search term returns too many/incorrect results, but it's getting there. 6 lat temu
  David Blue 27020db5b3 Fix handling of empty command since it was being accounted for in the tokenization but not in the parsing. 6 lat temu
  David Blue f26f32a3aa Searching works but is still hard coded. The percent thing displays now, though. 6 lat temu

+ 13 - 3
src/back/parser.cpp

@@ -46,8 +46,13 @@ std::list< std::string > Parser::parseCommand(std::string command) {
     argumentPart.clear();
 
     tokenizedCommand = tokenize(command);
-    commandPart = tokenizedCommand.front();
-    tokenizedCommand.pop_front();
+    if(!tokenizedCommand.empty()) {
+        commandPart = tokenizedCommand.front();
+        tokenizedCommand.pop_front();
+    }
+    else {
+        commandPart = "";
+    }
 
     parsedCommand.push_back(commandPart);
 
@@ -96,7 +101,12 @@ std::list< std::string > Parser::parseCommand(std::string command) {
         }
     }
     else if(commandPart == "search") {
-        parsedCommand.push_back("search");
+        //For now, assume all arguments are part of the search query
+        //in the future look at this to parse actual command arguments when
+        //those exist for search.
+        std::string query = "";
+        query = detokenize(argumentPart);
+        parsedCommand.push_back(query);
     }
     else {
         //Add a genral case to just pass arguments to the back as a list

+ 17 - 4
src/back/search.cpp

@@ -26,6 +26,9 @@
 
 #include <regex.h>
 #include <string>
+#include <iostream>
+
+Display Search::searchDisplay;
 
 void Search::setSwordLibrary(sword::SWMgr *library) {
     swordLibrary = library;
@@ -35,9 +38,17 @@ void Search::setModule(std::string mod) {
     module = swordLibrary->getModule(mod.c_str());
 }
 
+void Search::setDisplay(Display display) {
+    searchDisplay = display;
+}
+
 
 void Search::percentUpdate(char percent, void *userData) {
-
+    //TODO: Hook this into the display class
+    uint percentage;
+    percentage = (int) percent;
+    
+    searchDisplay.displayPercentage(percent);
 }
 
 
@@ -46,12 +57,14 @@ std::string Search::search(std::string searchString) {
     sword::ListKey results;
     char lineLen = 80;
     std::string verses = "";
-    
-    
 
+    
     results = module->search(searchString.c_str(),searchType,
-                                   REG_ICASE, 0,0, &percentUpdate, &lineLen);
+                            REG_ICASE, 0,0, &percentUpdate,
+                            &lineLen);
     while(!results.popError()) {
+        //TODO: Set this to return more than just verse references
+        //or maybe make that a separate method?
 //         verses = results.getElement()->userData;
       verses += (const char*)results;
       verses.append("\n");

+ 5 - 0
src/back/search.h

@@ -26,17 +26,22 @@
 #include <swmgr.h>
 
 #include "library.h"
+#include "../front/display.h" //for doing search progress displays
 
 class Search {
 public:
     void setSwordLibrary(sword::SWMgr *library);
     void setModule(std::string module);
+    void setDisplay(Display display);
 
     std::string search(std::string searchString);
 private:
     static void percentUpdate(char percent,void *userData);
     sword::SWMgr *swordLibrary;
     sword::SWModule *module;
+    //this is static so it can be accessed in the percentUpdate function
+    //sword needs to be static
+    static Display searchDisplay;
 };
 
 #endif // SEARCH_H

+ 10 - 1
src/front/display.cpp

@@ -65,7 +65,7 @@ void Display::setSize(uint size) {
 }
 
 uint Display::getSize() {
-    return screenSize;
+    return this->screenSize;
 }
 
 void Display::displayPages(std::list<page> text) {
@@ -93,3 +93,12 @@ void Display::displayPages(std::list<page> text) {
         }
     }
 }
+
+void Display::displayPercentage(uint percent) {
+    this->clearScreen();
+    this->displayHeader();
+    this->displaySpacer(0);
+    std::cout << "Searching " << percent;
+    std::cout << "% complete";
+    std::flush(std::cout);
+}

+ 1 - 0
src/front/display.h

@@ -36,6 +36,7 @@ class Display {
         void setSize(uint size);
         uint getSize();
         void displayPages(std::list<page> text);
+        void displayPercentage(uint percent);
     private:
         uint screenSize;
 

+ 21 - 3
src/front/interface.cpp

@@ -40,6 +40,7 @@ void Interface::initalize() {
     this->swordLibrary = new sword::SWMgr(new sword::MarkupFilterMgr
                                           (sword::FMT_PLAIN));
     std::cout << "Initalized, proceeding to shell..." << std::endl;
+//     this->display = new Display;
 }
 
 void Interface::configLines() {
@@ -185,21 +186,38 @@ std::string Interface::processCommand(std::string command) {
             Search searcher;
             Pager resultsPager;
             std::list<page> pagedResults;
-            std::string results;
+            std::string results = "";
+            std::string searchTerms = "";
             
             resultsPager.setSize(display.getSize());
             
             searcher.setSwordLibrary(this->swordLibrary);
             searcher.setModule(selectedVersion);
+            searcher.setDisplay(display);
             
+            //If no argument is provided to the command, propmpt for the
+            //search terms, otherwise recombine the arguments into a string
+            if (parsedCommand.empty()) {
+                display.displayHeader();
+                display.displaySpacer(2);
+                std::cout << "Enter a word or phrase to search for: ";
+                std::getline(std::cin,searchTerms);
+
+            }
+            else {
+                searchTerms = parsedCommand.front();
+            }
+
             //TODO: Make this more than references or an option to do text or
             //reference results or both.
-            results = searcher.search("Jesus");
+            results = searcher.search(searchTerms);
             pagedResults = resultsPager.getPagedText(results);
             
+            display.clearScreen();
+            display.displayHeader();
             display.displayPages(pagedResults);
             
-            return command;
+            return commandPart;
         }
         else {
             std::cerr << "Error: No Module Selected" << std::endl;