File tree 3 files changed +9
-6
lines changed
clikt/src/main/kotlin/com/github/ajalt/clikt/output
3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,13 @@ object TermUi {
13
13
* This is similar to [print] or [println], but converts newlines to the system line separator.
14
14
*
15
15
* @param message The message to print.
16
- * @param trailingNewline if true, behave like [println], otherwise behave like [print]
16
+ * @param trailingNewline If true, behave like [println], otherwise behave like [print]
17
+ * @param err If true, print to stderr instead of stdout
17
18
*/
18
- fun echo (message : Any? , trailingNewline : Boolean = true) {
19
+ fun echo (message : Any? , trailingNewline : Boolean = true, err : Boolean = false ) {
19
20
val text = message?.toString()?.replace(Regex (" \r ?\n " ), System .lineSeparator()) ? : " null"
20
- if (trailingNewline) println (text) else print (text)
21
+ val ps = if (err) System .err else System .out
22
+ if (trailingNewline) ps.println (text) else ps.print (text)
21
23
}
22
24
23
25
/* *
Original file line number Diff line number Diff line change 9
9
10
10
- title : Basic Concepts
11
11
url : /quickstart.html#basic-concepts
12
- - title : Echoing
12
+ - title : Printing to Stdout and Stderr
13
13
url : /quickstart.html#echoing
14
14
- title : Nesting Commands
15
15
url : /quickstart.html#nesting-commands
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ Options:
42
42
-h, --help Show this message and exit
43
43
```
44
44
45
- ## Echoing
45
+ ## Printing to Stdout and Stderr {#echoing}
46
46
47
47
Why does this example use {% include api.html pkg="output"
48
48
class="term-ui" fun="echo" %} instead of
@@ -52,7 +52,8 @@ support. {% include api.html pkg="output" class="term-ui" fun="echo"
52
52
text="echo"%} automatically translates line breaks into the line
53
53
separator for the current platform. So you don't have to worry that some
54
54
of your users will see mangled output because you didn't test on
55
- Windows.
55
+ Windows. You can also pass ` err=true ` to ` echo ` to print to stderr
56
+ instead of stdout.
56
57
57
58
## Nesting Commands
58
59
You can’t perform that action at this time.
0 commit comments