Skip to content

Commit 57f1848

Browse files
authored
Merge pull request #153 from itsjunetime/fix_dynamic_paging
fix: Make dynamic paging work again and add doc testing to CI
2 parents 759b848 + 4ee9655 commit 57f1848

File tree

8 files changed

+133
-87
lines changed

8 files changed

+133
-87
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ jobs:
8787
- name: Run documentation tests
8888
run: cargo test --doc --all-features
8989

90+
docs:
91+
name: docs
92+
env:
93+
RUST_BACKTRACE: 1
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Checkout repository
97+
uses: actions/checkout@v4
98+
- name: Run docs generation
99+
run: cargo doc --no-deps --document-private-items --keep-going --all-features
100+
90101
lint:
91102
name: lint
92103
runs-on: ubuntu-latest
@@ -100,12 +111,8 @@ jobs:
100111
- uses: actions-rs/cargo@v1
101112
with:
102113
command: clippy
103-
args: --features=dynamic_output,search --tests --examples
104-
- uses: actions-rs/cargo@v1
105-
with:
106-
command: clippy
107-
args: --features=dynamic_output,search --tests --examples
114+
args: --features=dynamic_output,search --tests --examples -- -D warnings
108115
- uses: actions-rs/cargo@v1
109116
with:
110117
command: clippy
111-
args: --features=static_output,search --tests --examples
118+
args: --features=static_output,search --tests --examples -- -D warnings

CHANGELOG.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ This file documents all changes made to the project and is updated before each r
122122

123123
## v5.2.0 [2023-03-01]
124124
### Added
125-
* Added `AppendStyle` and `AppendProps` enums in the new `minus_core::utils::text` to control the append behaviour and
125+
* Added `AppendStyle` and `AppendProps` enums in the new `minus_core::utils::text` to control the append behaviour and
126126
properties related to each append operation
127127

128128
### Changes
@@ -160,7 +160,7 @@ This file documents all changes made to the project and is updated before each r
160160

