Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haxiomic/console.hx
A haxe logging utility for easy rich output in both native and browser consoles
https://github.com/haxiomic/console.hx
Last synced: 23 days ago
JSON representation
A haxe logging utility for easy rich output in both native and browser consoles
- Host: GitHub
- URL: https://github.com/haxiomic/console.hx
- Owner: haxiomic
- License: unlicense
- Created: 2015-11-28T17:03:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-22T13:13:47.000Z (about 1 year ago)
- Last Synced: 2024-04-17T21:42:56.334Z (7 months ago)
- Language: Haxe
- Homepage:
- Size: 199 KB
- Stars: 47
- Watchers: 4
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Console.hx is a haxe logging utility for easy rich output in both native and browser consoles via a familiar HTML-like tag syntax. Supports haxe 3 and haxe 4.
For example:
```haxe
Console.log('Don’t> Panic.>');
```This will print in your console something like:
![don't-panic](https://user-images.githubusercontent.com/3742992/62642491-c160c900-b93d-11e9-94ef-a41358e0cf8c.png)
(Depending on your console color settings). This will also work in a browser console when targeting the web. All console output can be disable by passing `-D no_console`.
### Installing
`haxelib install console.hx`
And add
`-lib Console.hx` when compiling your haxe code### API
#### `Console.log(...args)`
`log()` prints all arguments to stdout. String type arguments will have \ processed by the formatter. The log prefix can be configured by setting `Console.logPrefix`.
**Example**
`Console.log('Hello>', 'world')`
\> **Hello** *world*
#### `Console.warn(...args)`
`warn()` prints all arguments to stderr. String type arguments will have \ processed by the formatter. The warn prefix can be configured by setting `Console.warnPrefix`.
#### `Console.error(...args)`
`error()` prints all arguments to stderr. String type arguments will have \ processed by the formatter. By default, errors will be printed in red, the error prefix (including formatting) configured by setting `Console.errorPrefix`.
#### `Console.success(...args)`
`success()` prints all arguments to stdout. String type arguments will have \ processed by the formatter. The success prefix can be configured by setting `Console.successPrefix`.
#### `Console.debug(...args)`
`debug()` output will only appear in the console when the haxe `-debug` flag is set and output is prefixed with the line number like `trace()`. String type arguments will have \ processed by the formatter. The debug prefix can be configured by setting `Console.debugPrefix`.
**Example**
`Console.debug('hello', 'world')`
\> **Main:5:** hello world
#### `Console.examine(...args)`
`examine()` prints variable names alongside their values
**Example**
```haxe
var x = 31.1;
var y = 65.3;
Console.examine(x, y);
```\> **x:** *32.1* **y:** *65.3*
#### `Console.printlnFormatted( string: String, outputStream: Log | Warn | Error | Debug = Log)`
Print a line to the console after processing \ but without a log prefix
#### `Console.println( string: String, outputStream: Log | Warn | Error | Debug = Log)`
Print a line directly to the console without processing formatting \.
### Formatting
- Apply formatting with HTML-like tags: \**bold**\ or \*italic*\
- Close the last tag with shorthand \>: \**bold**> not bold
- A double-closing tag like `/>` will clear all active formatting
- Formatting can be combined into a single tag: \***bold and italic***\>
- Hex colors can be used (including CSS shorthand form), for example
- `<#FF0000>Red Text>`
- `Red Background>`
- Whitespace is not allowed in tags, so `` would be ignored and printed as-is
- Tags can be escaped with a leading backslash: `\` would be printed as ``
- CSS can be used when targeting web browsers: for example: `<{color: red; font-size: 20px}>Inline CSS>`. These will have no affect on native consoles### Available Tags
| Tag Name | Description |
| :--------------------------: | :-----------------------------------: |
| ``, `/>` | Clear all previous formatting |
| `>` | Close last open formatting |
| ``, `` | Format as bold |
| ``, `` | Format as italic |
| `` | Dimmed color |
| ``, `` | Underline |
| `` | Blink (*Native console only*) |
| ``, `` | Invert colors (*Native console only*) |
| `` | Hide text (*Native console only*) |
| `<#FF0000>` | Use hex for text color |
| `` | Use hex for background color |
| `` | Black text color |
| `` | Red text color |
| `` | Green text color |
| `` | Yellow text color |
| `` | Blue text color |
| `` | Magenta text color |
| `` | Cyan text color |
| `` | White text color |
| ``, `` | Light black text color / gray |
| `` | Light red text color |
| `` | Light green text color |
| `` | Light yellow text color |
| `` | Light blue text color |
| `` | Light magenta text color |
| `` | Light cyan text color |
| `` | Light white text color |
| `` | Text background black |
| `` | Text background red |
| `` | Text background green |
| `` | Text background yellow |
| `` | Text background blue |
| `` | Text background magenta |
| `` | Text background cyan |
| `` | Text background white |
| ``, `` | Text background light black / gray |
| `` | Text background light red |
| `` | Text background light green |
| `` | Text background light yellow |
| `` | Text background light blue |
| `` | Text background light magenta |
| `` | Text background light cyan |
| `` | Text background light white |### Supported Targets
Formatting should work on mac, linux and browser consoles for all targets, however for built-in Windows consoles like Command Prompt and PowerShell, only Neko and C++ will produce colored output (assuming you're running a fairly recent build of Windows 10)
| Target | Platform | Supported |
| :----------------------------: | :---------------------: | :--------: |
| JS | Chrome, Firefox, Safari | ✔ |
| JS, C++, Neko, PHP, Python, HL | MacOS | ✔ |
| JS, C++, Neko, PHP, Python, HL | Linux Common Terminals | ✔ |
| C++, Neko | Windows Command Prompt | ✔ |