From a2e8d68c95c36e2b752d7d36c96b6f8489a649d5 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 12 Aug 2024 00:23:17 +0900 Subject: [PATCH] doc: update doc for thread-local colorization --- docs/content.en/docs/reference/color.md | 15 ++++++++++++--- docs/content.ja/docs/reference/color.md | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/content.en/docs/reference/color.md b/docs/content.en/docs/reference/color.md index da1c76f..ba6308f 100644 --- a/docs/content.en/docs/reference/color.md +++ b/docs/content.en/docs/reference/color.md @@ -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()` diff --git a/docs/content.ja/docs/reference/color.md b/docs/content.ja/docs/reference/color.md index 57e9609..6ded48c 100644 --- a/docs/content.ja/docs/reference/color.md +++ b/docs/content.ja/docs/reference/color.md @@ -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()`を実行した場合、その結果は未定義です。 ## 関数