https://github.com/miyako/4d-class-cli
LOG EVENT wrapper class
https://github.com/miyako/4d-class-cli
4d-class tool4d
Last synced: 3 months ago
JSON representation
LOG EVENT wrapper class
- Host: GitHub
- URL: https://github.com/miyako/4d-class-cli
- Owner: miyako
- License: mit
- Created: 2023-03-07T11:10:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-18T16:30:34.000Z (about 2 years ago)
- Last Synced: 2025-02-26T04:16:10.930Z (over 1 year ago)
- Topics: 4d-class, tool4d
- Language: 4D
- Homepage: https://miyako.github.io/4d-class-CLI/
- Size: 1010 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


[](LICENSE)

`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](https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?redirectedfrom=MSDN).
c.f. https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling
see also https://github.com/ytdl-org/youtube-dl/issues/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](https://en.wikipedia.org/wiki/ANSI_escape_code).
```4d
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()
```

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

# Progress indicator
```4d
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
```json
{
"diagnosticLogs":{
"state" : 1,
"level" : 6
}
}
```
c.f. https://developer.4d.com/docs/Debugging/debugLogFiles
# References
[Headless 4D applications](https://blog.4d.com/headless-4d-applications/)
[Command Line Interface](https://developer.4d.com/docs/Admin/cli/)
[A Tool for 4D Code Execution in CLI](https://blog.4d.com/a-tool-for-4d-code-execution-in-cli/)