1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::app::{App, COPY, LINE, PARAGRAPH, VECTOR};
use tui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph, Wrap},
Frame,
};
pub fn render<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>) {
// let tabs = [
// "Tab 1", "Tab 2", "Tab 3", "Tab 4", "Tab 5", "Tab 6", "Tab 7", "Tab 8", "Tab 9", "Tab 10",
// ]
// .iter()
// .cloned()
// .map(Line::from)
// .collect();
// if frame.size().height < 3 {
// frame.render_widget(
// Tabs::new(tabs)
// .select(app.selected)
// .block(
// Block::default()
// .title(format!("History size: {}", app.history.len()))
// .borders(Borders::ALL)
// .border_type(BorderType::Rounded),
// )
// .style(Style::default().fg(Color::White))
// .highlight_style(Style::default().fg(Color::Yellow))
// .divider(DOT),
// Rect::new(0, 0, frame.size().width, frame.size().height),
// );
// } else {
// frame.render_widget(
// Tabs::new(tabs)
// .select(app.selected)
// .block(
// Block::default()
// .title(format!("History size: {}", app.history.len()))
// .borders(Borders::ALL)
// .border_type(BorderType::Rounded),
// )
// .style(Style::default().fg(Color::White))
// .highlight_style(Style::default().fg(Color::Yellow))
// .divider(DOT),
// Rect::new(0, 0, frame.size().width, app.tab_length),
// );
unsafe {
if !VECTOR.is_empty() {
if VECTOR[VECTOR.len() - 1] == "\n" {
VECTOR.pop();
}
let (head, tail) = VECTOR.split_at(PARAGRAPH);
let a = head.join("\n\n");
let mut b = tail.first().unwrap().to_string();
let c = tail.get(1..tail.len()).unwrap().join("\n\n");
if PARAGRAPH != 0 {
b.insert(0, '\n');
}
b.push_str("\n\n");
let h = a.split_inclusive(|c| c == '\n');
let m = b.split_inclusive(|c| c == '\n');
let t = c.split_inclusive(|c| c == '\n');
let mut text = vec![];
for l in h {
text.push(Line::from(l));
}
for l in m {
text.push(Line::from(Span::styled(
l,
Style::default().fg(Color::LightYellow),
)));
}
for l in t {
text.push(Line::from(l));
}
frame.render_widget(
Paragraph::new(text)
.wrap(Wrap { trim: true })
.block(
Block::default()
.title(format!(
"{} chars {} words {} lines copied - pdf mode: {}", // after filtering out carriage return
COPY.chars().count(),
COPY.split_whitespace().count(),
COPY.lines().count(),
app.pdf_mode
))
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.style(Style::default().fg(Color::White)),
)
.style(Style::default().fg(Color::Yellow).bg(Color::Black))
.alignment(Alignment::Center)
.scroll((LINE, 0)), // no autoscroll, can't determine text length with wrap
Rect::new(
frame.size().x,
frame.size().y,
frame.size().width,
frame.size().height,
),
)
}
}
}