#tui #ratatui #widgets #widget

tui-scrollview

A simple scrollable view for Ratatui

10 releases

new 0.3.1 Feb 13, 2024
0.3.0 Feb 11, 2024
0.2.1 Jan 30, 2024
0.1.5 Jan 18, 2024

#387 in Command-line interface

Download history 207/week @ 2024-01-15 40/week @ 2024-01-22 53/week @ 2024-01-29 38/week @ 2024-02-05 120/week @ 2024-02-12

251 downloads per month

MIT/Apache

21KB
199 lines

Tui-scrollview

Crates.io Badge License Badge Docs.rs Badge
Deps.rs Badge Codecov.io Badge Discord Badge

tui-scrollview is a library for creating scrollable views in Ratatui.

Installation

cargo add tui-scrollview

Usage

use std::iter;
use tui_scrollview::{ScrollView, ScrollViewState};
use ratatui::{layout::Size, prelude::*, widgets::*};

fn render(frame: &mut Frame) {
    let size = Size::new(10, 100);
    let mut scroll_view = ScrollView::new(size);
    let some_long_string =
        iter::repeat("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n")
           .take(100)
           .collect::<String>();
    let area = Rect::new(0, 0, 10, 100);
    scroll_view.render_widget(Paragraph::new(some_long_string), area);
    let mut state = ScrollViewState::default();
    frame.render_stateful_widget(scroll_view, area, &mut state);
}

Example

This example shows a scrollable view with two paragraphs of text, one for the line numbers and one for the text. On top of this a Gauge widget is rendered to show that this can be used in combination with any other widget.

Demo

scrollview.rs

TODO

  • Conditionally show scrollbar
  • Implement horizontal scrolling and bar

License

Copyright (c) 2024 Josh McKinney

This project is licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.

Dependencies

~5–12MB
~114K SLoC