Cross-platform ConsoleTitle()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Cross-platform ConsoleTitle()

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

On linux for example you can't change the console title, as it's terminal dependant..
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

@Fred: Sorry that I have to double-post, but is the terminal a "Xterm" ?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Xterm is one of the huge number of terminal app available on linux.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Yes, but only if XTerm is used.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post 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
Ta - N
Post Reply