Skip to content

Commit b3ecb7d

Browse files
authored
Merge pull request #120 from grunweg/clearer-docs
More documentation improvements: clarifying behaviour
2 parents 5484ea9 + 60716ea commit b3ecb7d

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

src/term.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Term {
143143
term
144144
}
145145

146-
/// Return a new unbuffered terminal
146+
/// Return a new unbuffered terminal.
147147
#[inline]
148148
pub fn stdout() -> Term {
149149
Term::with_inner(TermInner {
@@ -152,7 +152,7 @@ impl Term {
152152
})
153153
}
154154

155-
/// Return a new unbuffered terminal to stderr
155+
/// Return a new unbuffered terminal to stderr.
156156
#[inline]
157157
pub fn stderr() -> Term {
158158
Term::with_inner(TermInner {
@@ -161,23 +161,23 @@ impl Term {
161161
})
162162
}
163163

164-
/// Return a new buffered terminal
164+
/// Return a new buffered terminal.
165165
pub fn buffered_stdout() -> Term {
166166
Term::with_inner(TermInner {
167167
target: TermTarget::Stdout,
168168
buffer: Some(Mutex::new(vec![])),
169169
})
170170
}
171171

172-
/// Return a new buffered terminal to stderr
172+
/// Return a new buffered terminal to stderr.
173173
pub fn buffered_stderr() -> Term {
174174
Term::with_inner(TermInner {
175175
target: TermTarget::Stderr,
176176
buffer: Some(Mutex::new(vec![])),
177177
})
178178
}
179179

180-
/// Return a terminal for the given Read/Write pair styled-like Stderr.
180+
/// Return a terminal for the given Read/Write pair styled like stderr.
181181
#[cfg(unix)]
182182
pub fn read_write_pair<R, W>(read: R, write: W) -> Term
183183
where
@@ -204,7 +204,7 @@ impl Term {
204204
})
205205
}
206206

207-
/// Return the style for this terminal
207+
/// Return the style for this terminal.
208208
#[inline]
209209
pub fn style(&self) -> Style {
210210
match self.inner.target {
@@ -215,7 +215,7 @@ impl Term {
215215
}
216216
}
217217

218-
/// Return the target of this terminal
218+
/// Return the target of this terminal.
219219
#[inline]
220220
pub fn target(&self) -> TermTarget {
221221
self.inner.target.clone()
@@ -396,48 +396,59 @@ impl Term {
396396
terminal_size(self)
397397
}
398398

399-
/// Move the cursor to row `x` and column `y`.
399+
/// Move the cursor to row `x` and column `y`. Values are 0-based.
400400
#[inline]
401401
pub fn move_cursor_to(&self, x: usize, y: usize) -> io::Result<()> {
402402
move_cursor_to(self, x, y)
403403
}
404404

405-
/// Move the cursor up `n` lines
405+
/// Move the cursor up by `n` lines, if possible.
406+
///
407+
/// If there are less than `n` lines above the current cursor position,
408+
/// the cursor is moved to the top line of the terminal (i.e., as far up as possible).
406409
#[inline]
407410
pub fn move_cursor_up(&self, n: usize) -> io::Result<()> {
408411
move_cursor_up(self, n)
409412
}
410413

411-
/// Move the cursor down `n` lines
414+
/// Move the cursor down by `n` lines, if possible.
415+
///
416+
/// If there are less than `n` lines below the current cursor position,
417+
/// the cursor is moved to the bottom line of the terminal (i.e., as far down as possible).
412418
#[inline]
413419
pub fn move_cursor_down(&self, n: usize) -> io::Result<()> {
414420
move_cursor_down(self, n)
415421
}
416422

417-
/// Move the cursor `n` characters to the left
423+
/// Move the cursor `n` characters to the left, if possible.
424+
///
425+
/// If there are fewer than `n` characters to the left of the current cursor position,
426+
/// the cursor is moved to the beginning of the line (i.e., as far to the left as possible).
418427
#[inline]
419428
pub fn move_cursor_left(&self, n: usize) -> io::Result<()> {
420429
move_cursor_left(self, n)
421430
}
422431

423-
/// Move the cursor `n` characters to the right
432+
/// Move the cursor `n` characters to the right.
433+
///
434+
/// If there are fewer than `n` characters to the right of the current cursor position,
435+
/// the cursor is moved to the end of the current line (i.e., as far to the right as possible).
424436
#[inline]
425437
pub fn move_cursor_right(&self, n: usize) -> io::Result<()> {
426438
move_cursor_right(self, n)
427439
}
428440

429441
/// Clear the current line.
430442
///
431-
/// This positions the cursor at the beginning of the current line.
443+
/// Position the cursor at the beginning of the current line.
432444
#[inline]
433445
pub fn clear_line(&self) -> io::Result<()> {
434446
clear_line(self)
435447
}
436448

437449
/// Clear the last `n` lines before the current line.
438450
///
439-
/// This positions the cursor at the beginning of the first line
440-
/// that was cleared.
451+
/// Position the cursor at the beginning of the first line that was cleared.
441452
pub fn clear_last_lines(&self, n: usize) -> io::Result<()> {
442453
self.move_cursor_up(n)?;
443454
for _ in 0..n {
@@ -449,38 +460,41 @@ impl Term {
449460
}
450461

451462
/// Clear the entire screen.
463+
///
464+
/// Move the cursor to the upper left corner of the screen.
452465
#[inline]
453466
pub fn clear_screen(&self) -> io::Result<()> {
454467
clear_screen(self)
455468
}
456469

457-
/// Clear the entire screen.
470+
/// Clear everything from the current cursor position to the end of the screen.
471+
/// The cursor stays in its position.
458472
#[inline]
459473
pub fn clear_to_end_of_screen(&self) -> io::Result<()> {
460474
clear_to_end_of_screen(self)
461475
}
462476

463-
/// Clear the last `n` chars of the current line.
477+
/// Clear the last `n` characters of the current line.
464478
#[inline]
465479
pub fn clear_chars(&self, n: usize) -> io::Result<()> {
466480
clear_chars(self, n)
467481
}
468482

469-
/// Set the terminal title
483+
/// Set the terminal title.
470484
pub fn set_title<T: Display>(&self, title: T) {
471485
if !self.is_tty {
472486
return;
473487
}
474488
set_title(title);
475489
}
476490

477-
/// Make the cursor visible again
491+
/// Make the cursor visible again.
478492
#[inline]
479493
pub fn show_cursor(&self) -> io::Result<()> {
480494
show_cursor(self)
481495
}
482496

483-
/// Hide the cursor
497+
/// Hide the cursor.
484498
#[inline]
485499
pub fn hide_cursor(&self) -> io::Result<()> {
486500
hide_cursor(self)

0 commit comments

Comments
 (0)