Jump to page: 1 2
Thread overview
Spawn a Command Line application Window and output log information
May 18, 2020
BoQsc
May 18, 2020
Panke
May 18, 2020
BoQsc
May 18, 2020
Kagamin
May 18, 2020
BoQsc
May 18, 2020
Kagamin
May 18, 2020
BoQsc
May 18, 2020
BoQsc
May 18, 2020
BoQsc
May 19, 2020
BoQsc
May 23, 2020
BoQsc
May 18, 2020
Adam D. Ruppe
May 18, 2020
I'd like to have application as small as possible with a simple Command Line Window.
I'd use that Window to output notices, log information and the like.

Would this require GUI library and how can this be achieved?


May 18, 2020
On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
> I'd like to have application as small as possible with a simple Command Line Window.
> I'd use that Window to output notices, log information and the like.
>
> Would this require GUI library and how can this be achieved?

If you do not want to create the library yourself, you could spawn a terminal application like konsole or kitty and start a simple cli app.

You'd need to have some form of inter process communication setup for this though.
May 18, 2020
On Monday, 18 May 2020 at 16:40:24 UTC, Panke wrote:
> On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
>> I'd like to have application as small as possible with a simple Command Line Window.
>> I'd use that Window to output notices, log information and the like.
>>
>> Would this require GUI library and how can this be achieved?
>
> If you do not want to create the library yourself, you could spawn a terminal application like konsole or kitty and start a simple cli app.
>
> You'd need to have some form of inter process communication setup for this though.

On Windows 10, this example, when compiled and clicked on the executable - spawns a command line with the "Hello World" output shown.


import std.stdio;

void main() {
    write("Hello, World!");

	string line;
	while ((line = readln()) !is null)
	        write(line);
}


The important question is: how can we change the name/title of this Command Line application.
May 18, 2020
On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
> The important question is: how can we change the name/title of this Command Line application.

As the simplest solution, you can set the window title in shortcut properties.
May 18, 2020
On Monday, 18 May 2020 at 17:08:41 UTC, Kagamin wrote:
> On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
>> The important question is: how can we change the name/title of this Command Line application.
>
> As the simplest solution, you can set the window title in shortcut properties.

It seems that all the Command Prompt Batch command of windows such as "title" do work well.
By using executeShell I was able to change the title of the Command Line that runs my program.

import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
    writeln("Hello, World!");
	executeShell("title HelloWorld");
	string line;
	while ((line = readln()) !is null)
	        write(line);
}


import std.file : mkdir;

It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library.
May 18, 2020
On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
> Would this require GUI library and how can this be achieved?

you might enjoy using my terminal lib

https://code.dlang.org/packages/arsd-official%3Aterminal

include that and set

"subConfigurations": {
   "arsd-official:terminal": "builtin_emulator"
}


and it gives you a gui window that acts like a terminal.

then in your program, here's a complete program you can run with

dub run --single file.d


/+ dub.sdl:
        name "cool"
        dependency "arsd-official:terminal" version=">=7.2.0"
        subConfiguration "arsd-official:terminal" "builtin_emulator"
+/

import arsd.terminal;
void main() {
   auto terminal = Terminal(ConsoleOutputType.linear);
   terminal.setTitle("whatever");

   // this is possible too but you MUST have an indexed png which might be hard to make if you aren't ready for it.
   terminal.changeWindowIcon("your_icon.png");

   terminal.writeln("hi");

   auto got = terminal.getline("say something: ");

   terminal.writeln("you said ", got);
}
May 18, 2020
On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
> It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library.

I think the window icon is just the first icon pulled from the executable file.
May 18, 2020
On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
> It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library.

Forever thankful to Adam D. Ruppe
It is possible to embed icon into the Windows executable.
The Original Adam's thread: https://forum.dlang.org/post/enrmidvsfdugqmudokdz@forum.dlang.org

The instructions:
Download a valid Windows 3.0 icon resource
Examples: http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip

Download the tools to embed the Icon for the .exe executable.
http://ftp.digitalmars.com/bup.zip

Create a new text file named whatever.rc with the content similar to this:

