Skip to content

Commit

Permalink
more updates to x.sh, fmt/clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-hartley committed Oct 29, 2023
1 parent a443a00 commit ec4b85c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 40 deletions.
2 changes: 1 addition & 1 deletion tuig-iosys/examples/list-actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn list_events(mut sys: Box<dyn IoSystem>) {
sys.draw(&screen).expect("failed to render screen");
match sys.input().expect("failed to get input") {
Action::Closed | Action::KeyPress { key: Key::Escape } => break,
Action::Error(e) => Err(e).expect("got an error for input"),
Action::Error(e) => panic!("{1}: {:?}", e, "got an error for input"),
other => log.push(format!("{:?}", other)),
}
if log.len() > screen.size().y() {
Expand Down
2 changes: 0 additions & 2 deletions tuig-iosys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ pub mod fmt;
mod screen;
mod xy;

mod util;

pub use crate::{
action::{Action, Key, MouseButton},
error::{Error, Result},
Expand Down
18 changes: 0 additions & 18 deletions tuig-iosys/src/util.rs

This file was deleted.

4 changes: 1 addition & 3 deletions tuig-ui/src/attachments/textbox.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::mem;

use alloc::{string::String, vec::Vec};
use tuig_iosys::{
fmt::{Cell, Formatted, FormattedExt, Text},
Expand Down Expand Up @@ -101,7 +99,7 @@ impl Textbox {
// break the chunks into paragraphs on newlines
let mut paragraphs = alloc::vec![];
let mut cur_para = alloc::vec![];
for mut chunk in mem::replace(&mut self.chunks, alloc::vec![]) {
for mut chunk in std::mem::take(&mut self.chunks) {
while let Some((line, rest)) = chunk.text.split_once('\n') {
cur_para.push(chunk.with_text(line.into()));
paragraphs.push(cur_para);
Expand Down
2 changes: 1 addition & 1 deletion tuig-ui/src/splitters/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! split_static {
}
}

fn fill_sep<'r>(r: &mut Region<'r>, sep: &str) {
fn fill_sep(r: &mut Region<'_>, sep: &str) {
if sep.is_empty() {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions tuig-ui/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'s> ScreenView<'s> {
/// Get a single cell in this view.
///
/// This returns `None` if the index is out of bounds.
pub fn cell<'v>(&'v self, pos: XY) -> Option<&'v Cell> {
pub fn cell(&self, pos: XY) -> Option<&Cell> {
let buf = self.buf?;
let offset = self.offset(pos)?;
// SAFETY: See [`Self::offset`] docs.
Expand All @@ -115,7 +115,7 @@ impl<'s> ScreenView<'s> {
/// Get a single cell in this view, mutably.
///
/// This returns `None` if the index is out of bounds.
pub fn cell_mut<'v>(&'v mut self, pos: XY) -> Option<&'v mut Cell> {
pub fn cell_mut(&mut self, pos: XY) -> Option<&mut Cell> {
let buf = self.buf?;
let offset = self.offset(pos)?;
// SAFETY: See [`Self::offset`] docs. Mutable references are safe because this method is `&mut self`, which
Expand All @@ -130,7 +130,7 @@ impl<'s> ScreenView<'s> {
/// cell in a column independently.
///
/// This returns `None` if the index is out of bounds.
pub fn row<'v>(&'v self, idx: usize) -> Option<&'v [Cell]> {
pub fn row(&self, idx: usize) -> Option<&[Cell]> {
let buf = self.buf?;
let offset = self.offset(XY(0, idx))?;
// SAFETY: See [`Self::offset`] docs.
Expand All @@ -150,7 +150,7 @@ impl<'s> ScreenView<'s> {
/// cell in a column independently.
///
/// This returns `None` if the index is out of bounds.
pub fn row_mut<'v>(&'v mut self, idx: usize) -> Option<&'v mut [Cell]> {
pub fn row_mut(&mut self, idx: usize) -> Option<&mut [Cell]> {
let buf = self.buf?;
let offset = self.offset(XY(0, idx))?;
// SAFETY: The offset is guaranteed to be within the allocated object (the screen's Vec's buffer) because
Expand Down
2 changes: 1 addition & 1 deletion tuig/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pub trait Game: Send {
///
/// If you want to render in terms of a raw [`Screen`](tuig_iosys::Screen) and input [`Action`](tuig_iosys::Action)
/// instead, call [`Region::attach`] with a [`RawAttachment`](tuig_ui::attachments::RawAttachment).
fn attach<'s>(&mut self, into: Region<'s>, replies: &mut Replies<Self::Message>);
fn attach(&mut self, into: Region<'_>, replies: &mut Replies<Self::Message>);
}
31 changes: 21 additions & 10 deletions x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

CRATES="tuig-pm tuig-iosys tuig-ui tuig"

# parameter should be:
# - fix (default): run lightweight checks and fix things automatically where possible
# - check: run all checks w/o fixing (including publish dry-drun -- likely to fail for bumped versions)
# - publish: run all checks, and if they pass, publish all the crates to crates.io.
mode="$1"
if [ -z "$mode" ]; then
mode="fix"
fi

set -e

Expand All @@ -14,21 +21,25 @@ for crate in $CRATES; do
exit 1
fi
done
cargo fmt --check
cargo build --all-features --workspace --all-targets
cargo doc --all-features --workspace --no-deps --lib --bins --examples
cargo test --all-features --workspace --all-targets

case "$mode" in
pub*)
for crate in $CRATES; do
cargo publish -p "$crate"
done
f*)
cargo fmt
cargo clippy --fix --allow-dirty --allow-staged
cargo check
;;
precom*) ;;
*)
cargo fmt --check
cargo clippy
cargo build --all-features --workspace --all-targets
cargo doc --all-features --workspace --no-deps --lib --bins --examples
cargo test --all-features --workspace --all-targets
esac

case "$mode" in
p*)
for crate in $CRATES; do
cargo publish -p "$crate" --dry-run
cargo publish -p "$crate"
done
;;
esac

0 comments on commit ec4b85c

Please sign in to comment.