Page 1 of 1

Cross-platform ConsoleTitle()

Posted: Fri May 05, 2006 7:59 pm
by josku_x
Hello!

I am really into making console apps and it's because I want everything to be cross-platform. However, I found out that some functions of the Console library work with Windows, Linux and Mac, but ConsoleTitle() which I really need works only on Windows.

Is it possible to have a cross-platform version of the ConsoleTitle() function? Please understand me that this is a VERY important function for me.

Thanks

EDIT: Here's a list of Console functions that work only in Windows:
ClearConsole()
ConsoleColor()
ConsoleCursor()
ConsoleLocate()
ConsoleTitle()
It would be nice to have those also working in Linux and Mac.

Posted: Fri May 05, 2006 9:17 pm
by Fred
On linux for example you can't change the console title, as it's terminal dependant..

Posted: Fri May 05, 2006 9:22 pm
by Nik
Should be the same on mac isn't it? It's the same principle yet even the same shell as on linux, both use bash, or similiar shells

Posted: Fri May 05, 2006 9:29 pm
by josku_x
Fred wrote:On linux for example you can't change the console title, as it's terminal dependant..
I see, just hoped to have a nice Console app with a title, but I didn't lose anything yet.

Posted: Sat May 06, 2006 11:04 am
by josku_x
@Fred: Sorry that I have to double-post, but is the terminal a "Xterm" ?

Posted: Sat May 06, 2006 12:09 pm
by Fred
Xterm is one of the huge number of terminal app available on linux.

Posted: Sat May 06, 2006 5:30 pm
by Trond
josku_x wrote:@Fred: Sorry that I have to double-post, but is the terminal a "Xterm" ?
How can he know what kind of terminal the user uses? He cannot account for all of them.

Posted: Sat May 06, 2006 5:41 pm
by josku_x
I don't know Trond, but I read somewhere that you can change the title of a XTerm terminal in your application, that's why I hoped there will be a Linux ConsoleTitle().

EDIT: If the user can know which terminal the program is runned on, wouldn't this pseudo-code help out to have a ConsoleTitle() available in Linux?

Code: Select all

If UserCalled_ConsoleTitle
 If Terminal=XTerm
  Set_XTerm_Title(UserDefined_ConsoleTitle)
 EndIf
EndIf

Posted: Sat May 06, 2006 6:18 pm
by Trond
Yes, but only if XTerm is used.

Posted: Sat May 06, 2006 6:56 pm
by josku_x
And that's upon to the user. If we know other Terminals, which title can be changed, then the pseudo-code can be changed to this:

Code: Select all

If UserCalled_ConsoleTitle 
 If Terminal=XTerm 
  Set_XTerm_Title(UserDefined_ConsoleTitle) 
 ElseIf Terminal=TrondTerminal
  Set_TrondTerminal_Title(UserDefined_ConsoleTitle)
 EndIf 
EndIf
However, I found that the ConsoleTitle is not SO improtant.
I could just before the real program do this:

Code: Select all

PrintN("---------------------")
PrintN("My Cool Console Title")
PrintN("---------------------")
It would even look cooler than setting the terminals title.

Posted: Sat May 06, 2006 7:24 pm
by Nik
I also think that most Linux users would hate to have their terminal title changed that's just not how it is done here(on linux), the will probably also use your tool in a plain Text based environnment they are (luckily) still common in the *NIX area

Posted: Sat May 06, 2006 7:55 pm
by josku_x
I think you are right. I like Linux, I have used Red-Hat Linux and Mandrake, and both are very cool. What I liked the most was the Terminal (XTerm to be specific). I wish Windows would be like that.. Because Windows has the advantage that it has a quite powerful and large API.

I have one question though: If I compile a console program in PB (Windows version) will the console program work also in Linux or Mac OSX?

The console program source is similar to this, and it uses only commands that work in Windows, Linux and Mac OSX as stated in the helpfile of each command.

Code: Select all

OpenConsole()
Print("> "):CInput$=Input()
Repeat
 If CInput$="/help"
  PrintN("")
  PrintN(" My Cool Console Version 2")
 EndIf
 PrintN(""):Print("> ")
 CInput$=Input()
ForEver
Thanks

Posted: Wed May 10, 2006 2:07 am
by naw
what you need is a little shell script to launch your program in a custom xterm - this is the easiest way for you:

X-Windows based applications can have their appearance customised in nearly every aspect - way more flexible than MS/Windows...

Code: Select all

#!/bin/sh
xterm -T "My Cool Program" -bg yellow -fg red -cr green -e /home/josku_x/myapp
The first line specifies the shell in which to launch your program (note: *N*X (Linux / Unix) systems don't require .exe or .bat)

-T or -title = the title of your window
-bg = the background colour
-fg = the foreground colour
-cr = the cursor colour
-e = the program to execute

type

Code: Select all

man xterm 
for a more complete list of options