161161
## v5.0.4 [2022-07-31]
162162
### Added
163-
* Added dependency on [crossbeam-utils](https://crates.io/crates/crossbeam-utils).
163+
* Added dependency on [crossbeam-utils](https://crates.io/crates/crossbeam-utils).
164164
This allows us to use scoped threads feature provided by it.
165165

166166
### Changed
@@ -188,17 +188,17 @@ This file documents all changes made to the project and is updated before each r
188188
- Line Numbers are displayed only on the first wrapped row of each line.
189189

190190
This decreases the clutter on the line number column especially on text which span multiple lines.
191-
191+
192192
- Line Numbers are now padded by about 5 spaces. This makes the line numbers not get tightly packed with the left edge of the terminal.
193193

194194
### Fixed
195-
- Fixed bug when appending complex sets of text, a wrong value of `unterminated` got calculated which
195+
- Fixed bug when appending complex sets of text, a wrong value of `unterminated` got calculated which
196196
caused junk text to appended to the `PagerState::formatted_lines` and also to be displayed on the terminal.
197197

198198
- Fixed mouse scroll wheel not scrolling through the screen.
199199

200200
This occurred because a of a previous patch which removed the line that enabled the mouse events to be captured.
201-
201+
202202
* Fix panic when the search term gets changed
203203

204204
This occurred due to the `search_idx` not being repopulated when a new search is activated.
@@ -219,35 +219,35 @@ This file documents all changes made to the project and is updated before each r
219219
This is the unification of the previous `tokio_lib` and `async_std_lib` features.
220220
minus no longer depends on `tokio` or `async_std` directly and requires end-application to
221221
bring in these libs as dependency. **This makes minus completely runtime agnostic**
222-
223-
* minus can now be called from a OS thread using
224-
[`threads`](https://doc.rust-lang.org/std/thread/index.html).
222+
223+
* minus can now be called from a OS thread using
224+
[`threads`](https://doc.rust-lang.org/std/thread/index.html).
225225
See example in [README](./README.md#threads)
226-
227-
* Applications should call `dynamic_paging` on s separate non-blocking thread like
226+
227+
* Applications should call `dynamic_paging` on s separate non-blocking thread like
228228
[`tokio::task::spawn_blocking()`](https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html)
229229
or [`threads`](https://doc.rust-lang.org/std/thread/index.html).
230230

231231
* Use channels for communication
232-
232+
233233
* This allows minus to exactly know when data is changed and do various optimizations on it's
234234
* Added [`crossbeam_channels`](https://crates.io/crates/crossbeam_channels) as dependency.
235235

236236
* Store the current run mode as static value
237237

238238
* The `RUNMODE` static item tells minus whether it is running in static mode or asynchronous mode
239239
* Added `once_cell` as a dependency to store the above value in static scope.
240-
240+
241241
* Added feature to scroll through more than one line
242-
* Prefixing any of the movement keys with a number will move the screen up or down to that many lines.
242+
* Prefixing any of the movement keys with a number will move the screen up or down to that many lines.
243243
For example `10j` will take the view 10 lines down.
244-
* Similarly jump to specific line by prefixing `G` with a number. For example `15G` will take you to the
244+
* Similarly jump to specific line by prefixing `G` with a number. For example `15G` will take you to the
245245
15th line of the data.
246-
246+
247247
* Searching through text with lots of ansi sequence inside it will no longer break the search
248248
Previously this case would cause the search matcher to not match it and move to the next one
249249
(#57)
250-
250+
251251
* Added a `PagerState` struct to store and share internal data. It is made public, along with some of its
252252
fields so that it can be used to implement `InputClassifier` trait for applications that want to modify the
253253
default keybindings
@@ -263,18 +263,18 @@ default keybindings
263263
The `handle_input()` function cared about a lot of things and passing everything as a parameter
264264
was really tedious. This also caused a breaking change whenever a new parameter was added
265265

266-
* Changed function signature of `Pager::new` to `new() -> Pager`. It previously used to return a
266+
* Changed function signature of `Pager::new` to `new() -> Pager`. It previously used to return a
267267
`Result<Pager, TermError>`.
268268

269-
* Use threads even in static paging mode. Although mutating the `Pager`s data won't reflect any changes in
269+
* Use threads even in static paging mode. Although mutating the `Pager`s data won't reflect any changes in
270270
static mode.
271-
272-
* Replaced `tokio-no-overflow` example with `static-no-overflow` function. This is because the
271+
272+
* Replaced `tokio-no-overflow` example with `static-no-overflow` function. This is because the
273273
`Pager::run_no_overflow` function is only available in `static_output`feature.
274-
274+
275275
* All implemented functions on `Pager` except `Pager::new` will return a `Result<(), MinusError>`
276276
because the communication with the pager may fail if the pager has quit early on.
277-
277+
278278
* Applications should spawn `dynamic_paging` by themselves. For example on tokio, this would be
279279
```rust
280280
use tokio::{task::spawn_blocking, join}
@@ -294,10 +294,10 @@ default keybindings
294294
* Removed `tokio`, `async-std` and `async-mutex` from dependencies.
295295
* Removed `Pager::finish` function.
296296
* Removed `Pager::end_data_stream` function.
297-
298-
This was only required for running in dynamic mode with run no overflow on. With deprecation of this
297+
298+
This was only required for running in dynamic mode with run no overflow on. With deprecation of this
299299
feature we no longer need this function
300-
300+
301301
* Removed `static_long` example.
302302
* Removed `PageAllError` from `static_pager` and `errors` modules.
303303

@@ -358,10 +358,10 @@ default keybindings
358358
### Fixed
359359
* Prevent panic if invalid regex is given during search
360360
* Fix run\_no\_overflow for static pager (#43)
361-
361+
362362
Previously, this setting had no effect if paging static output, due to an if condition in
363363
`static_pager.rs` which did not consider the setting. This commit makes
364-
this setting behave as expected. (@tomstoneham)
364+
this setting behave as expected. (@tomstoneham)
365365

366366
* The cursor is hidden as soon as the search query entry is complete.
367367
* Fix where color outputs get distorted after search matches

Justfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
_prechecks:
22
-cargo hack 2> /dev/null
3-
3+
44
if [ $? -eq 101 ]; then \
55
cargo install cargo-hack; \
66
fi
@@ -18,14 +18,17 @@ tests:
1818
cargo test --all-features --no-run
1919
cargo test --all-features
2020

21+
docs:
22+
cargo doc --no-deps --document-private-items --keep-going --all-features
23+
2124
examples:
22-
cargo check --example=dyn_tokio --features=dynamic_output
23-
cargo check --example=msg-tokio --features=dynamic_output
24-
cargo check --example=static --features=static_output
25-
cargo check --example=less-rs --features=dynamic_output,search
25+
cargo clippy --example=dyn_tokio --features=dynamic_output
26+
cargo clippy --example=msg-tokio --features=dynamic_output
27+
cargo clippy --example=static --features=static_output
28+
cargo clippy --example=less-rs --features=dynamic_output,search
2629

2730
lint: _prechecks
2831
cargo hack --feature-powerset clippy --all-targets
29-
30-
verify-all: check-fmt build tests examples lint
32+
33+
verify-all: check-fmt build tests examples lint docs
3134
@echo "Ready to go"

src/core/init.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use super::{CommandQueue, RUNMODE, utils::display::draw_for_change};
5656
///
5757
/// * If the size of the data is less than the available number of rows in the terminal
5858
/// then it displays everything on the main stdout screen at once and quits. This
59-
/// behaviour can be turned off if [`Pager::set_run_no_overflow(true)`] is called
59+
/// behaviour can be turned off if [`Pager::set_run_no_overflow`](true) is called
6060
/// by the main application
6161
// Sorry... this behaviour would have been cool to have in async mode, just think about it!!! Many
6262
// implementations were proposed but none were perfect
@@ -83,38 +83,34 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr
8383
#[cfg(feature = "search")]
8484
let input_thread_running = Arc::new((Mutex::new(true), Condvar::new()));
8585

86-
#[allow(unused_mut)]
87-
let mut ps = crate::state::PagerState::generate_initial_state(&pager.rx, &mut out)?;
88-
8986
{
9087
let mut runmode = super::RUNMODE.lock();
91-
assert!(
92-
runmode.is_uninitialized(),
88+
assert_eq!(
89+
*runmode,
90+
RunMode::Uninitialized,
9391
"Failed to set the RUNMODE. This is caused probably because another instance of minus is already running"
9492
);
9593
*runmode = rm;
96-
drop(runmode);
9794
}
9895

96+
#[allow(unused_mut)]
97+
let mut ps = crate::state::PagerState::generate_initial_state(&pager.rx, &mut out)?;
98+
9999
// Static mode checks
100100
#[cfg(feature = "static_output")]
101101
if *RUNMODE.lock() == RunMode::Static {
102102
// If stdout is not a tty, write everything and quit
103103
if !out.is_tty() {
104104
write_raw_lines(&mut out, &[ps.screen.orig_text], None)?;
105-
let mut rm = RUNMODE.lock();
106-
*rm = RunMode::Uninitialized;
107-
drop(rm);
105+
*RUNMODE.lock() = RunMode::Uninitialized;
108106
return Ok(());
109107
}
110108
// If number of lines of text is less than available rows, write everything and quit
111109
// unless run_no_overflow is set to true
112110
if ps.screen.formatted_lines_count() <= ps.rows && !ps.run_no_overflow {
113111
write_raw_lines(&mut out, &ps.screen.formatted_lines, Some("\r"))?;
114112
ps.exit();
115-
let mut rm = RUNMODE.lock();
116-
*rm = RunMode::Uninitialized;
117-
drop(rm);
113+
*RUNMODE.lock() = RunMode::Uninitialized;
118114
return Ok(());
119115
}
120116
}
@@ -131,7 +127,7 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr
131127
panic::set_hook(Box::new(move |pinfo| {
132128
is_exited2.store(true, std::sync::atomic::Ordering::SeqCst);
133129
// While silently ignoring error is considered a bad practice, we are forced to do it here
134-
// as we cannot use the ? and panicking here will cause UB.
130+
// as we cannot use the ? and panicking here will (probably?) cause an immediate abort
135131
drop(term::cleanup(
136132
stdout(),
137133
&crate::ExitStrategy::PagerQuit,
@@ -169,9 +165,7 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr
169165

170166
if res.is_err() {
171167
is_exited3.store(true, std::sync::atomic::Ordering::SeqCst);
172-
let mut rm = RUNMODE.lock();
173-
*rm = RunMode::Uninitialized;
174-
drop(rm);
168+
*RUNMODE.lock() = RunMode::Uninitialized;
175169
term::cleanup(out.as_ref(), &crate::ExitStrategy::PagerQuit, true)?;
176170
}
177171
res
@@ -188,9 +182,7 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr
188182

189183
if res.is_err() {
190184
is_exited4.store(true, std::sync::atomic::Ordering::SeqCst);
191-
let mut rm = RUNMODE.lock();
192-
*rm = RunMode::Uninitialized;
193-
drop(rm);
185+
*RUNMODE.lock() = RunMode::Uninitialized;
194186
term::cleanup(out_copy.as_ref(), &crate::ExitStrategy::PagerQuit, true)?;
195187
}
196188
res
@@ -215,9 +207,8 @@ pub fn init_core(pager: &Pager, rm: RunMode) -> std::result::Result<(), MinusErr
215207
/// and redraw if it event requires it to do so.
216208
///
217209
/// For example if all rows in a terminal aren't filled and a
218-
/// [`AppendData`](super::events::Event::AppendData) event occurs, it is absolutely necessory
219-
/// to update the screen immediately; while if all rows are filled, we can omit to redraw the
220-
/// screen.
210+
/// [`AppendData`](super::commands::Command::AppendData) event occurs, it is absolutely necessary to
211+
/// update the screen immediately; while if all rows are filled, we can omit to redraw the screen.
221212
#[allow(clippy::too_many_lines)]
222213
fn start_reactor(
223214
rx: &Receiver<Command>,

src/core/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ pub mod ev_handler;
55
#[cfg(any(feature = "dynamic_output", feature = "static_output"))]
66
pub mod init;
77
pub mod utils;
8+
9+
// TODO: Global statics aren't great and this one, in particular, is making it hard to run tests
10+
// (since most non-unit tests will end up setting this, which then needs to be unset for the next
11+
// test). Figure out how to get rid of this.
812
pub static RUNMODE: parking_lot::Mutex<RunMode> = parking_lot::const_mutex(RunMode::Uninitialized);
913

1014
use commands::Command;
@@ -65,7 +69,7 @@ impl CommandQueue {
6569
}
6670

6771
/// Define the modes in which minus can run
68-
#[derive(Copy, Clone, PartialEq, Eq)]
72+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
6973
pub enum RunMode {
7074
#[cfg(feature = "static_output")]
7175
Static,

0 commit comments

Comments
 (0)