Author Topic: How can I send escape key sequences to console from QB64?  (Read 4172 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
How can I send escape key sequences to console from QB64?
« on: October 25, 2019, 03:30:50 pm »
I have a program written in QB64 that displays information to a Windows command prompt console so it contains the following lines:

$CONSOLE:ONLY
_DEST _CONSOLE

I would like to set display attributes by sending escape key sequences. As an example, sending the sequence <Esc>[1;31m sets the foreground text color to bold red. Does anyone know how I could send such a key sequence to the console from QB64?

I tried this as an example, but it does not work:

print chr$(27);"[1;31m"

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #1 on: October 25, 2019, 03:41:16 pm »
If it works from the command line then try RUNing it or SHELLing it or writing and run a .bat file from QB64.

You might have to enclose things with CHR$(34) for double quotes and use CHR$(27) for escape.

wait... are you trying for color from a console program?
Steve might have that covered.
https://www.qb64.org/forum/index.php?topic=1589.0
« Last Edit: October 25, 2019, 03:58:48 pm by bplus »

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #2 on: October 25, 2019, 04:00:32 pm »
I wish it were that simple. apparently sending ANSI escape key sequences at a command line is a very difficult thing to do as well. There are some weird tricks I've read about that involve methods of getting an escape character into a document and then displaying that text.

I was hoping that someone might happen to know of some trick I was not aware of.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #3 on: October 26, 2019, 10:28:28 am »
You might look into _SCREENPRINT.
http://www.qb64.org/wiki/SCREENPRINT
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #4 on: October 26, 2019, 11:30:12 am »
Quote
I have a program written in QB64 that displays information to a Windows command prompt console so it contains the following lines:

$CONSOLE:ONLY
_DEST _CONSOLE

"displays information to a Windows command prompt"

How can a QB64 program talk to Windows through a PRINT command?

I do know SmallBASIC can or could use escape codes but that was an interpreter that might have more direct access to Windows through it's C code.

I wonder if we could see the program?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How can I send escape key sequences to console from QB64?
« Reply #5 on: October 26, 2019, 11:45:58 am »
"displays information to a Windows command prompt"

How can a QB64 program talk to Windows through a PRINT command?

Wouldn’t you just use the SHELL command for this? 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #6 on: October 26, 2019, 12:17:49 pm »
Wouldn’t you just use the SHELL command for this? 

Ha! I tried that in reply #1!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #7 on: October 28, 2019, 03:58:35 pm »
Rather than place the whole program here, I'll simply place a sample since my current code is almost 7000 line long :-)

$CONSOLE:ONLY
_DEST _CONSOLE

PRINT "Hello World!"
PRINT
INPUT "Press ENTER to end the program",a
SYSTEM

All that this program does is display "Hello World!" to the Windows command prompt console.

My reason for doing this is simply that the entire reason for the existence of my program is to run a very large number of Windows command line commands, while also gathering input from a user and then generating all the commands that will need to be run. Because those commands will output information to the Windows command prompt console, I want the entire QB64 program to display its text to that console. As an example, it might look something like this

Display prompts to user in the Windows command line window and get input from the user, entirely within that Window.
Display a message on the screen from the QB64 program that says "We are now performing operation blah, blah, blah"
shell "some windows command"
Windows command line utility displays status information

The whole program is complete and working wonderfully, but as you can imagine, in a program that is 7000 line long, there are some messages where I want to highlight specific text output to the console for a better user experience rather than displaying every little detail all in monochrome. That is where the escape key sequences come in, because with them you can change color attributes.

It's not critical, it was just something I had hoped to be able to figure out a way to accomplish.



Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How can I send escape key sequences to console from QB64?
« Reply #8 on: October 28, 2019, 04:18:06 pm »
If you download the development build, you can just use the COLOR statement with the console, along with all the other changes I pushed recently.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #9 on: October 28, 2019, 07:29:52 pm »
Fantastic! I'm going to give this a try. Thanks for pointing me to this.


Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #10 on: October 28, 2019, 07:55:09 pm »
Steve, I just tried a couple of the console enhancements and I can't even begin to tell you how thrilled I am with this.

I saw your note indicating how tired you are of working with console enhancements that you will probably never even use but please know just how much this particular user appreciates the efforts. This is going to make a HUGE impact in my program!

BTW, I'm 100% fine with using a dev build, but I'm just curious; any comment on a rough timeframe when the next official release will be or is that something you don't comment on?

In any case, thank you again. This is going to make an incredible world of difference for me.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How can I send escape key sequences to console from QB64?
« Reply #11 on: October 28, 2019, 07:59:42 pm »
:D and what did I say in reply #1? 

Glad you found happiness for a minute :D