improved autocomplete and history

This commit is contained in:
Lendemor 2017-08-31 20:15:42 +02:00
parent 51e3b949c4
commit c70453ff65
3 changed files with 23 additions and 22 deletions

View File

@ -182,7 +182,7 @@ std::string TextInputNode::getText()
void TextInputNode::clearText()
{
m_history.push_back(m_text);
m_history_pos++;
m_history_pos=m_history.size();
m_text.clear();
}

View File

@ -73,22 +73,28 @@ void SparrowShell::AutocompletionCallBack::exec(){
std::vector<std::string> results = m_shell->m_script->possibleCompletion(text);
if (!results.empty()){
std:: string common_prefix = results[0];
for( auto result : results){
int i = 0;
auto s1 = common_prefix.c_str();
auto s2 = result.c_str();
std::string cp;
while( (s1[i] && s2[i]) && (s1[i] == s2[i]) )
cp.push_back(s1[i++]);
common_prefix = cp;
if(results.size() == 1){
std::string text = results[0];
text+="()";
m_text_input_node->setText(text);
}else{
std:: string common_prefix = results[0];
for( auto result : results){
int i = 0;
auto s1 = common_prefix.c_str();
auto s2 = result.c_str();
std::string cp;
while( (s1[i] && s2[i]) && (s1[i] == s2[i]) )
cp.push_back(s1[i++]);
common_prefix = cp;
}
m_text_input_node->setText(common_prefix);
std::string output = "";
for(std::string& fun : results)
output+=fun+" ";
m_shell->out(output,glm::vec3(1,1,0));
}
m_text_input_node->setText(common_prefix);
}
std::string output = "";
for(std::string& fun : results)
output+=fun+" ";
m_shell->out(output,glm::vec3(1,1,0));
}
void SparrowShell::InputCallBack::exec(){

View File

@ -438,13 +438,8 @@ int main(){
}*/
// shell output tests
engine.getShell()->out("Hello World!");
engine.getShell()->out("Starting test :");
// engine.getScene()->updateShaders();
// BackGroundNode* bgrn = new BackGroundNode(glm::vec2(10),glm::vec3(1.,1.,1.),1,1);
// engine.getScene()->getRootObject()->addChild(bgrn);
// engine.getShell()->out("Hello World!");
// engine.getShell()->out("Starting test :");
// preparing shaders and launching the engine
engine.start();