First pass at label completion in prompt. Since Tab is used for switching

between widgets, I used Escape as the completion key. It's almost working
correctly, but the implementation should be cleaned up.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@552 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
urchlay 2005-06-24 00:03:39 +00:00
parent 7db440c0b1
commit 18aebd77c9
3 changed files with 87 additions and 3 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EquateList.cxx,v 1.14 2005-06-23 01:10:25 urchlay Exp $
// $Id: EquateList.cxx,v 1.15 2005-06-24 00:03:39 urchlay Exp $
//============================================================================
#include <string>
@ -307,3 +307,25 @@ string EquateList::dumpAll() {
}
return ret;
}
int EquateList::countCompletions(const char *in) {
int count = 0;
completions = "";
cerr << "Attempting to complete \"" << in << "\"" << endl;
for(int i=0; i<currentSize; i++) {
if(ourVcsEquates[i].address != -1) {
const char *l = ourVcsEquates[i].label;
if(STR_N_CASE_CMP(l, in, strlen(in)) == 0) {
if(count++) completions += " ";
completions += l;
}
}
}
cerr << "Found " << count << " label(s):" << endl << completions << endl;
return count;
}
const char *EquateList::getCompletions() {
return completions.c_str();
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EquateList.hxx,v 1.8 2005-06-23 01:10:25 urchlay Exp $
// $Id: EquateList.hxx,v 1.9 2005-06-24 00:03:39 urchlay Exp $
//============================================================================
#ifndef EQUATELIST_HXX
@ -38,12 +38,15 @@ class EquateList {
bool undefine(string& label);
bool undefine(const char *lbl);
string dumpAll();
int countCompletions(const char *in);
const char *getCompletions();
private:
int calcSize();
int parse4hex(char *c);
string extractLabel(char *c);
int extractValue(char *c);
string completions;
private:
Equates ourVcsEquates;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: PromptWidget.cxx,v 1.13 2005-06-23 14:33:11 stephena Exp $
// $Id: PromptWidget.cxx,v 1.14 2005-06-24 00:03:38 urchlay Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -30,6 +30,7 @@
#include "DebuggerDialog.hxx"
#include "PromptWidget.hxx"
#include "EquateList.hxx"
#define PROMPT "> "
@ -191,6 +192,64 @@ bool PromptWidget::handleKeyDown(int ascii, int keycode, int modifiers)
break;
}
case 27: // escape
{
if(_currentPos <= _promptStartPos)
break;
scrollToCurrent();
int len = _promptEndPos - _promptStartPos;
if(len <= 3)
break;
int lastSpace = -1;
char *str = new char[len + 1];
for (i = 0; i < len; i++) {
str[i] = buffer(_promptStartPos + i);
if(str[i] == ' ')
lastSpace = i;
}
str[len] = '\0';
if(lastSpace < 2) {
delete[] str;
break;
}
int oldPos = _currentPos;
nextLine();
int possibilities = instance()->debugger().equates()->countCompletions(str + lastSpace + 1);
if(possibilities < 1) {
delete[] str;
break;
}
const char *got = instance()->debugger().equates()->getCompletions();
if(possibilities == 1) {
// add to buffer as though user typed it (plus a space)
_currentPos = _promptStartPos + lastSpace + 1;
while(*got != '\0') {
_buffer[_currentPos++] = *got++;
}
_buffer[_currentPos++] = ' ';
_promptEndPos = _currentPos;
} else {
// add to buffer as-is, then add PROMPT plus whatever the user's typed
print(got);
print("\n");
print(PROMPT);
print(str);
int offset = _currentPos - oldPos;
_promptStartPos += offset;
_promptEndPos += offset;
}
draw();
delete[] str;
break;
}
case 8: // backspace
if (_currentPos > _promptStartPos)
killChar(-1);