doc: update doc for thread-local colorization

This commit is contained in:
ToruNiina
2024-08-12 00:23:17 +09:00
parent 9b58c7e321
commit a2e8d68c95
2 changed files with 24 additions and 6 deletions

View File

@@ -12,14 +12,23 @@ In terminals or other output destinations that do not support ANSI escape code,
## Macros
```cpp
TOML11_COLORIZE_ERROR_MESSAGE
```
### `TOML11_COLORIZE_ERROR_MESSAGE`
If this macro is defined during compilation (`-DTOML11_COLORIZE_ERROR_MESASGE`), error messages are colored by default.
If not defined, colors are not applied by default. You need to specify them using `toml::color::enable()`.
### `TOML11_USE_THREAD_LOCAL_COLORIZATION`
If this macro is defined during compilation (`-DTOML11_USE_THREAD_LOCAL_COLORIZATION`), the colorization flag becomes `thread_local`.
In this case, `toml::color::enable()` or `toml::color::disable()` will only affect the colorization flag in the thread that called it.
This means that if you want to use a different setting from the default, you will need to set it again when starting a new thread.
This makes `toml::color::enable()` and `toml::color::disable()` thread safe.
By default, the setting is global.
When it is global, if one thread executes `toml::color::enable()`, the error messages will be colored in all threads.
However, if one thread executes `enable()` or `disable()` while another executes `enable()`, `disable()` or `should_color()`, the result is undefined.
## Functions
### `enable()`

View File

@@ -12,9 +12,7 @@ ANSIエスケープシーケンスをサポートしていないターミナル
## マクロ
```cpp
TOML11_COLORIZE_ERROR_MESSAGE
```
### `TOML11_COLORIZE_ERROR_MESSAGE`
コンパイル時にこのマクロが定義されていた場合(`-DTOML11_COLORIZE_ERROR_MESASGE`)、
デフォルトでエラーメッセージに色が付きます。
@@ -22,6 +20,17 @@ TOML11_COLORIZE_ERROR_MESSAGE
定義されていなかった場合、デフォルトでは色は付きません。以下の `toml::color::enable()`
使用して指定する必要があります。
### `TOML11_USE_THREAD_LOCAL_COLORIZATION`
コンパイル時にこのマクロが定義されていた場合(`-DTOML11_COLORIZE_ERROR_MESASGE`)、
`toml::color::enable`の設定が`thread_local`になります。
この場合、`toml::color::enable()``toml::color::disable()`は、それを呼び出したスレッドでの設定しか変更しません。
つまり、新しいスレッドを起動した際にデフォルトと異なる設定にしたい場合は、再度設定が必要になります。
その代わり、`toml::color::enable()``toml::color::disable()`はスレッドセーフになります。
デフォルトでは設定はグローバルです。
グローバルの場合、一つのスレッドが`toml::color::enable()`を実行した場合、すべてのスレッドで色が付きます。
ただし、あるスレッドが`enable()`または`disable()`を実行している間に別のスレッドが`enable()``disable()``should_color()`を実行した場合、その結果は未定義です。
## 関数