Skip to content

Commit a45f387

Browse files
committed
tick_beam
1 parent e9782e7 commit a45f387

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+571
-421
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*If you're reading this because you try make sense of some new API or a breaking change, you might also be interested in coming to the chat for explanations or guidance.*
22

3+
<a name="v0.31.0"></a>
4+
### v0.31.0 - 2024-10-26
5+
- reexport crossbeam
6+
- new Ticker tool: emit tick(s) on a channel
7+
38
<a name="v0.30.1"></a>
49
### v0.30.1 - 2024-10-10
510
- input_field#display returns the curstor position if it's rendered - experimental - Thanks @xubaiwang

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "termimad"
3-
version = "0.30.1"
3+
version = "0.31.0"
44
authors = ["dystroy <denys.seguret@gmail.com>"]
55
repository = "https://github.com/Canop/termimad"
66
description = "Markdown Renderer for the Terminal"

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,28 @@
1212
[s4]: https://miaou.dystroy.org/static/shields/room.svg
1313
[l4]: https://miaou.dystroy.org/3
1414

15-
A CLI utilities library leveraging Markdown to format terminal rendering, allowing separation of structure, data and skin.
15+
## Introduction
1616

17-
Based on [crossterm](#crossterm-compatibility) so works on most terminals (even on windows).
17+
Termimad is a set of cross-platform utilities dedicated to CLI and TUI apps,
18+
- leveraging Markdown to format terminal rendering, allowing separation of structure, data and skin,
19+
- using [crossterm](https://github.com/crossterm-rs/crossterm) as backend for styling and event,
20+
- based on [crokey](https://docs.rs/crokey/latest/crokey/) for key combinations support
21+
- with a focus on total control and performances, with no active loop,
22+
- using [crossbeam](https://docs.rs/crossbeam/latest/crossbeam/) for event passing,
23+
- striving to be correct, even on Unicode and wide characters
24+
25+
Termimad is **not**
26+
- a TUI framework: Unless you have serious performance concerns or want precise control, you'll find it much easier and faster, when building a TUI application, to just use one of the TUI frameworks of the Rust ecosystem
27+
- a generic Markdown renderer
28+
- consistent or complete in any way
29+
30+
## Markdown in Termimad
1831

1932
![text](doc/text.png)
2033

2134
The goal isn't to display any markdown text with its various extensions (a terminal isn't really fit for that).
2235
The goal is rather to improve the display of texts in a terminal application when we want both the text and the skin to be easily configured.
2336

24-
Termimad also includes a few utilities helping efficient managing of events and user input in a multithread application.
25-
2637
**Wrapping**, table balancing, and **scrolling** are essential features of Termimad.
2738

2839
A text or a table can be displayed in an *a priori* unknown part of the screen, scrollable if desired, with a dynamically discovered width.
@@ -286,6 +297,10 @@ scrollbar: "#fb0 gray(11) |"
286297

287298
Execute `cargo run --example skin-file` for an example and explanations.
288299

300+
## Events and inputs
301+
302+
Termimad also includes a few utilities helping efficient managing of events and user input in a multithread application.
303+
289304
## Advices to get started
290305

291306
* Start by reading the examples (in `/examples`): they cover almost the whole API, including templates, how to use an alternate screen or scroll the page, etc. Many examples print a bunch of relevant documentation.

bacon.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ command = [
2424
"--",
2525
"-A", "clippy::match_like_matches_macro",
2626
"-A", "clippy::manual_range_contains",
27+
"-A", "clippy::new_without_default",
2728
]
2829
need_stdout = false
2930
watch = ["tests", "benches", "examples"]

src/area.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use {
22
crate::crossterm::terminal,
3-
std::convert::{TryFrom, TryInto},
3+
std::convert::{
4+
TryFrom,
5+
TryInto,
6+
},
47
};
58

69
/// A default width which is used when we failed measuring the real terminal width
@@ -67,10 +70,7 @@ impl Area {
6770

6871
/// tell whether the char at (x,y) is in the area
6972
pub const fn contains(&self, x: u16, y: u16) -> bool {
70-
x >= self.left
71-
&& x < self.left + self.width
72-
&& y >= self.top
73-
&& y < self.top + self.height
73+
x >= self.left && x < self.left + self.width && y >= self.top && y < self.top + self.height
7474
}
7575

7676
/// shrink the area
@@ -101,7 +101,8 @@ impl Area {
101101
scroll: U, // number of lines hidden on top
102102
content_height: U,
103103
) -> Option<(u16, u16)>
104-
where U: Into<usize>
104+
where
105+
U: Into<usize>,
105106
{
106107
compute_scrollbar(scroll, content_height, self.height, self.top)
107108
}

src/color.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use {
2-
crate::crossterm::style::Color,
3-
};
1+
use crate::crossterm::style::Color;
42

53
/// Build a RGB color
64
///
@@ -21,4 +19,3 @@ pub fn gray(mut level: u8) -> Color {
2119
pub const fn ansi(level: u8) -> Color {
2220
Color::AnsiValue(level)
2321
}
24-

src/composite.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use {
22
crate::*,
3-
minimad::{Composite, Compound},
3+
minimad::{
4+
Composite,
5+
Compound,
6+
},
47
unicode_width::UnicodeWidthStr,
58
};
69

710
/// Wrap Minimad compounds with their style and
811
/// termimad specific information
912
#[derive(Debug, Clone)]
1013
pub struct FmtComposite<'s> {
11-
1214
pub kind: CompositeKind,
1315

1416
pub compounds: Vec<Compound<'s>>,
@@ -17,7 +19,6 @@ pub struct FmtComposite<'s> {
1719
pub visible_length: usize,
1820

1921
pub spacing: Option<Spacing>,
20-
2122
}
2223

2324
impl<'s> FmtComposite<'s> {

src/composite_kind.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub enum CompositeKind {
1414
Quote,
1515
}
1616

17-
1817
impl From<CompositeStyle> for CompositeKind {
1918
fn from(ty: CompositeStyle) -> Self {
2019
match ty {

src/compound_style.rs

+15-27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use {
22
crate::{
3-
errors::Result,
43
crossterm::{
5-
QueueableCommand,
64
style::{
75
Attribute,
86
Attributes,
@@ -13,11 +11,19 @@ use {
1311
SetForegroundColor,
1412
StyledContent,
1513
},
16-
terminal::{Clear, ClearType},
14+
terminal::{
15+
Clear,
16+
ClearType,
17+
},
18+
QueueableCommand,
1719
},
20+
errors::Result,
1821
styled_char::StyledChar,
1922
},
20-
std::fmt::{self, Display},
23+
std::fmt::{
24+
self,
25+
Display,
26+
},
2127
};
2228

2329
/// The attributes which are often supported
@@ -32,7 +38,6 @@ pub static ATTRIBUTES: &[Attribute] = &[
3238
Attribute::OverLined,
3339
];
3440

35-
3641
/// A style which may be applied to a compound
3742
#[derive(Default, Clone, Debug, PartialEq)]
3843
pub struct CompoundStyle {
@@ -75,7 +80,7 @@ impl CompoundStyle {
7580
///
7681
/// The `dest` color can be for example a [crossterm] color or a [coolor] one.
7782
pub fn blend_with<C: Into<coolor::Color>>(&mut self, dest: C, weight: f32) {
78-
debug_assert!(weight>=0.0 && weight<=1.0);
83+
debug_assert!(weight >= 0.0 && weight <= 1.0);
7984
let dest: coolor::Color = dest.into();
8085
if let Some(fg) = self.object_style.foreground_color.as_mut() {
8186
let src: coolor::Color = (*fg).into();
@@ -89,29 +94,17 @@ impl CompoundStyle {
8994

9095
/// Get an new instance of `CompoundStyle`
9196
pub fn with_fgbg(fg: Color, bg: Color) -> Self {
92-
Self::new(
93-
Some(fg),
94-
Some(bg),
95-
Attributes::default(),
96-
)
97+
Self::new(Some(fg), Some(bg), Attributes::default())
9798
}
9899

99100
/// Get an new instance of `CompoundStyle`
100101
pub fn with_fg(fg: Color) -> Self {
101-
Self::new(
102-
Some(fg),
103-
None,
104-
Attributes::default(),
105-
)
102+
Self::new(Some(fg), None, Attributes::default())
106103
}
107104

108105
/// Get an new instance of `CompoundStyle`
109106
pub fn with_bg(bg: Color) -> Self {
110-
Self::new(
111-
None,
112-
Some(bg),
113-
Attributes::default(),
114-
)
107+
Self::new(None, Some(bg), Attributes::default())
115108
}
116109

117110
/// Get an new instance of `CompoundStyle`
@@ -180,12 +173,7 @@ impl CompoundStyle {
180173

181174
/// Write a char several times with the line compound style
182175
#[inline(always)]
183-
pub fn repeat_char(
184-
&self,
185-
f: &mut fmt::Formatter<'_>,
186-
c: char,
187-
count: usize,
188-
) -> fmt::Result {
176+
pub fn repeat_char(&self, f: &mut fmt::Formatter<'_>, c: char, count: usize) -> fmt::Result {
189177
if count > 0 {
190178
let s = std::iter::repeat(c).take(count).collect::<String>();
191179
write!(f, "{}", self.apply_to(s))?;

src/errors.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use crate::{
2-
fit::InsufficientWidthError,
3-
};
1+
use crate::fit::InsufficientWidthError;
42

53
/// Termimad error type
64
#[derive(thiserror::Error, Debug)]
75
pub enum Error {
8-
96
#[error("IO error: {0}")]
107
IO(#[from] std::io::Error),
118

src/events/escape_sequence.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use {
2-
crate::crossterm::{
3-
event::{
4-
KeyCode,
5-
KeyEvent,
6-
KeyModifiers,
7-
},
2+
crate::crossterm::event::{
3+
KeyCode,
4+
KeyEvent,
5+
KeyModifiers,
86
},
97
std::fmt,
108
};
@@ -26,7 +24,12 @@ pub struct EscapeSequence {
2624
impl fmt::Display for EscapeSequence {
2725
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2826
for key in &self.keys {
29-
if let KeyEvent { code: KeyCode::Char(c), modifiers: KeyModifiers::NONE, .. } = key {
27+
if let KeyEvent {
28+
code: KeyCode::Char(c),
29+
modifiers: KeyModifiers::NONE,
30+
..
31+
} = key
32+
{
3033
write!(f, "{}", c)?;
3134
}
3235
}

0 commit comments

Comments
 (0)