]> git.saurik.com Git - cycript.git/blobdiff - Console.cpp
Let's at least parse Objective-J.
[cycript.git] / Console.cpp
index 2d6b566e05aa57565bee6e85dbeef4a0179351d3..1afdb2fe93ef2c9d5f601b9458dc9ecf6c250c22 100644 (file)
@@ -141,7 +141,9 @@ static CYUTF8String Run(CYPool &pool, int client, CYUTF8String code) {
         json = NULL;
 #endif
         mode_ = Working;
-        if (json != NULL)
+        if (json == NULL)
+            size = 0;
+        else
             size = strlen(json);
     } else {
         mode_ = Sending;
@@ -290,18 +292,19 @@ static char **Complete(const char *word, int start, int end) {
             _assert(false);
     }
 
-    std::string begin(prefix.str() + word);
+    std::string begin(prefix.str());
 
-    driver.program_ = $ CYProgram($ CYExpress($C2(ParseExpression(pool,
-    "   function(object, prefix) {\n"
+    driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression(pool,
+    "   function(object, prefix, word) {\n"
     "       var names = [];\n"
-    "       var pattern = '^' + prefix;\n"
+    "       var pattern = '^' + prefix + word;\n"
+    "       var length = prefix.length;\n"
     "       for (name in object)\n"
     "           if (name.match(pattern) != null)\n"
-    "               names.push(name);\n"
+    "               names.push(name.substr(length));\n"
     "       return names;\n"
     "   }\n"
-    ), expression, $S(begin.c_str()))));
+    ), expression, $S(begin.c_str()), $S(word))));
 
     driver.program_->Replace(context);
 
@@ -333,7 +336,14 @@ static char **Complete(const char *word, int start, int end) {
         CYString *string(dynamic_cast<CYString *>(element->value_));
         _assert(string != NULL);
 
-        std::string completion(string->value_, string->size_);
+        std::string completion;
+        if (string->size_ != 0)
+            completion.assign(string->value_, string->size_);
+        else if (driver.mode_ == CYDriver::AutoMessage)
+            completion = "]";
+        else
+            continue;
+
         completions.push_back(completion);
 
         if (!rest) {
@@ -357,12 +367,6 @@ static char **Complete(const char *word, int start, int end) {
     if (count == 0)
         return NULL;
 
-    if (!common.empty()) {
-        size_t size(prefix.str().size());
-        _assert(common.size() >= size);
-        common = common.substr(size);
-    }
-
     size_t colon(common.find(':'));
     if (colon != std::string::npos)
         common = common.substr(0, colon + 1);
@@ -382,7 +386,7 @@ static char **Complete(const char *word, int start, int end) {
 
 // need char *, not const char *
 static char name_[] = "cycript";
-static char break_[] = " \t\n\"\\'`@$><=;|&{(" ".:";
+static char break_[] = " \t\n\"\\'`@$><=;|&{(" ")}" ".:[]";
 
 static void Console(apr_pool_t *pool, CYOptions &options) {
     passwd *passwd;