Skip to content

Commit 7c2bb22

Browse files
committed
added a few new features; adjusted the namespaces where some functions are located
1 parent 83d62ed commit 7c2bb22

File tree

3 files changed

+266
-187
lines changed

3 files changed

+266
-187
lines changed

docs/QuickStart.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ assert( bar.config().bar_length() == 30 ); // default value
275275
assert( bar.config().fixed_length() != 0 ); // The exact value depends on the content of the data member
276276
```
277277

278-
The specific terminal line width (in characters) can be obtained using `pgbar::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
278+
The specific terminal line width (in characters) can be obtained using `pgbar::config::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
279279

280280
> If the running platform is neither `Windows` nor `Unix-like`, then this function will only return a fixed value of 100.
281281

282282
```cpp
283-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
284-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
283+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
284+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
285285
// At this point, the progress bar can exactly fill one line.
286286
```
287287
#### Data configuration
@@ -356,8 +356,6 @@ int main()
356356
```
357357

358358
Especially it is important to note that the binding to the same output stream objects are not allowed to run at the same time, otherwise it will throw an exception `pgbar::exception::InvalidState`; For a detailed explanation of this, see [FAQ - Design of renderer](#design-of-renderer).
359-
360-
If the output stream is not bound to the terminal, the progress bar will not be rendered. You can see this in [Global configuration - Output stream detection](#output-stream-detection).
361359
#### Rendering strategy
362360
There are two ways for `ProgressBar` to render the progress bar to the terminal: synchronously (`pgbar::Policy::Sync`) or asynchronously (`pgbar::Policy::Async`); different rendering strategies will hand over the rendering behavior to different threads for execution.
363361

@@ -695,13 +693,13 @@ assert( bar.config().bar_length() == 30 ); // default value
695693
assert( bar.config().fixed_length() != 0 ); // The exact value depends on the content of the data member
696694
```
697695

698-
The specific terminal line width (in characters) can be obtained using `pgbar::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
696+
The specific terminal line width (in characters) can be obtained using `pgbar::config::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
699697

700698
> If the running platform is neither `Windows` nor `Unix-like`, then this function will only return a fixed value of 100.
701699

702700
```cpp
703-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
704-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
701+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
702+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
705703
// At this point, the progress bar can exactly fill one line.
706704
```
707705
#### Data configuration
@@ -774,8 +772,6 @@ int main()
774772
```
775773

776774
Especially it is important to note that the binding to the same output stream objects are not allowed to run at the same time, otherwise it will throw an exception `pgbar::exception::InvalidState`; For a detailed explanation of this, see [FAQ - Design of renderer](#design-of-renderer).
777-
778-
If the output stream is not bound to the terminal, the progress bar will not be rendered. You can see this in [Global configuration - Output stream detection](#output-stream-detection).
779775
#### Rendering strategy
780776
There are two ways for `BlockBar` to render the progress bar to the terminal: synchronously (`pgbar::Policy::Sync`) or asynchronously (`pgbar::Policy::Async`); different rendering strategies will hand over the rendering behavior to different threads for execution.
781777

@@ -1118,13 +1114,13 @@ assert( bar.config().bar_length() == 30 ); // default value
11181114
assert( bar.config().fixed_length() != 0 ); // The exact value depends on the content of the data member
11191115
```
11201116

1121-
The specific terminal line width (in characters) can be obtained using `pgbar::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
1117+
The specific terminal line width (in characters) can be obtained using `pgbar::config::terminal_width()`. If the passed output stream does not point to an actual terminal device, the return value will be 0.
11221118

11231119
> If the running platform is neither `Windows` nor `Unix-like`, then this function will only return a fixed value of 100.
11241120

11251121
```cpp
1126-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
1127-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
1122+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
1123+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
11281124
// At this point, the progress bar can exactly fill one line.
11291125
```
11301126
#### Data configuration
@@ -1197,8 +1193,6 @@ int main()
11971193
```
11981194

11991195
Especially it is important to note that the binding to the same output stream objects are not allowed to run at the same time, otherwise it will throw an exception `pgbar::exception::InvalidState`; For a detailed explanation of this, see [FAQ - Design of renderer](#design-of-renderer).
1200-
1201-
If the output stream is not bound to the terminal, the progress bar will not be rendered. You can see this in [Global configuration - Output stream detection](#output-stream-detection).
12021196
#### Rendering strategy
12031197
There are two ways for `SweepBar` to render the progress bar to the terminal: synchronously (`pgbar::Policy::Sync`) or asynchronously (`pgbar::Policy::Async`); different rendering strategies will hand over the rendering behavior to different threads for execution.
12041198

@@ -1588,8 +1582,6 @@ int main()
15881582
```
15891583

15901584
Especially it is important to note that the binding to the same output stream objects are not allowed to run at the same time, otherwise it will throw an exception `pgbar::exception::InvalidState`; For a detailed explanation of this, see [FAQ - Design of renderer](#design-of-renderer).
1591-
1592-
If the output stream is not bound to the terminal, the progress bar will not be rendered. You can see this in [Global configuration - Output stream detection](#output-stream-detection).
15931585
#### Rendering strategy
15941586
There are two ways for `SpinBar` to render the progress bar to the terminal: synchronously (`pgbar::Policy::Sync`) or asynchronously (`pgbar::Policy::Async`); different rendering strategies will hand over the rendering behavior to different threads for execution.
15951587

@@ -1944,7 +1936,7 @@ int main()
19441936
pgbar::DynamicBar<> dbar;
19451937

19461938
auto bar1 = dbar.insert<pgbar::ProgressBar<>>();
1947-
// bar1, bar2, bar3 are all objects of type std::shared_ptr</* ProgressBar */>.
1939+
// bar1, bar2 are all objects of type std::shared_ptr</* ProgressBar */>.
19481940
auto bar2 = dbar.insert(
19491941
pgbar::config::Line( pgbar::option::Prefix( "No.2" ), pgbar::option::Tasks( 8000 ) ) );
19501942

@@ -2102,17 +2094,21 @@ Given that `stdout` and `stderr` are redirected to other files, `pgbar` also che
21022094

21032095
`pgbar` supports checking output stream bindings for Windows and unix-like (actually POSIX-compliant) platforms; For non-Windows and unix-like platforms, `pgbar` will not recognize whether the output stream is bound to the terminal.
21042096

2105-
When `pgbar` finds that an output stream does not point to the terminal, all progress bars pointing to the output stream will not output any information, but the internal exception check work is normal.
2097+
When `pgbar` detects that an output stream is not directed to a terminal, the coloring effect of all progress bars pointing to that output stream will be automatically disabled, and no additional virtual terminal sequence strings for manipulating the terminal cursor will be inserted.
2098+
2099+
Whether the coloring effect is automatically turned off or not can be enabled or disabled by the `pgbar::config::disable_styling()` function.
2100+
2101+
When it is enabled (that is, by default), if the progress bar detects that the output stream it is in does not point to a terminal device, it will call the `colored()` and `bolded()` methods of the configuration object to turn off color and font effects.
21062102

2107-
You can also call the `intty()` method in namespace `pgbar` to check if an output stream is pointing to a terminal.
2103+
You can also call the `intty()` method in namespace `pgbar::config` to check if an output stream is pointing to a terminal.
21082104

21092105
```cpp
21102106
#include "pgbar/pgbar.hpp"
21112107
#include <iostream>
21122108

21132109
int main()
21142110
{
2115-
if ( pgbar::intty( pgbar::Channel::Stdout ) )
2111+
if ( pgbar::config::intty( pgbar::Channel::Stdout ) )
21162112
std::cout << "Standard output is bound to a terminal." << std::endl;
21172113
else
21182114
std::cout << "Standard output is not bound to a terminal." << std::endl;

docs/QuickStart_zh.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ assert( bar.config().bar_length() == 30 ); // 默认值
275275
assert( bar.config().fixed_length() != 0 ); // 具体值取决于数据成员的内容
276276
```
277277

278-
具体的终端行宽度(以字符为单位)可以使用 `pgbar::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
278+
具体的终端行宽度(以字符为单位)可以使用 `pgbar::config::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
279279

280280
> 如果运行平台既不是 `Windows` 也不是 `unix-like`,那么该函数只会返回一个固定值 100。
281281

282282
```cpp
283-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
284-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
283+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
284+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
285285
// 此时进度条恰能填满一行
286286
```
287287
#### 数据配置
@@ -356,8 +356,6 @@ int main()
356356
```
357357

358358
特别需要注意的是,绑定到相同输出流上的对象不允许同时运行,否则会抛出异常 `pgbar::exception::InvalidState`;关于这一点的详细说明见 [FAQ-渲染器设计](#渲染器设计)。
359-
360-
如果指向的输出流并没有被绑定到终端上,那么这个进度条并不会被渲染;这一点可以详见 [全局设置-输出流检测](#输出流检测)。
361359
#### 渲染策略
362360
`ProgressBar` 将进度条渲染到终端的方式有两种:同步(`pgbar::Policy::Sync`)或异步(`pgbar::Policy::Async`);不同的渲染策略会将渲染行为交给不同的线程执行。
363361

@@ -695,13 +693,13 @@ assert( bar.config().bar_length() == 30 ); // 默认值
695693
assert( bar.config().fixed_length() != 0 ); // 具体值取决于数据成员的内容
696694
```
697695

698-
具体的终端行宽度(以字符为单位)可以使用 `pgbar::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
696+
具体的终端行宽度(以字符为单位)可以使用 `pgbar::config::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
699697

700698
> 如果运行平台既不是 Windows 也不是 unix-like,那么该函数只会返回一个固定值 100。
701699

702700
```cpp
703-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
704-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
701+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
702+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
705703
// 此时进度条恰能填满一行
706704
```
707705
#### 数据配置
@@ -774,8 +772,6 @@ int main()
774772
```
775773

776774
特别需要注意的是,绑定到相同输出流上的对象不允许同时运行,否则会抛出异常 `pgbar::exception::InvalidState`;关于这一点的详细说明见 [FAQ-渲染器设计](#渲染器设计)。
777-
778-
如果指向的输出流并没有被绑定到终端上,那么这个进度条并不会被渲染;这一点可以详见 [全局设置-输出流检测](#输出流检测)。
779775
#### 渲染策略
780776
`BlockBar` 将进度条渲染到终端的方式有两种:同步(`pgbar::Policy::Sync`)或异步(`pgbar::Policy::Async`);不同的渲染策略会将渲染行为交给不同的线程执行。
781777

@@ -1118,13 +1114,13 @@ assert( bar.config().bar_length() == 30 ); // 默认值
11181114
assert( bar.config().fixed_length() != 0 ); // 具体值取决于数据成员的内容
11191115
```
11201116

1121-
具体的终端行宽度(以字符为单位)可以使用 `pgbar::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
1117+
具体的终端行宽度(以字符为单位)可以使用 `pgbar::config::terminal_width()` 获取;如果传递的输出流不指向实际终端设备,那么返回值为 0。
11221118

11231119
> 如果运行平台既不是 Windows 也不是 unix-like,那么该函数只会返回一个固定值 100。
11241120

11251121
```cpp
1126-
assert( pgbar::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
1127-
bar.bar_length( pgbar::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
1122+
assert( pgbar::config::terminal_width( pgbar::Channel::Stdout ) > bar.config().fixed_length() );
1123+
bar.bar_length( pgbar::config::terminal_width( pgbar::Channel::Stdout ) - bar.config().fixed_length() );
11281124
// 此时进度条恰能填满一行
11291125
```
11301126
#### 数据配置
@@ -1197,8 +1193,6 @@ int main()
11971193
```
11981194

11991195
特别需要注意的是,绑定到相同输出流上的对象不允许同时运行,否则会抛出异常 `pgbar::exception::InvalidState`;关于这一点的详细说明见 [FAQ-渲染器设计](#渲染器设计)。
1200-
1201-
如果指向的输出流并没有被绑定到终端上,那么这个进度条并不会被渲染;这一点可以详见 [全局设置-输出流检测](#输出流检测)。
12021196
#### 渲染策略
12031197
`SweepBar` 将进度条渲染到终端的方式有两种:同步(`pgbar::Policy::Sync`)或异步(`pgbar::Policy::Async`);不同的渲染策略会将渲染行为交给不同的线程执行。
12041198

@@ -1589,8 +1583,6 @@ int main()
15891583
```
15901584

15911585
特别需要注意的是,绑定到相同输出流上的对象不允许同时运行,否则会抛出异常 `pgbar::exception::InvalidState`;关于这一点的详细说明见 [FAQ-渲染器设计](#渲染器设计)。
1592-
1593-
如果指向的输出流并没有被绑定到终端上,那么这个进度条并不会被渲染;这一点可以详见 [全局设置-输出流检测](#输出流检测)。
15941586
#### 渲染策略
15951587
`SpinBar` 将进度条渲染到终端的方式有两种:同步(`pgbar::Policy::Sync`)或异步(`pgbar::Policy::Async`);不同的渲染策略会将渲染行为交给不同的线程执行。
15961588

@@ -1900,8 +1892,8 @@ int main()
19001892

19011893
auto mbar = pgbar::make_multi( pgbar::ProgressBar<>( pgbar::option::Tasks( 2 ) ),
19021894
pgbar::BlockBar<>( pgbar::option::Tasks( 3 ) ) );
1903-
19041895
auto& [bar1, bar2] = mbar;
1896+
19051897
bar1.tick();
19061898
bar2.tick();
19071899

@@ -1941,7 +1933,7 @@ int main()
19411933
pgbar::DynamicBar<> dbar;
19421934

19431935
auto bar1 = dbar.insert<pgbar::ProgressBar<>>();
1944-
// bar1, bar2, bar3 都是 std::shared_ptr</* ProgressBar */> 类型的对象
1936+
// bar1, bar2 都是 std::shared_ptr</* ProgressBar */> 类型的对象
19451937
auto bar2 = dbar.insert(
19461938
pgbar::config::Line( pgbar::option::Prefix( "No.2" ), pgbar::option::Tasks( 8000 ) ) );
19471939

@@ -2095,17 +2087,21 @@ int main()
20952087

20962088
`pgbar` 支持检查 Windows 和 unix-like(实际上是支持 POSIX 标准的)平台的输出流绑定;对于非 Windows 和 unix-like 平台,`pgbar` 将无法识别输出流是否绑定在终端上。
20972089

2098-
当 `pgbar` 发现某个输出流并不指向终端时,所有指向该输出流的进度条都不会对外输出任何信息,但是内部的异常检查工作是正常进行的。
2090+
当 `pgbar` 发现某个输出流并不指向终端时,所有指向该输出流的进度条的着色效果都会被自动关闭,并且也不会再额外插入用于操纵终端光标的虚拟终端序列字符串。
2091+
2092+
着色效果的自动关闭与否可以由 `pgbar::config::disable_styling()` 函数开启或关闭。
2093+
2094+
在开启时(也就是默认情况),若进度条发现它所处的输出流并没有指向一个终端设备,就会调用配置对象的 `colored()` 和 `bolded()` 方法以关闭着色和字体效果。
20992095

2100-
你也可以调用在名称空间 `pgbar` 中的 `intty()` 方法检查某个输出流是否指向终端。
2096+
你也可以调用在名称空间 `pgbar::config` 中的 `intty()` 方法检查某个输出流是否指向终端。
21012097

21022098
```cpp
21032099
#include "pgbar/pgbar.hpp"
21042100
#include <iostream>
21052101

21062102
int main()
21072103
{
2108-
if ( pgbar::intty( pgbar::Channel::Stdout ) )
2104+
if ( pgbar::config::intty( pgbar::Channel::Stdout ) )
21092105
std::cout << "Standard output is bound to a terminal." << std::endl;
21102106
else
21112107
std::cout << "Standard output is not bound to a terminal." << std::endl;

0 commit comments

Comments
 (0)