From cc37f7eb8e19cb13c4ad950905af54320aabd4df Mon Sep 17 00:00:00 2001 From: "gitlab.com/pepa65" Date: Sat, 6 Dec 2025 11:48:03 +0700 Subject: [PATCH 1/6] Add -c/--caption option --- src/app.rs | 3 +++ src/config.rs | 3 +++ src/main.rs | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/app.rs b/src/app.rs index d6085a8..b788764 100644 --- a/src/app.rs +++ b/src/app.rs @@ -140,6 +140,9 @@ fn view_file(conf: &Config, filename: &str, (tx, rx): TxRx) -> ViuResult { viuer::print_from_file(filename, &conf.viuer_config)?; } } + if conf.caption { + println!("{}", filename); + } Ok(()) } diff --git a/src/config.rs b/src/config.rs index 7535659..222db31 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,6 +6,7 @@ pub struct Config<'a> { pub files: Vec<&'a str>, pub loop_gif: bool, pub name: bool, + pub caption: bool, pub recursive: bool, pub static_gif: bool, pub viuer_config: ViuerConfig, @@ -63,6 +64,7 @@ impl<'a> Config<'a> { files, loop_gif, name: matches.get_flag("name"), + caption: matches.get_flag("caption"), recursive: matches.get_flag("recursive"), static_gif, viuer_config, @@ -75,6 +77,7 @@ impl<'a> Config<'a> { files: vec![], loop_gif: true, name: false, + caption: false, recursive: false, static_gif: false, viuer_config: ViuerConfig { diff --git a/src/main.rs b/src/main.rs index 56c0fc8..5c5b893 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,6 +75,13 @@ fn main() { .action(SetTrue) .help("Output the name of the file before displaying"), ) + .arg( + Arg::new("caption") + .short('c') + .long("caption") + .action(SetTrue) + .help("Output the name of the file after displaying"), + ) .arg( Arg::new("transparent") .short('t') From df5d58f54763d41f712f823c66ce0364dc1c3e11 Mon Sep 17 00:00:00 2001 From: "gitlab.com/pepa65" Date: Tue, 9 Dec 2025 20:58:25 +0700 Subject: [PATCH 2/6] User Error::other to fix warnings --- src/app.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index b788764..5d3ab9c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -38,7 +38,7 @@ pub fn run(mut conf: Config) -> ViuResult { } std::process::exit(0); }) - .map_err(|_| Error::new(ErrorKind::Other, "Could not setup Ctrl-C handler."))?; + .map_err(|_| Error::other("Could not setup Ctrl-C handler."))?; //TODO: handle multiple files //read stdin if only one parameter is passed and it is "-" @@ -70,7 +70,7 @@ fn view_passed_files(conf: &mut Config, (tx, rx): TxRx) -> ViuResult { //check if Ctrl-C has been received. If yes, stop iterating if rx.try_recv().is_ok() { return tx.send(true).map_err(|_| { - Error::new(ErrorKind::Other, "Could not send signal to clean up.").into() + Error::other("Could not send signal to clean up.").into() }); }; //if it's a directory, stop gif looping because there will probably be more files @@ -91,7 +91,7 @@ fn view_directory(conf: &Config, dirname: &str, (tx, rx): TxRx) -> ViuResult { //check if Ctrl-C has been received. If yes, stop iterating if rx.try_recv().is_ok() { return tx.send(true).map_err(|_| { - Error::new(ErrorKind::Other, "Could not send signal to clean up.").into() + Error::other("Could not send signal to clean up.").into() }); }; let dir_entry = dir_entry_result?; @@ -195,7 +195,7 @@ where // terminal from leftover colors if rx.try_recv().is_ok() { return tx.send(true).map_err(|_| { - Error::new(ErrorKind::Other, "Could not send signal to clean up.").into() + Error::other("Could not send signal to clean up.").into() }); }; From dcd968d11194d79e032bc977a257c115576bea46 Mon Sep 17 00:00:00 2001 From: atanunq Date: Tue, 9 Dec 2025 14:22:34 +0000 Subject: [PATCH 3/6] Fmt --- src/app.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5d3ab9c..b6a2ef6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -69,9 +69,9 @@ fn view_passed_files(conf: &mut Config, (tx, rx): TxRx) -> ViuResult { for filename in &conf.files { //check if Ctrl-C has been received. If yes, stop iterating if rx.try_recv().is_ok() { - return tx.send(true).map_err(|_| { - Error::other("Could not send signal to clean up.").into() - }); + return tx + .send(true) + .map_err(|_| Error::other("Could not send signal to clean up.").into()); }; //if it's a directory, stop gif looping because there will probably be more files if fs::metadata(filename)?.is_dir() { @@ -90,9 +90,9 @@ fn view_directory(conf: &Config, dirname: &str, (tx, rx): TxRx) -> ViuResult { for dir_entry_result in fs::read_dir(dirname)? { //check if Ctrl-C has been received. If yes, stop iterating if rx.try_recv().is_ok() { - return tx.send(true).map_err(|_| { - Error::other("Could not send signal to clean up.").into() - }); + return tx + .send(true) + .map_err(|_| Error::other("Could not send signal to clean up.").into()); }; let dir_entry = dir_entry_result?; @@ -194,9 +194,9 @@ where //if ctrlc is received then respond so the handler can clear the // terminal from leftover colors if rx.try_recv().is_ok() { - return tx.send(true).map_err(|_| { - Error::other("Could not send signal to clean up.").into() - }); + return tx + .send(true) + .map_err(|_| Error::other("Could not send signal to clean up.").into()); }; //keep replacing old pixels as the gif goes on so that scrollback From 2059cc74bdf61cf309a672072e8fbb93e9fc3a01 Mon Sep 17 00:00:00 2001 From: atanunq Date: Tue, 9 Dec 2025 14:27:00 +0000 Subject: [PATCH 4/6] Add --caption to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b26d375..1060dcb 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ Options: Force block output -n, --name Output the name of the file before displaying + -c, --caption + Output the name of the file after displaying -t, --transparent Display transparent images with transparent background -f, --frame-rate From 5a87c97190d18d5392fc760bc796beb794fb07e1 Mon Sep 17 00:00:00 2001 From: atanunq Date: Tue, 9 Dec 2025 15:15:07 +0000 Subject: [PATCH 5/6] Update CI --- .github/workflows/rust.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6c4b6c1..90756b8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,11 +6,10 @@ jobs: check-and-test: runs-on: ubuntu-latest steps: - - uses: hecrj/setup-rust-action@master + - uses: dtolnay/rust-toolchain@stable with: - rust-version: stable components: clippy, rustfmt - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Format run: cargo fmt --all -- --check - name: Lint @@ -49,28 +48,21 @@ jobs: - name: Building ${{ matrix.TARGET }} run: echo "${{ matrix.TARGET }}" - - uses: actions/checkout@master - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - target: ${{ matrix.TARGET }} - override: true - - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --verbose --release --target=${{ matrix.TARGET }} + targets: ${{ matrix.TARGET }} + - run: cargo build --verbose --release --target=${{ matrix.TARGET }} - name: Rename run: cp target/${{ matrix.TARGET }}/release/viu${{ matrix.EXTENSION }} viu-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: viu-${{ matrix.TARGET }}${{ matrix.EXTENSION }} path: viu-${{ matrix.TARGET }}${{ matrix.EXTENSION }} - - uses: softprops/action-gh-release@v1 + - uses: softprops/action-gh-release@v2 name: Upload binaries to release if: startsWith(github.ref, 'refs/tags/') with: From fe84ca77f4b550a197d00584faed3920241b16b8 Mon Sep 17 00:00:00 2001 From: atanunq Date: Tue, 9 Dec 2025 16:39:17 +0000 Subject: [PATCH 6/6] Indirectly use cross --- .github/workflows/rust.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 90756b8..a1b8ce9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -49,10 +49,12 @@ jobs: run: echo "${{ matrix.TARGET }}" - uses: actions/checkout@v6 - - uses: dtolnay/rust-toolchain@stable + - name: Build binary + uses: houseabsolute/actions-rust-cross@v1 with: - targets: ${{ matrix.TARGET }} - - run: cargo build --verbose --release --target=${{ matrix.TARGET }} + command: build + target: ${{ matrix.TARGET }} + args: "--verbose --release" - name: Rename run: cp target/${{ matrix.TARGET }}/release/viu${{ matrix.EXTENSION }} viu-${{ matrix.TARGET }}${{ matrix.EXTENSION }}