U++ framework
Do not panic. Ask here before giving up.

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 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1796
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

I think you are taking it too seriously Wink 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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Issue tracking...
Next Topic: Question: Simple plugin implementation
Goto Forum:
  


Current Time: Thu Oct 15 08:23:51 GMT+2 2026

Total time taken to generate the page: 0.00665 seconds