Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ clap_complete_nushell = "4.5.10"
satty_cli.workspace = true
clap_complete_fig = "4.5.2"
relm4-icons-build = "0.10"
clap_mangen = "0.2.31"

[workspace]
members = [ "cli" ]
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install: target/release/satty
install -s -Dm755 target/release/satty -t ${PREFIX}/bin/
install -Dm644 satty.desktop ${PREFIX}/share/applications/satty.desktop
install -Dm644 assets/satty.svg ${PREFIX}/share/icons/hicolor/scalable/apps/satty.svg

install -Dm644 satty.1 ${PREFIX}/share/man/man1
install -Dm644 LICENSE ${PREFIX}/share/licenses/satty/LICENSE

uninstall:
Expand All @@ -44,6 +44,7 @@ uninstall:
rm ${PREFIX}/share/licenses/satty/LICENSE
rmdir -p ${PREFIX}/share/licenses/satty || true

rm ${PREFIX}/share/man/man1/satty.1

package: clean build-release
$(eval TMP := $(shell mktemp -d))
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Thanks to our package maintainers, Satty is available for many distributions on
| Gentoo | `emerge -av satty` | You need guru overlay (see [wiki](https://github.com/gabm/Satty/wiki/Gentoo-Guru)). Pending [PR](https://github.com/gentoo/gentoo/pull/33908) |
| Alpine Linux | `apk add satty` | Available in [Alpine Community](https://pkgs.alpinelinux.org/packages?name=satty&branch=edge&repo=&arch=&maintainer=) |

### Cargo

You can install satty via `cargo install satty` and `cargo binstall satty`, the latter requires [cargo-binstall](https://crates.io/crates/cargo-binstall). In that case, no manpage, LICENSE file, .Desktop file are available. But you can use the `--man` and `--license` arguments to display either.

### Prebuilt Sources

You can download a prebuilt binary for x86-64 on the [Satty Releases](https://github.com/gabm/satty/releases) page.
Expand Down Expand Up @@ -217,6 +221,10 @@ Modern Screenshot Annotation.
Usage: satty [OPTIONS] --filename <FILENAME>

Options:
--man
Show manpage. Pipe to man -l -
--license
Show license
-c, --config <CONFIG>
Path to the config file. Otherwise will be read from XDG_CONFIG_DIR/satty/config.toml
-f, --filename <FILENAME>
Expand Down
24 changes: 17 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
#[allow(dead_code)]
use std::borrow::BorrowMut;
use std::fs;
use std::io;

use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use clap_complete_fig::Fig;
use clap_complete_nushell::Nushell;
use clap_mangen::Man;

use satty_cli::command_line;

fn main() -> Result<(), io::Error> {
let cmd = &mut command_line::CommandLine::command();
let out_dir =
std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?);
let mut cmd = command_line::CommandLine::command();
let cmd2 = cmd.borrow_mut();
let bin = "satty";
let out = "completions";

fs::create_dir_all(out)?;
generate_to(Shell::Bash, cmd, bin, out)?;
generate_to(Shell::Fish, cmd, bin, out)?;
generate_to(Shell::Zsh, cmd, bin, out)?;
generate_to(Shell::Elvish, cmd, bin, out)?;
generate_to(Nushell, cmd, bin, out)?;
generate_to(Fig, cmd, bin, out)?;
generate_to(Shell::Bash, cmd2, bin, out)?;
generate_to(Shell::Fish, cmd2, bin, out)?;
generate_to(Shell::Zsh, cmd2, bin, out)?;
generate_to(Shell::Elvish, cmd2, bin, out)?;
generate_to(Nushell, cmd2, bin, out)?;
generate_to(Fig, cmd2, bin, out)?;

let man = Man::new(cmd);
let mut buffer: Vec<u8> = Default::default();
man.title(bin).render(&mut buffer)?;
std::fs::write(out_dir.join(format!("{}.1", bin)), buffer)?;

relm4_icons_build::bundle_icons(
"icon_names.rs",
Expand Down
14 changes: 11 additions & 3 deletions cli/src/command_line.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use clap::{Parser, ValueEnum};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
#[command(author, version, about, long_about = None, name="satty")]
pub struct CommandLine {
/// Show manpage. Pipe to man -l -.
#[arg(long, exclusive = true)]
pub man: bool,

/// Show license.
#[arg(long, exclusive = true)]
pub license: bool,

/// Path to the config file. Otherwise will be read from XDG_CONFIG_DIR/satty/config.toml
#[arg(short, long)]
pub config: Option<String>,

/// Path to input image or '-' to read from stdin
#[arg(short, long)]
pub filename: String,
#[arg(short, long, required = true)]
pub filename: Option<String>,

/// Start Satty in fullscreen mode
#[arg(long)]
Expand Down
27 changes: 24 additions & 3 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ enum ConfigurationFileError {
}

pub struct Configuration {
input_filename: String,
man: bool,
license: bool,
input_filename: Option<String>,
output_filename: Option<String>,
fullscreen: bool,
early_exit: bool,
Expand Down Expand Up @@ -350,6 +352,12 @@ impl Configuration {
}

// overwrite with all specified values from command line
if command_line.man {
self.man = command_line.man;
}
if command_line.license {
self.license = command_line.license;
}
if command_line.fullscreen {
self.fullscreen = command_line.fullscreen;
}
Expand Down Expand Up @@ -444,6 +452,14 @@ impl Configuration {
// ---
}

pub fn man(&self) -> bool {
self.man
}

pub fn license(&self) -> bool {
self.license
}

pub fn early_exit(&self) -> bool {
self.early_exit
}
Expand Down Expand Up @@ -473,7 +489,10 @@ impl Configuration {
}

pub fn input_filename(&self) -> &str {
self.input_filename.as_ref()
match self.input_filename {
Some(ref v) => v,
None => "",
}
}

pub fn annotation_size_factor(&self) -> f32 {
Expand Down Expand Up @@ -559,7 +578,9 @@ impl Configuration {
impl Default for Configuration {
fn default() -> Self {
Self {
input_filename: String::new(),
man: false,
license: false,
input_filename: Some(String::new()),
output_filename: None,
fullscreen: false,
early_exit: false,
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::io::Read;
use std::sync::LazyLock;
use std::{fs, ptr};
use std::{io, time::Duration};

use configuration::{Configuration, APP_CONFIG};
use gdk_pixbuf::gio::ApplicationFlags;
use gdk_pixbuf::{Pixbuf, PixbufLoader};
use gtk::prelude::*;
use std::io::Read;
use std::process::exit;
use std::sync::LazyLock;
use std::{fs, ptr};
use std::{io, time::Duration};

use relm4::gtk::gdk::Rectangle;

Expand Down Expand Up @@ -399,6 +399,14 @@ fn main() -> Result<()> {
// populate the APP_CONFIG from commandline and
// config file. this might exit, if an error occurred.
Configuration::load();
if APP_CONFIG.read().man() {
print!(include_str!(concat!(env!("OUT_DIR"), "/satty.1")));
exit(0);
}
if APP_CONFIG.read().license() {
print!(include_str!("../LICENSE"));
exit(0);
}
if APP_CONFIG.read().profile_startup() {
eprintln!(
"startup timestamp was {}",
Expand Down