Skip to content

Commit

Permalink
Indicate when there are new messages below scrollback viewport (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa committed Jul 8, 2023
1 parent b1ccec6 commit 7b050f8
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/windows/room/scrollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ use regex::Regex;

use matrix_sdk::ruma::OwnedRoomId;

use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget};
use modalkit::tui::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Modifier as StyleModifier, Style},
text::{Span, Spans},
widgets::{Paragraph, StatefulWidget, Widget},
};
use modalkit::widgets::{ScrollActions, TerminalCursor, WindowOps};

use modalkit::editing::{
Expand Down Expand Up @@ -1205,6 +1211,27 @@ impl TerminalCursor for ScrollbackState {
}
}

fn render_jump_to_recent(area: Rect, buf: &mut Buffer, focused: bool) -> Rect {
if area.height <= 5 || area.width <= 20 {
return area;
}

let top = Rect::new(area.x, area.y, area.width, area.height - 1);
let bar = Rect::new(area.x, area.y + top.height, area.width, 1);
let msg = vec![
Span::raw("Use "),
Span::styled("G", Style::default().add_modifier(StyleModifier::BOLD)),
Span::raw(if focused { "" } else { " in scrollback" }),
Span::raw(" to jump to latest message"),
];

Paragraph::new(Spans::from(msg))
.alignment(Alignment::Center)
.render(bar, buf);

return top;
}

pub struct Scrollback<'a> {
room_focused: bool,
focused: bool,
Expand Down Expand Up @@ -1236,7 +1263,11 @@ impl<'a> StatefulWidget for Scrollback<'a> {
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
let info = self.store.application.rooms.get_or_default(state.room_id.clone());
let settings = &self.store.application.settings;
let area = info.render_typing(area, buf, &self.store.application.settings);
let area = if state.cursor.timestamp.is_some() {
render_jump_to_recent(area, buf, self.focused)
} else {
info.render_typing(area, buf, &self.store.application.settings)
};

state.set_term_info(area);

Expand Down

0 comments on commit 7b050f8

Please sign in to comment.