Skip to content

Commit 42ccf6a

Browse files
committed
Merge branch 'main' into fix/macos-burn-issue
2 parents b5bf85e + edd8b15 commit 42ccf6a

File tree

10 files changed

+165
-64
lines changed

10 files changed

+165
-64
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A clear and concise description of what you expected to happen.
2424
Please upload log files to aid in debugging the issue.
2525

2626
## OS/Environment
27+
- Terminal emulator: [e.g. konsole, GNOME terminal, alacritty, xterm]
2728
- OS: [e.g. Linux]
2829
- Version: [e.g. v0.4.3]
2930
- Distribution channel: [e.g. release binary, AUR, Nix, built from source]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*.img
99
*.iso
1010
*.xz
11+
*.lz4
1112
*.gz
1213
*.o
1314
*.a

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,19 @@ version = "0.4.4"
88
edition = "2021"
99
license = "GPL-3.0"
1010

11-
[features]
12-
default = ["gz", "xz", "bz2"]
13-
gz = ["dep:flate2"]
14-
xz = ["dep:xz2"]
15-
bz2 = ["dep:bzip2"]
16-
1711
[dependencies]
1812
anyhow = "1.0.82"
1913
base16 = "0.2.1"
2014
base64 = "0.22.1"
2115
bincode = "1.3.3"
2216
byteorder = "1.5.0"
2317
bytesize = "1.3.0"
24-
bzip2 = { version = "0.4.4", optional = true, features = ["static"] }
18+
bzip2 = { version = "0.4.4", features = ["static"] }
2519
clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
2620
crossterm = { version = "0.27.0", features = ["event-stream"] }
2721
derive_more = "0.99.17"
2822
digest = "0.10.6"
29-
flate2 = { version = "1.0.25", optional = true }
23+
flate2 = "1.0.25"
3024
format-bytes = "0.3.0"
3125
futures = "0.3.30"
3226
futures-io = "0.3.26"
@@ -36,6 +30,7 @@ interprocess = { version = "2.0.0", features = ["tokio"] }
3630
is-terminal = "0.4.12"
3731
itertools = "0.12.1"
3832
libc = "0.2.154"
33+
lz4_flex = "0.11.3"
3934
md-5 = "0.10.5"
4035
process_path = "0.1.4"
4136
ratatui = "0.26.0"
@@ -56,7 +51,7 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter", "fmt"] }
5651
tracing-unwrap = "1.0.1"
5752
valuable = { version = "0.1.0", features = ["derive"] }
5853
which = "6.0.1"
59-
xz2 = { version = "0.1.7", optional = true, features = ["static"] }
54+
xz2 = { version = "0.1.7", features = ["static"] }
6055

6156
[dev-dependencies]
6257
approx = "0.5.1"

