Re: Spawn a Command Line application Window and output log information

2020-05-23 Thread BoQsc via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 10:05:00 UTC, BoQsc wrote:

On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote:


I'm kind of stuck right now on how.



Some more Updates and it seems that it is impossible to scroll 
the history of the output.




Some relevant discussion: 
https://stackoverflow.com/a/5779422/3789797




Re: Spawn a Command Line application Window and output log information

2020-05-19 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote:


I'm kind of stuck right now on how.



Some more Updates and it seems that it is impossible to scroll 
the history of the output.



import std.stdio   : write, writeln, readln, writefln;
import std.process : spawnShell, wait, executeShell, kill, 
thisProcessID;

import core.thread.osthread : getpid;
import std.process : environment;
import std.file : getcwd;
import std.file : thisExePath;

void main() {
spawnShell( "cls" ).wait;
executeShell("title HelloWorld");
executeShell("chcp 65001");
executeShell("mode con: cols=120 lines=30");




writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•
The Adventures of HelloWorld");
writeln("
   ┌──┐
   ▒░░░┼┐ ≡▒░ ¦
___▒▒┼┤┼▒▒▓");

writeln("
   ~¨(··)¸
 <│ >
‗┌═¬‗´
  ");

writeln("Path to executable and the filename: ", thisExePath());
writeln("Current Working Directory: ", getcwd());
writeln();
writeln("Accessible files from these Environment Paths");
writeln(environment["PATH"]);
writeln();
	writeln("Access TEMP environmental variable: ", 
environment.get("TEMP"));

writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
if (line == "exit\x0a") {
writeln("Going down");
return;
}
write(line);
write("Your Input: ");
}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

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: ");

}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

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/enrmidvsfdugqmudo...@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   ICONDISCARDABLE "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=Elite=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);
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

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.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

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/enrmidvsfdugqmudo...@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   ICONDISCARDABLE "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.






Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

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);
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

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.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

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.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

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.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Panke via Digitalmars-d-learn

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.


Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn
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?