Launcher: screenshots gallery per instance
Home shows the selected instance's newest screenshots (what F2 saves in its screenshots/ folder), all of them on request, and opens one over the window with Newer/Older (and the arrow keys), Copy (the picture to the clipboard), Open, Show in folder and Delete (to the trash, after a confirmation). CLI: `screenshots [list|delete] [--instance]`; `screenshots delete` needs confirm over MCP. worlds::to_trash is shared by worlds and screenshots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,6 +214,23 @@ enum WorldsCmd {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum ScreenshotsCmd {
|
||||
/// The screenshots, the newest first, with their files (the default)
|
||||
List {
|
||||
/// The instance (default: the selected one)
|
||||
#[arg(long)]
|
||||
instance: Option<String>,
|
||||
},
|
||||
/// Move a screenshot to the system's trash
|
||||
Delete {
|
||||
/// Its file name, with or without .png
|
||||
screenshot: String,
|
||||
#[arg(long)]
|
||||
instance: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum MultiplayerCmd {
|
||||
/// The servers of the game's Multiplayer screen (the default)
|
||||
@@ -442,6 +459,11 @@ enum Cmd {
|
||||
#[command(subcommand)]
|
||||
action: Option<WorldsCmd>,
|
||||
},
|
||||
/// The screenshots F2 took in an instance: list, delete
|
||||
Screenshots {
|
||||
#[command(subcommand)]
|
||||
action: Option<ScreenshotsCmd>,
|
||||
},
|
||||
/// The servers in an instance's Multiplayer list (servers.dat): list, add, remove
|
||||
Multiplayer {
|
||||
#[command(subcommand)]
|
||||
@@ -911,6 +933,10 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> {
|
||||
action.unwrap_or(WorldsCmd::List { instance: None }),
|
||||
as_json,
|
||||
)?,
|
||||
Cmd::Screenshots { action } => screenshots(
|
||||
action.unwrap_or(ScreenshotsCmd::List { instance: None }),
|
||||
as_json,
|
||||
)?,
|
||||
Cmd::Multiplayer { action } => multiplayer(
|
||||
action.unwrap_or(MultiplayerCmd::List { instance: None }),
|
||||
as_json,
|
||||
@@ -1542,6 +1568,50 @@ fn instance(action: InstanceCmd, as_json: bool) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn screenshots(action: ScreenshotsCmd, as_json: bool) -> Result<(), String> {
|
||||
use horizon_launcher::screenshots;
|
||||
let home = |instance: Option<String>| -> Result<PathBuf, String> {
|
||||
Ok(match instance {
|
||||
Some(name) => instances::find(&name)?.home,
|
||||
None => instances::selected().home,
|
||||
})
|
||||
};
|
||||
match action {
|
||||
ScreenshotsCmd::List { instance } => {
|
||||
let home = home(instance)?;
|
||||
let shots = screenshots::list(&home);
|
||||
if as_json {
|
||||
json(
|
||||
shots
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let millis = s
|
||||
.taken
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |d| d.as_millis() as u64);
|
||||
serde_json::json!({ "name": s.name, "path": s.path, "taken_ms": millis, "size": s.size })
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
} else if shots.is_empty() {
|
||||
println!("No screenshots in {}", screenshots::folder(&home).display());
|
||||
}
|
||||
for s in shots.iter().filter(|_| !as_json) {
|
||||
println!("{}", s.path.display());
|
||||
}
|
||||
}
|
||||
ScreenshotsCmd::Delete {
|
||||
screenshot,
|
||||
instance,
|
||||
} => {
|
||||
let shot = screenshots::find(&home(instance)?, &screenshot)?;
|
||||
screenshots::delete(&shot)?;
|
||||
println!("{} is in the trash.", shot.name);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn multiplayer(action: MultiplayerCmd, as_json: bool) -> Result<(), String> {
|
||||
let home = |instance: Option<String>| -> Result<PathBuf, String> {
|
||||
Ok(match instance {
|
||||
|
||||
Reference in New Issue
Block a user