Home » Developing U++ » U++ Developers corner » Q: howto incorporate a native console window in GUI
Re: Q: howto incorporate a native console window in GUI [message #31154 is a reply to message #31153] |
Thu, 10 February 2011 14:54 |
|
I think you are taking it too seriously Here is a working example (change the paths if you are on windows): #include <CtrlLib/CtrlLib.h>
using namespace Upp;
class ConsoleCtrl:public LineEdit{
typedef ConsoleCtrl CLASSNAME;
LocalProcess p;
int last;
public:
virtual bool Key(dword key,int count){
switch(key) {
case K_ENTER:{
String cmd=line.Top().text.Right(GetLength()-last)+'\n';
Insert(GetLength(),"\n");
p.Write(cmd);
}
return true;
case K_UP: //might implement history browsing...
case K_DOWN:
case K_PAGEUP:
case K_PAGEDOWN:
case K_CTRL_PAGEUP:
case K_CTRL_HOME:
case K_CTRL_PAGEDOWN:
case K_CTRL_END:
return true;
}
return LineEdit::Key(key,count);
}
void Read(){
String s;
p.Read(s);
if(s.IsEmpty()) return;
Insert(GetLength(),s);
last=GetLength();
SetCursor(last);
}
ConsoleCtrl(const String& cmd="/bin/bash"){
p.Start(cmd);
SetTimeCallback(-50,THISBACK(Read));
}
~ConsoleCtrl(){
p.Kill();
}
};
class App :public TopWindow {
typedef App CLASSNAME;
ConsoleCtrl c;
public:
App():c("/usr/bin/python -i"){ // -i is required to use it interactively
Add(c.SizePos());
}
};
GUI_APP_MAIN{
App().Sizeable().Run();
}
It is just quickly hacked to gather, but the general idea seems to be working just fine. I tested it with bash and python and it feels almost like a terminal, except for missing features like history or tab completion... but those could be probably implemented too with a bit of work.
Honza
|
|
|
|
|
Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 10:39
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 13:33
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 14:04
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: mdelfede on Thu, 10 February 2011 14:10
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 14:45
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 15:02
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 15:34
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 20:52
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Thu, 10 February 2011 21:58
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: mdelfede on Thu, 10 February 2011 14:03
|
|
|
Re: Q: howto incorporate a native console window in GUI
|
|
|
Re: Q: howto incorporate a native console window in GUI
By: kohait00 on Fri, 11 February 2011 11:32
|
Goto Forum:
Current Time: Sat May 11 13:31:53 CEST 2024
Total time taken to generate the page: 0.02963 seconds
|