[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.25,1.26 console.h,1.15,1.16
Max Horn
fingolfin at users.sourceforge.net
Sat May 3 14:50:21 CEST 2003
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv17763/gui
Modified Files:
console.cpp console.h
Log Message:
Patch #731613: debugger tab-completion (thanks, Willem!)
Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- console.cpp 3 May 2003 00:08:38 -0000 1.25
+++ console.cpp 3 May 2003 21:49:19 -0000 1.26
@@ -159,7 +159,7 @@
// comply to the C++ standard, so we can't use a dynamic sized stack array.
char *str = new char[len + 1];
- // Copy the user intput to str
+ // Copy the user input to str
for (i = 0; i < len; i++)
str[i] = _buffer[(_promptStartPos + i) % kBufferSize];
str[len] = '\0';
@@ -197,6 +197,33 @@
scrollToCurrent();
draw(); // FIXME - not nice to redraw the full console just for one char!
break;
+ case 9: // tab
+ {
+ if (_completionCallbackProc) {
+ int len = _currentPos - _promptStartPos;
+ assert(len >= 0);
+ char *str = new char[len + 1];
+
+ // Copy the user input to str
+ for (i = 0; i < len; i++)
+ str[i] = _buffer[(_promptStartPos + i) % kBufferSize];
+ str[len] = '\0';
+
+ char *completion = 0;
+ if ((*_completionCallbackProc)(this, str, completion,
+ _callbackRefCon))
+ {
+ if (_caretVisible)
+ drawCaret(true);
+ insertIntoPrompt(completion);
+ scrollToCurrent();
+ draw();
+ delete[] completion;
+ }
+ delete[] str;
+ }
+ break;
+ }
case 127:
killChar();
draw();
@@ -252,6 +279,18 @@
putchar((char)ascii);
scrollToCurrent();
}
+ }
+}
+
+void ConsoleDialog::insertIntoPrompt(const char* str)
+{
+ unsigned int l = strlen(str);
+ for (int i = _promptEndPos-1; i >= _currentPos; i--)
+ _buffer[(i + l) % kBufferSize] =
+ _buffer[i % kBufferSize];
+ for (unsigned int j = 0; j < l; ++j) {
+ _promptEndPos++;
+ putcharIntern(str[j]);
}
}
Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- console.h 6 Mar 2003 21:45:39 -0000 1.15
+++ console.h 3 May 2003 21:49:19 -0000 1.16
@@ -39,6 +39,7 @@
class ConsoleDialog : public Dialog {
public:
typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon);
+ typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon);
protected:
char _buffer[kBufferSize];
@@ -63,6 +64,10 @@
InputCallbackProc _callbackProc;
void *_callbackRefCon;
+ // _completionCallbackProc is called when tab is pressed
+ CompletionCallbackProc _completionCallbackProc;
+ void *_completionCallbackRefCon;
+
char _history[kHistorySize][kLineBufferSize];
int _historySize;
int _historyIndex;
@@ -88,10 +93,15 @@
_callbackProc = proc;
_callbackRefCon = refCon;
}
+ void setCompletionCallback(CompletionCallbackProc proc, void *refCon) {
+ _completionCallbackProc = proc;
+ _completionCallbackRefCon = refCon;
+ }
protected:
void drawCaret(bool erase);
void putcharIntern(int c);
+ void insertIntoPrompt(const char *str);
void print(const char *str);
void nextLine();
void updateScrollBar();
More information about the Scummvm-git-logs
mailing list