Struct fltk::group::experimental::BuffRow
source · pub struct BuffRow<'a> {
pub length: usize,
pub char_size: usize,
/* private fields */
}
Expand description
Class to read characters from the terminal’s buffer rows. Includes indexing access and iterators
Fields§
§length: usize
Number of characters in the row
char_size: usize
sizeof(Fl_Terminal::Utf8Char)
Implementations§
source§impl<'a> BuffRow<'a>
impl<'a> BuffRow<'a>
sourcepub fn new(ptr: *const Fl_Terminal_Utf8Char, parent: &'a Terminal) -> Self
pub fn new(ptr: *const Fl_Terminal_Utf8Char, parent: &'a Terminal) -> Self
Generate a new BuffRow object based on a pointer from C++ Fl_Terminal
sourcepub fn trim(self) -> Self
pub fn trim(self) -> Self
Trim trailing blanks off of BuffRow object. Does not affect the data in the RingBuff, just this object’s access.
Examples found in repository?
examples/terminal.rs (line 580)
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
fn read_disp(term: &Terminal) -> String {
let rows = term.display_rows();
let mut text: Vec<u8> = Vec::with_capacity((rows * 64) as usize);
for row in 0..rows {
let r = term.u8c_disp_row(row).trim();
// Iterate through a row, accumulating [u8]
for c in r.iter() {
// Note: Sometimes utf-8 length is > 1
text.extend_from_slice(c.text_utf8());
}
text.extend_from_slice(b"\n");
}
// Return the result as a string
std::str::from_utf8(&text).unwrap().to_string()
}
sourcepub fn col(&self, idx: usize) -> Utf8Char
pub fn col(&self, idx: usize) -> Utf8Char
Index into row array of Utf8Char
Examples found in repository?
examples/terminal.rs (line 604)
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
fn mb_test4_cb(_choice: &mut fltk::menu::Choice, term: &mut Terminal) {
// Test the Utf8Char primitive
let uc = Utf8Char::new(b'Q');
let uc1 = uc.text_utf8();
assert_eq!(&uc1, &[b'Q']);
assert_eq!(&uc.attrib(), &Attrib::Normal);
assert_eq!(
&uc.charflags(),
&(CharFlags::FG_XTERM | CharFlags::BG_XTERM)
);
assert_eq!(&uc.fgcolor(), &Color::XtermWhite);
assert_eq!(&uc.bgcolor(), &Color::TransparentBg);
let ring_rows = term.ring_rows();
// println!();
// dbg!(term.disp_srow(), term.disp_erow(), term.disp_rows(), term.ring_cols(), term.ring_srow(), term.ring_erow() );
// dbg!(term.hist_srow(), term.hist_erow(), term.hist_rows(), ring_rows );
// dbg!(term.offset(), term.hist_use_srow(), term.hist_use() );
term.take_focus().unwrap();
term.clear_history();
assert_eq!(term.history_use(), 0);
// Subtract row numbers, modulo `rows`
fn row_diff(rows: i32, a: i32, b: i32) -> i32 {
match a - b {
n if n < 0 => n + rows,
n => n
}
}
// disp_srow is always 1 greater than hist_erow, modulo (ring_rows+1)
assert_eq!(row_diff(ring_rows, term.disp_srow(), term.hist_erow()), 1);
assert!(term.disp_srow() >= 0);
assert!(term.disp_erow() >= 0);
assert!(term.hist_srow() >= 0);
assert!(term.hist_erow() >= 0);
assert!(term.offset() >= 0);
assert!(term.disp_srow() <= ring_rows);
assert!(term.disp_erow() <= ring_rows);
assert!(term.hist_srow() <= ring_rows);
assert!(term.hist_erow() <= ring_rows);
assert!(term.offset() <= ring_rows);
assert_eq!(term.ring_srow(), 0);
assert_eq!(term.ring_erow(), ring_rows - 1);
assert_eq!(
row_diff(ring_rows, term.disp_erow(), term.disp_srow()) + 1,
term.disp_rows()
);
assert_eq!(
row_diff(ring_rows, term.hist_erow(), term.hist_srow()) + 1,
term.hist_rows()
);
assert_eq!(term.ring_erow(), term.ring_rows() - 1);
assert_eq!(term.ring_srow(), 0);
// Check the different cols methods, which should all return the same answer
assert!(term.disp_cols() > 10);
assert_eq!(term.disp_cols(), term.ring_cols());
assert_eq!(term.disp_cols(), term.hist_cols());
// Redundant protected vs public methods:
assert_eq!(term.disp_cols(), term.display_columns());
assert_eq!(term.disp_rows(), term.display_rows());
/// Local function to read back all rows from the display into a long string.
/// Does not include scrollback history.
/// Trims trailing blanks on each line
fn read_disp(term: &Terminal) -> String {
let rows = term.display_rows();
let mut text: Vec<u8> = Vec::with_capacity((rows * 64) as usize);
for row in 0..rows {
let r = term.u8c_disp_row(row).trim();
// Iterate through a row, accumulating [u8]
for c in r.iter() {
// Note: Sometimes utf-8 length is > 1
text.extend_from_slice(c.text_utf8());
}
text.extend_from_slice(b"\n");
}
// Return the result as a string
std::str::from_utf8(&text).unwrap().to_string()
}
term.clear();
term.append("Top line ↑ (up-arrow)");
term.set_text_attrib(Attrib::Underline);
term.append(" ");
term.set_text_attrib(Attrib::Normal);
term.append(" \n");
let mut text_out = read_disp(term);
// Trim trailing empty lines
text_out = text_out.trim_end_matches(&"\n\n").to_string();
// The two plain blanks at the end will be trimmed, the two underlined blanks will be retained.
assert_eq!(text_out, "Top line ↑ (up-arrow) \n");
let r = term.u8c_disp_row(0);
assert_eq!(r.col(0).text_utf8(), b"T");
assert_eq!(r.col(10).text_utf8(), b"\xe2\x86\x91"); // UTF-8 up-arrow
assert_eq!(r.col(24).text_utf8(), b" "); // First blank after test text, NOT trimmed
let r = term.u8c_disp_row(1);
assert_eq!(r.col(0).text_utf8(), b" "); // Second row starts with blanks
assert_eq!(r.col(1).text_utf8(), b" "); // Second row is full of blanks
// Clear the screen again, then append test text, then read it back and compare
let test_text =
"The wind was a torrent of darkness among the gusty trees.
The moon was a ghostly galleon tossed upon cloudy seas.
The road was a ribbon of moonlight over the purple moor,
And the highwayman came riding—
Riding—riding—
The highwayman came riding, up to the old inn-door.";
term.clear_history();
term.clear();
let bg_save = term.text_bg_color();
let fg_save = term.text_fg_color();
term.set_text_bg_color(Color::DarkBlue); // Set spooky colors
term.set_text_fg_color(Color::from_rgb(0x40, 0x40, 0xff));
term.append(test_text);
term.set_text_bg_color(bg_save);
term.set_text_fg_color(fg_save);
let mut text_out = read_disp(term);
// Trim trailing empty lines
text_out = text_out.trim_end_matches(&"\n\n").to_string();
assert_eq!(test_text, text_out);
assert_eq!(row_diff(ring_rows, term.disp_srow(), term.hist_erow()), 1);
assert_eq!(term.ring_srow(), 0);
assert_eq!(term.ring_erow(), ring_rows - 1);
assert_eq!(
row_diff(ring_rows, term.disp_erow(), term.disp_srow()) + 1,
term.disp_rows()
);
assert_eq!(
row_diff(ring_rows, term.hist_erow(), term.hist_srow()) + 1,
term.hist_rows()
);
term.append(&format!(
"\n\nScreen has {} rows of {} columns.\n",
term.disp_rows(),
term.disp_cols()
));
term.set_text_attrib(Attrib::Italic);
term.append("Done!");
term.set_text_attrib(Attrib::Normal);
}
sourcepub fn iter(&self) -> BuffRowIter<'_> ⓘ
pub fn iter(&self) -> BuffRowIter<'_> ⓘ
Iterator object to step through a sequence of Utf8Char in a BuffRow
Examples found in repository?
examples/terminal.rs (line 582)
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
fn read_disp(term: &Terminal) -> String {
let rows = term.display_rows();
let mut text: Vec<u8> = Vec::with_capacity((rows * 64) as usize);
for row in 0..rows {
let r = term.u8c_disp_row(row).trim();
// Iterate through a row, accumulating [u8]
for c in r.iter() {
// Note: Sometimes utf-8 length is > 1
text.extend_from_slice(c.text_utf8());
}
text.extend_from_slice(b"\n");
}
// Return the result as a string
std::str::from_utf8(&text).unwrap().to_string()
}
Auto Trait Implementations§
impl<'a> RefUnwindSafe for BuffRow<'a>
impl<'a> !Send for BuffRow<'a>
impl<'a> !Sync for BuffRow<'a>
impl<'a> Unpin for BuffRow<'a>
impl<'a> UnwindSafe for BuffRow<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more