Search…
Displaying information
DCli provides a number of methods to display information to a user:

print

Dart provides the built in function 'print' which prints a line of text including a new line.
1
print('hello world');
Copied!

printerr

The standard Dart 'print' function prints to stdout, DCli's 'printerr' function is identical except that it prints to stderr.
1
printerr('something bad happened.');
Copied!
You should use printerr when you are printing error messages.

echo

The echo function is provided to supplement the Dart print method. The 'echo' allows you to control whether a new line is output after the text. By default echo will NOT output a newline.
1
echo('hello', newline: false);
Copied!

Colour coding

DCli allows you colour code your text output.
1
print(orange('hello world'));
Copied!
You can also control the background colour:
1
print(orange('hello world', background: AnsiColor.white));
Copied!
The following colours are supported for both the foreground (text) and background colours.
  • red
  • black
  • green
  • blue
  • yellow
  • magenta
  • cyan
  • white
  • orange
  • grey
By default the bold attribute is attached to each of the above builtin colours. You can suppress the bold attribute:
1
print(red('a dark message', bold: false));
Copied!

Format.row

This method is considered experimental. Use at your own peril.
The row method allows you to output a row of fixed with columns with controlled alignment.
1
print(Format.row(['OS Version', '${Platform.operatingSystemVersion}'],
2
widths: [17, -1]));
Copied!
Outputs a row with two columns. The first is 17 characters wide, the second expands as needed.
1
print(Format.row([
2
'$label',
3
'${fstat.modeString()}',
4
'<user>:${(owner.group == owner.user ? '<user>' : owner.group)}',
5
'${privatePath(path)} '
6
], widths: [
7
17,
8
9,
9
16,
10
-1
11
], alignments: [
12
TableAlignment.left,
13
TableAlignment.left,
14
TableAlignment.middle,
15
TableAlignment.left
16
]));
Copied!
Outputs a row with four columns of widths 17, 9, 16 and infinite. The columns are aligned, left, right, middle and left.

clearScreen

Clears the console.
1
clearScreen();
Copied!

clearLine

Clears the current line.
1
clearLine();
Copied!

startOfLine

Moves the cursor to the start of the current line.
1
startOfLine;
Copied!

previousLine

Moves the cursor to the start of the previous line.

showCursor

Shows or hides the cursor.
1
showCursor(show: true);
Copied!

column

Moves the cursor to the given column on the current line.
Last modified 1mo ago