!PNVJpPVfXjgFKGFolb:matrix.org

Ratatui General

589 Members
A Rust crate for cooking up Terminal User Interfaces https://ratatui.rs21 Servers

Load older messages


SenderMessageTime
2 Jun 2024
@_discord_198253197201113089:t2bot.iokdheepak Just curious buddylindsey, how did you land on the examples page? Did you open Github, see an examples folder, click on the folder and picked a file to open based on the file name? 17:42:39
@_discord_198253197201113089:t2bot.iokdheepak * Just curious buddylindsey, how did you land on the examples page? Did you open Github, see an examples folder, click on the folder and pick a file to open based on the file name? 17:42:54
@_discord_198253197201113089:t2bot.iokdheepak I've opened an issue that will help solve this imo:

https://github.com/ratatui-org/ratatui/issues/1161
17:57:53
@_discord_1037126672543133706:t2bot.iobuddylindsey I do not recall how I knew they were there. I think I was told there are examples in the repo and so I just clicked around looking for things that looked similar to what I was trying to figure out. 18:00:58
@_discord_198253197201113089:t2bot.iokdheepak I've used this before https://crates.io/crates/rustyline 18:01:35
@_discord_452580294331990027:t2bot.iovolitional_decisions This looks very helpful, especially the history and ctrl-C/D features 18:42:42
@_discord_430757239154802700:t2bot.ioartogahr joined the room.21:32:33
@_discord_1178360114097422381:t2bot.iorustypal_18616 Hello everyone ! I have renamed the crate 'ratframe' to 'egui_ratatui' for clarity and discoverability.
I removed unneccesary code and dependencies, there are no API changes, simply rename ratframe to egui_ratatui in all cases.
The old version can be found in the PRE-RENAME branch, it contains the eframe examples which I have cut from this release.
This release only contains bevy and macroquad examples. Absolutely feel free to contact me with any questions.
Find the new version here:

https://github.com/gold-silver-copper/egui_ratatui

https://crates.io/crates/egui_ratatui
22:34:23
3 Jun 2024
@_discord_615829621296070659:t2bot.iodanik999 joined the room.10:07:33
@_discord_615829621296070659:t2bot.iodanik999 use tui::backend::Backend;
use tui::layout::Rect;
use tui::widgets::{Block, Borders, Paragraph};
use tui::style::{Color, Style};
use tui::Frame;
use crossterm::event::KeyCode;

use crate::ui::Component;

pub struct OutputComponent {
pub message: String,
pub scroll_x: u16,
pub scroll_y: u16,
}

impl OutputComponent {
pub fn new() -> Self {
Self {
message: String::new(),
scroll_x: 0,
scroll_y: 0,
}
}
}

impl Component for OutputComponent {
fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect, is_active: bool) {
let block = Block::default()
.borders(Borders::ALL)
.title("Message")
.style(Style::default().fg(if is_active {
Color::Green
} else {
Color::White
}));
let paragraph = Paragraph::new(self.message.clone())
.block(block)
.style(Style::default().fg(Color::Green))
.scroll((self.scroll_y, self.scroll_x));
f.render_widget(paragraph, area);
}

fn keybinds(&mut self, key: KeyCode) {
match key {
KeyCode::Up | KeyCode::Char('k') | KeyCode::Char('K') => {
if self.scroll_y > 0 {
self.scroll_y -= 1;
}
}
KeyCode::Down | KeyCode::Char('j') | KeyCode::Char('J')=> {
self.scroll_y += 1;
}
KeyCode::Left | KeyCode::Char('h') | KeyCode::Char('H') => {
if self.scroll_x > 0 {
self.scroll_x -= 1;
}
}
KeyCode::Right | KeyCode::Char('l') | KeyCode::Char('L') => {
self.scrollx += 1;
}
=> {}
}
}
} hey guys i need to add scrollbar to right corner do you have any ideas how can i do it?
12:30:07
@_discord_638733632604733458:t2bot.ioorhunp you can render a [Scrollbar widget](https://docs.rs/ratatui/latest/ratatui/widgets/struct.Scrollbar.html) as follows:

let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
    .begin_symbol(Some("↑"))
    .end_symbol(Some("↓"));

let mut scrollbar_state = ScrollbarState::new(/* items len */).position(0);

frame.render_stateful_widget(
    scrollbar,
    area.inner(&Margin {
        // using an inner vertical margin of 1 unit makes the scrollbar inside the block
        vertical: 1,
        horizontal: 0,
    }),
    &mut scrollbar_state,
);
17:05:03
@_discord_615829621296070659:t2bot.iodanik999 Thanks man 17:24:03
@_discord_820173014044901406:t2bot.io_desligado joined the room.17:56:12
@_discord_512504899817308180:t2bot.iodekirisu joined the room.18:09:47
@yuirivict:matrix.orgyuri@FreeBSD

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)]));
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data)
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
23:51:07
@yuirivict:matrix.orgyuri@FreeBSD *

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)])); // static array here
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data) // dynamic array here
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
23:51:54
4 Jun 2024
@yuirivict:matrix.orgyuri@FreeBSD *

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)])); // static array here
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data) // dynamic array here
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
01:37:49
7 Jun 2024
@awiteb:4rs.nl@awiteb:4rs.nl joined the room.11:45:50
@awiteb:4rs.nl@awiteb:4rs.nl left the room.11:51:06
@awiteb:4rs.nl@awiteb:4rs.nl joined the room.11:51:21
@awiteb:4rs.nl@awiteb:4rs.nl left the room.11:52:56
8 Jun 2024
@max_ishere:matrix.orgmax_ishere changed their profile picture.10:12:18
11 Jun 2024
@azizemir:matrix.orgAziz Emir joined the room.16:51:35
19 Jun 2024
@burntk:matrix.orgSam O’nella joined the room.05:39:48
21 Jun 2024
@auronandace:matrix.org@auronandace:matrix.org left the room.08:18:48
23 Jun 2024
@joao00066joao:matrix.org@joao00066joao:matrix.org joined the room.18:59:05
@joao00066joao:matrix.org@joao00066joao:matrix.org left the room.18:59:58
27 Jun 2024
@alemi:alemi.dev@alemi:alemi.dev left the room.16:19:47
29 Jun 2024
@burntk:matrix.orgSam O’nella changed their display name from burntkrispe to BurntKrispe.05:28:40
30 Jun 2024
@avery71:matrix.orgAvery set a profile picture.00:06:06

Show newer messages


Back to Room ListRoom Version: 10