Skip to content

miyako/4d-class-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

version platform license downloads

LOG EVENT wrapper class.

Note: On older versions of Windows you may need to set the HKEY_CURRENT_USER\Console\VirtualTerminalLevel registry key to 1 to activate Console Virtual Terminal Sequences.

c.f. https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling
see also ytdl-org/youtube-dl#15758

To print unicode to the command prompt on the Windows command prompt you may need to chcp 65001.

8-bit and 16-bit colours

A Simple API to print ASCII escape codes.

var $CLI : cs.CLI

$CLI:=cs.CLI.new()

//foreground
$CLI.print("Hello World"; "red;bold;underline").LF()
//foreground and background
$CLI.print("Hello World"; "red;yellow;bold;underline").LF()

$CLI.LF()

//16-bit color
For ($i; 0; 255)
	$CLI.print(String($i; "^^0"+"   "); String($i)+";bold")
End for 

$CLI.LF()

Progress indicator

var $CLI : cs.CLI

$CLI:=cs.CLI.new()

$CLI.ES().XY(0; 0)

$CLI.hideCursor()

For ($i; 1; 100)
	$CLI.CR().print(String($i; "^^0")+"%%").EL()
	DELAY PROCESS(Current process; 1)
End for 

$CLI.showCursor()

$CLI.LF()

Notes

By default, diagnostic warnings (level 5) are printed to the console in headless mode. To filter these messages from the CLI, you might want to activate the diagnostic log file or else limit the information to errors (level 6).

  • Settings/logConfig.json
{
 "diagnosticLogs":{
		"state" : 1,
		"level" : 6
 }
}

c.f. https://developer.4d.com/docs/Debugging/debugLogFiles

References

Headless 4D applications

Command Line Interface

A Tool for 4D Code Execution in CLI