src/compression.rs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ macro_rules! generate {
1212
{
1313
$readervar:ident: $r:ident {
1414
$(
15-
[feature=$feature:expr] $extpat:pat =>
15+
$extpat:pat =>
1616
$enumarm:ident($display:expr, $inner:ty)
1717
$dcrinner:expr,
1818
)*
@@ -74,15 +74,6 @@ macro_rules! generate {
7474
_ => false,
7575
}
7676
}
77-
78-
pub fn is_available(self) -> bool {
79-
match self {
80-
Self::Identity => true,
81-
$(
82-
Self::$enumarm => cfg!(feature = $feature),
83-
)*
84-
}
85-
}
8677
}
8778

8879
impl Display for CompressionFormat {
@@ -96,10 +87,9 @@ macro_rules! generate {
9687
}
9788
}
9889

99-
pub enum DecompressRead<$r> {
90+
pub enum DecompressRead<$r: BufRead> {
10091
Identity($r),
10192
$(
102-
#[cfg(feature = $feature)]
10393
$enumarm($inner),
10494
)*
10595
}
@@ -112,7 +102,6 @@ macro_rules! generate {
112102
match self {
113103
Self::Identity(r) => r,
114104
$(
115-
#[cfg(feature = $feature)]
116105
Self::$enumarm(r) => r.get_mut(),
117106
)*
118107
}
@@ -127,30 +116,22 @@ macro_rules! generate {
127116
match self {
128117
Self::Identity(r) => r.read(buf),
129118
$(
130-
#[cfg(feature = $feature)]
131119
Self::$enumarm(r) => r.read(buf),
132120
)*
133121
}
134122
}
135123
}
136124

137-
pub fn decompress<R>(cf: CompressionFormat, $readervar: R) -> Result<DecompressRead<R>, DecompressError>
125+
/// Open a decompressor for the given reader.
126+
pub fn decompress<R>(cf: CompressionFormat, $readervar: R) -> anyhow::Result<DecompressRead<R>>
138127
where
139128
R : BufRead
140129
{
141130
match cf {
142131
CompressionFormat::Identity => Ok(DecompressRead::Identity($readervar)),
143132
$(
144133
CompressionFormat::$enumarm => {
145-
#[cfg(feature = $feature)]
146-
let result = Ok(DecompressRead::$enumarm($dcrinner));
147-
148-
#[cfg(not(feature = $feature))]
149-
let result = Err(DecompressError::UnsupportedFormat(
150-
CompressionFormat::$enumarm
151-
));
152-
153-
result
134+
Ok(DecompressRead::$enumarm($dcrinner))
154135
}
155136
)*
156137
}
@@ -160,25 +141,21 @@ macro_rules! generate {
160141

161142
generate! {
162143
r: R {
163-
[feature = "gz"] "gz" => Gz("gzip", flate2::bufread::GzDecoder<R>) {
144+
"gz" => Gz("gzip", flate2::bufread::GzDecoder<R>) {
164145
flate2::bufread::GzDecoder::new(r)
165146
},
166-
[feature = "bz2"] "bz2" => Bz2("bzip2", bzip2::bufread::BzDecoder<R>) {
147+
"bz2" => Bz2("bzip2", bzip2::bufread::BzDecoder<R>) {
167148
bzip2::bufread::BzDecoder::new(r)
168149
},
169-
[feature = "xz"] "xz" => Xz("xz/LZMA", xz2::bufread::XzDecoder<R>) {
150+
"xz" => Xz("xz/LZMA", xz2::bufread::XzDecoder<R>) {
170151
xz2::bufread::XzDecoder::new(r)
171152
},
153+
"lz4" => Lz4("lz4", lz4_flex::frame::FrameDecoder<R>) {
154+
lz4_flex::frame::FrameDecoder::new(r)
155+
},
172156
}
173157
}
174158

175-
#[derive(Debug, thiserror::Error)]
176-
pub enum DecompressError {
177-
#[allow(unused)]
178-
#[error("Unsupported compression format {0}!")]
179-
UnsupportedFormat(CompressionFormat),
180-
}
181-
182159
impl CompressionFormat {
183160
pub fn detect_from_path(path: impl AsRef<Path>) -> Option<CompressionFormat> {
184161
if let Some(ext) = path.as_ref().extension() {

src/ui/fancy_ui/display.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,54 @@ struct ComputedLayout {
113113
progress: Rect,
114114
graph: Rect,
115115
args_display: Rect,
116+
quit_modal: Rect,
116117
}
117118

118119
impl From<Rect> for ComputedLayout {
119-
fn from(value: Rect) -> Self {
120+
fn from(area: Rect) -> Self {
120121
let root = Layout::default()
121122
.direction(Direction::Vertical)
122123
.constraints([
123124
Constraint::Length(1),
124125
Constraint::Min(10),
125126
Constraint::Length(10),
126127
])
127-
.split(value);
128+
.split(area);
128129

129130
let info_pane = root[2];
130131

132+
let quit_modal = centered_rect(area, 40, 4);
133+
131134
Self {
132135
graph: root[1],
133136
progress: root[0],
134137
args_display: info_pane,
138+
quit_modal,
135139
}
136140
}
137141
}
138142

143+
/// Given an outer rect and desired inner rect dimensions, returns the inner rect.
144+
fn centered_rect(r: Rect, w: u16, h: u16) -> Rect {
145+
let popup_layout = Layout::default()
146+
.direction(Direction::Vertical)
147+
.constraints([
148+
Constraint::Fill(1),
149+
Constraint::Length(h),
150+
Constraint::Fill(1),
151+
])
152+
.split(r);
153+
154+
Layout::default()
155+
.direction(Direction::Horizontal)
156+
.constraints([
157+
Constraint::Fill(1),
158+
Constraint::Length(w),
159+
Constraint::Fill(1),
160+
])
161+
.split(popup_layout[1])[1]
162+
}
163+
139164
pub fn draw(
140165
state: &mut State,
141166
terminal: &mut Terminal<impl ratatui::backend::Backend>,
@@ -184,6 +209,10 @@ pub fn draw(
184209
} else {
185210
f.render_widget(info_table, layout.args_display);
186211
}
212+
213+
if let Some(qm) = state.quit_modal {
214+
f.render_widget(qm, layout.quit_modal)
215+
}
187216
})?;
188217
Ok(())
189218
}

src/ui/fancy_ui/state.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
writer_process::ipc::StatusMessage,
99
};
1010

11-
use super::widgets::SpeedChartState;
11+
use super::widgets::{QuitModal, QuitModalResult, SpeedChartState};
1212

1313
#[derive(Debug, PartialEq, Clone)]
1414
pub enum UIEvent {
@@ -23,6 +23,7 @@ pub struct State {
2323
pub target_filename: String,
2424
pub child: WriterState,
2525
pub graph_state: SpeedChartState,
26+
pub quit_modal: Option<QuitModal>,
2627
}
2728

2829
impl State {
@@ -32,6 +33,7 @@ impl State {
3233
target_filename: params.target.devnode.to_string_lossy().to_string(),
3334
child: WriterState::initial(now, !params.compression.is_identity(), input_file_bytes),
3435
graph_state: SpeedChartState::default(),
36+
quit_modal: None,
3537
}
3638
}
3739

@@ -51,13 +53,34 @@ impl State {
5153
fn on_term_event(self, ev: Event) -> anyhow::Result<Self> {
5254
match ev {
5355
Event::Key(KeyEvent {
54-
code: KeyCode::Char('c'),
55-
modifiers: KeyModifiers::CONTROL,
5656
kind: KeyEventKind::Press,
57+
code,
58+
modifiers,
5759
..
58-
}) => {
59-
info!("Got CTRL-C, quitting");
60-
Err(Quit)?
60+
}) => self.handle_key_down((code, modifiers)),
61+
_ => Ok(self),
62+
}
63+
}
64+
65+
fn handle_key_down(mut self, (kc, km): (KeyCode, KeyModifiers)) -> anyhow::Result<Self> {
66+
if let Some(qm) = &self.quit_modal {
67+
return match qm.handle_key_down(kc) {
68+
Some(QuitModalResult::Quit) => Err(Quit.into()),
69+
Some(QuitModalResult::Stay) => Ok(Self {
70+
quit_modal: None,
71+
..self
72+
}),
73+
None => Ok(self),
74+
};
75+
}
76+
77+
match (kc, km) {
78+
(KeyCode::Char('c'), KeyModifiers::CONTROL)
79+
| (KeyCode::Esc, _)
80+
| (KeyCode::Char('q'), _) => {
81+
info!("Got request to quit, spawning prompt");
82+
self.quit_modal = Some(QuitModal::new());
83+
Ok(self)
6184
}
6285
_ => Ok(self),
6386
}

0 commit comments

Comments
 (0)