Remove old non-tui view and remove tui feature

This commit is contained in:
Patrick Auernig 2023-08-14 21:07:56 +02:00
parent 5258447579
commit ccf7376637
9 changed files with 64 additions and 199 deletions

4
Cargo.lock generated
View File

@ -444,7 +444,7 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "jrny-save"
version = "0.3.0"
version = "0.4.0"
dependencies = [
"binrw",
"chrono",
@ -1064,7 +1064,7 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wayfarer"
version = "0.3.0"
version = "0.4.0"
dependencies = [
"anyhow",
"clap",

View File

@ -7,7 +7,7 @@ members = [
[workspace.package]
version = "0.3.0"
version = "0.4.0"
edition = "2021"
license-file = "LICENSE"

View File

@ -13,11 +13,11 @@ cargo install --git https://github.com/valeth/wayfarer
Make sure the path cargo installs to is in your system's `PATH`.
```sh
wayfarer tui
wayfarer
# or
# of if you want to override the last remembered file
wayfarer show <path-to-savefile>
wayfarer --path <path-to-savefile>
```

View File

@ -18,27 +18,23 @@ version = "4.3"
features = ["derive"]
[dependencies.jrny-save]
version = "0.3"
version = "0.4"
path = "../save"
[dependencies.ratatui]
version = "0.22"
[dependencies.tui-input]
version = "0.8"
[dependencies.crossterm]
version = "0.27"
[dependencies.notify]
version = "6.0"
optional = true
[dependencies.ratatui]
version = "0.22"
optional = true
[dependencies.tui-input]
version = "0.8"
optional = true
[dependencies.crossterm]
version = "0.27"
optional = true
[features]
default = ["watch", "tui"]
default = ["watch"]
watch = ["dep:notify"]
tui = ["dep:ratatui", "dep:tui-input", "dep:crossterm"]

View File

@ -6,7 +6,7 @@ use clap::builder::PossibleValuesParser;
use clap::{value_parser, Parser as ArgParser};
use jrny_save::{RobeColor, Savefile, LEVEL_NAMES};
use crate::Args as AppArgs;
use crate::AppArgs;
#[derive(Debug, Clone, ArgParser)]

View File

@ -1,5 +1,4 @@
mod edit;
mod show;
mod tui;
mod watcher;
@ -26,37 +25,31 @@ lazy_static::lazy_static! {
#[derive(Debug, ArgParser)]
#[command(author, version, about)]
pub(crate) struct Args {
pub(crate) struct AppArgs {
#[command(flatten)]
tui_args: tui::Args,
#[command(subcommand)]
command: CommandArgs,
command: Option<CommandArgs>,
}
#[derive(Debug, Clone, clap::Subcommand)]
pub(crate) enum CommandArgs {
/// Display info about save files
Show(show::Args),
/// Edit verious aspect of save files
Edit(edit::Args),
#[cfg(feature = "tui")]
Tui(tui::Args),
}
fn main() -> Result<()> {
tracing_setup()?;
let args = Args::parse();
let args = AppArgs::parse();
match &args.command {
CommandArgs::Show(sub_args) => show::execute(&args, sub_args)?,
CommandArgs::Edit(sub_args) => edit::execute(&args, sub_args)?,
#[cfg(feature = "tui")]
CommandArgs::Tui(sub_args) => tui::execute(&args, sub_args)?,
Some(CommandArgs::Edit(sub_args)) => edit::execute(&args, sub_args)?,
None => tui::execute(&args.tui_args)?,
}
Ok(())

View File

@ -1,146 +0,0 @@
use std::fs::File;
use std::path::{Path, PathBuf};
use anyhow::Result;
use clap::Parser as ArgParser;
use jrny_save::Savefile;
use crate::Args as AppArgs;
#[derive(Debug, Clone, ArgParser)]
pub struct Args {
path: PathBuf,
#[cfg(feature = "watch")]
#[arg(long, default_value_t = false)]
watch: bool,
}
pub(crate) fn execute(_app_args: &AppArgs, args: &Args) -> Result<()> {
if !args.path.exists() {
anyhow::bail!("Could not find file at given path");
}
show_all_info(&args.path)?;
#[cfg(feature = "watch")]
if args.watch {
watch_all_info(&args.path)?;
}
Ok(())
}
#[cfg(feature = "watch")]
fn watch_all_info<P>(path: P) -> Result<()>
where
P: AsRef<Path>,
{
use std::sync::mpsc;
use crate::watcher::FileWatcher;
let (tx, rx) = mpsc::channel();
let _watcher = FileWatcher::new(path.as_ref(), move || {
tx.send(()).unwrap();
});
println!("Watching file for changes...");
loop {
let _ = rx.recv()?;
show_all_info(&path).unwrap();
}
}
fn show_all_info<P>(path: P) -> Result<()>
where
P: AsRef<Path>,
{
let file = File::open(path)?;
let savefile = Savefile::from_reader(file)?;
println!("------======::::: WAYFARER :::::======------\n");
general_info(&savefile);
println!("\n---===---===---===---===---===---===---===---\n");
current_journey(&savefile);
println!("\n---===---===---===---===---===---===---===---\n");
glyphs(&savefile);
println!("\n---===---===---===---===---===---===---===---\n");
murals(&savefile);
println!("\n---===---===---===---===---===---===---===---\n");
current_companions(&savefile);
println!("\n---===---===---===---===---===---===---===---\n");
past_companions(&savefile);
println!("\n------======::::::::::::::::::::======------");
Ok(())
}
fn general_info(savefile: &Savefile) {
println!("Journeys Completed: {:>}", savefile.journey_count);
println!("Total Companions Met: {:>}", savefile.total_companions_met);
println!(
"Total Symbols Collected: {}",
savefile.total_collected_symbols
);
}
fn current_journey(savefile: &Savefile) {
println!("Current Level: {:<10}", savefile.current_level_name());
println!("Companions Met: {:<10}", savefile.companions_met);
println!("Scarf Length: {:<10}", savefile.scarf_length);
println!("Symbol Number: {:<10}", savefile.symbol.id);
println!(
"Robe: {:<10}, Tier {}",
savefile.robe_color(),
savefile.robe_tier()
);
println!("Last Played: {:<10}", savefile.last_played);
}
fn current_companions(savefile: &Savefile) {
for companion in savefile.current_companions() {
println!(
"{:24} {}",
companion.name,
companion.steam_url().to_string()
);
}
}
fn past_companions(savefile: &Savefile) {
for companion in savefile.past_companions() {
println!(
"{:24} {}",
companion.name,
companion.steam_url().to_string()
);
}
}
fn glyphs(savefile: &Savefile) {
for (level, glyphs) in savefile.glyphs.all() {
print!("{:<16} ", jrny_save::LEVEL_NAMES[level]);
for glyph in glyphs {
print!("{:3}", if glyph { "X" } else { "O" });
}
println!();
}
}
fn murals(savefile: &Savefile) {
for (level, murals) in savefile.murals.all() {
print!("{:<16} ", jrny_save::LEVEL_NAMES[level]);
for mural in murals {
print!("{:3}", if mural { "X" } else { "O" });
}
println!();
}
}

View File

@ -1,11 +1,10 @@
#![cfg(feature = "tui")]
mod events;
mod state;
mod view;
use std::io::{self, Stdout};
use std::path::PathBuf;
use std::sync::mpsc::{self, TryRecvError};
use anyhow::Result;
@ -21,14 +20,17 @@ use ratatui::backend::CrosstermBackend;
use tracing::{debug, error, info};
use self::state::{Mode, State};
use crate::Args as AppArgs;
type Terminal = ratatui::Terminal<CrosstermBackend<Stdout>>;
#[derive(Debug, Clone, ArgParser)]
pub struct Args;
pub struct Args {
/// Overrides the last loaded file
#[arg(long, short)]
path: Option<PathBuf>,
}
#[derive(Debug, Clone)]
@ -47,8 +49,15 @@ pub enum Message {
}
pub(crate) fn execute(_app_args: &AppArgs, _args: &Args) -> Result<()> {
let state = State::load()?;
pub(crate) fn execute(args: &Args) -> Result<()> {
let state = match &args.path {
Some(path) => {
let mut state = State::default();
state.set_savefile_from_path(path)?;
state
}
None => State::load()?,
};
let mut terminal = setup()?;

View File

@ -1,6 +1,7 @@
use std::fs::{self, create_dir_all, read_to_string};
use std::io::Write;
use std::os::unix::prelude::OsStrExt;
use std::path::Path;
use anyhow::Result;
use jrny_save::Savefile;
@ -12,15 +13,6 @@ use crate::watcher::FileWatcher;
use crate::DIRS;
pub struct State {
savefile: Option<Savefile>,
pub mode: Mode,
pub file_select: Input,
#[cfg(feature = "watch")]
file_watcher: Option<FileWatcher>,
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub enum Mode {
#[default]
@ -31,6 +23,17 @@ pub enum Mode {
SelectFile,
}
#[derive(Default)]
pub struct State {
savefile: Option<Savefile>,
pub mode: Mode,
pub file_select: Input,
#[cfg(feature = "watch")]
file_watcher: Option<FileWatcher>,
}
impl State {
pub fn load() -> Result<Self> {
let data_dir = DIRS.data_local_dir();
@ -54,6 +57,16 @@ impl State {
self.savefile.as_ref()
}
pub fn set_savefile_from_path<P>(&mut self, path: P) -> Result<()>
where
P: AsRef<Path>,
{
let savefile = Savefile::from_path(path)?;
self.savefile = Some(savefile);
Ok(())
}
pub fn set_selected_as_active_savefile(&mut self) -> Result<()> {
let savefile = Savefile::from_path(&self.file_select.value())?;