> IDI_ICON1       ICON    DISCARDABLE     "iconfil.ico"

Use rcc.exe tool and whatever.rc file to generate whatever.res file.
> rcc.exe whatever.rc

Use dmd.exe compiler to embed newly created whatever.res file into your .exe file while compiling:
> dmd.exe whatever.res

You should see that the newly compiled .exe file is now with an Icon.
And when launched the icon will be used by the Command Prompt.




May 18, 2020
On Monday, 18 May 2020 at 17:51:54 UTC, BoQsc wrote:
> On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
>> It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library.
>
> Forever thankful to Adam D. Ruppe
> It is possible to embed icon into the Windows executable.
> The Original Adam's thread: https://forum.dlang.org/post/enrmidvsfdugqmudokdz@forum.dlang.org
>
> The instructions:
> Download a valid Windows 3.0 icon resource
> Examples: http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip
>
> Download the tools to embed the Icon for the .exe executable.
> http://ftp.digitalmars.com/bup.zip
>
> Create a new text file named whatever.rc with the content similar to this:
>
>> IDI_ICON1       ICON    DISCARDABLE     "iconfil.ico"
>
> Use rcc.exe tool and whatever.rc file to generate whatever.res file.
>> rcc.exe whatever.rc
>
> Use dmd.exe compiler to embed newly created whatever.res file into your .exe file while compiling:
>> dmd.exe whatever.res
>
> You should see that the newly compiled .exe file is now with an Icon.
> And when launched the icon will be used by the Command Prompt.

Also, if you want some kind of Fancy ASCII art in your application:

Look at the Google for any ASCII Art generator:  http://patorjk.com/software/taag/#p=display&f=Elite&t=Hello%20World

Add this line and insert your ASCII art in a writeln function.
> executeShell("chcp 65001");
to your D language program source code

More about chcp can be found here: https://ss64.com/nt/chcp.html
Or here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/chcp


import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
	executeShell("title HelloWorld");
	executeShell("chcp 65001");
	writeln("Hello, World!");
	writeln("
 ▄ .▄▄▄▄ .▄▄▌  ▄▄▌            ▄▄▌ ▐ ▄▌      ▄▄▄  ▄▄▌  ·▄▄▄▄
██▪▐█▀▄.▀·██•  ██•  ▪         ██· █▌▐█▪     ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄     ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌    ▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪     ▀▀▀▀ ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀▀▀▀▀•

");


	string line;
	while ((line = readln()) !is null)
	        write(line);
}
May 18, 2020
On Monday, 18 May 2020 at 18:10:06 UTC, BoQsc wrote:
> Also, if you want some kind of Fancy ASCII art in your application

Since I started this thread, I might share some more improvements.

In this Update I managed to get the PID of the current process and
in the future I hope the HelloWorld program process could be killed,
I'm kind of stuck right now on how.

Right now a complete Command Line command to compile HelloWorld example with a working Command Line Interface looks like this:
> dmd HelloWorld.d whatever.res && start "" "HelloWorld.exe"


whatever.res - look at above posts on how to generate whatever.res

HelloWorld.d

import std.stdio   : write, writeln, readln, writefln;
import std.process : executeShell, kill, thisProcessID;
import core.thread.osthread : getpid;

void main() {
	executeShell("title HelloWorld");
	executeShell("chcp 65001");
    writeln("Hello, World!");
	writeln("
	 ▄ .▄▄▄▄ .▄▄▌  ▄▄▌            ▄▄▌ ▐ ▄▌      ▄▄▄  ▄▄▌  ·▄▄▄▄
	██▪▐█▀▄.▀·██•  ██•  ▪         ██· █▌▐█▪     ▀▄ █·██•  ██▪ ██
	██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄     ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
	██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌    ▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
	▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪     ▀▀▀▀ ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀▀▀▀▀•

");
	writefln("Current process id: %s", getpid());
	writeln("This process id: ", thisProcessID());
	
	string line;
	write("Your Input: ");
	while ((line = readln()) !is null) {
	        writeln(line);
			write("Your Input: ");

			}
}
« First   ‹ Prev
1 2