Skip to content

Commit

Permalink
fix: Moved Size and Position into CLI because xtas k does not depend …
Browse files Browse the repository at this point in the history
…on inlyne and removed unnecessary & in main.rs
  • Loading branch information
kokoISnoTarget committed Mar 27, 2024
1 parent f7889e0 commit ba98ebd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Inlyne {
let event_loop = EventLoopBuilder::<InlyneEvent>::with_user_event().build();

let window = {
let mut wb = WindowBuilder::new().with_title(&utils::format_title(&file_path));
let mut wb = WindowBuilder::new().with_title(utils::format_title(&file_path));

if let Some(ref pos) = opts.position {
wb = wb.with_position(winit::dpi::PhysicalPosition::new(pos.x, pos.y))
Expand Down
49 changes: 48 additions & 1 deletion src/opts/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{Position, Size};
use clap::{
builder::PossibleValue, command, value_parser, Args as ClapArgs, Parser, Subcommand, ValueEnum,
};
use serde::Deserialize;
use std::path::PathBuf;
use std::str::FromStr;

#[derive(Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ThemeType {
Expand Down Expand Up @@ -33,6 +33,53 @@ impl ValueEnum for ThemeType {
}
}

#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
pub struct Position {
pub x: i32,
pub y: i32,
}

impl FromStr for Position {
type Err = &'static str;

fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = input.split(',').collect();
if parts.len() != 2 {
return Err("Invalid format for Position: expected format <x>,<y>");
}
let x = parts[0]
.parse::<i32>()
.map_err(|_| "Invalid x-coordinate: not a valid integer")?;
let y = parts[1]
.parse::<i32>()
.map_err(|_| "Invalid y-coordinate: not a valid integer")?;
Ok(Position { x, y })
}
}

#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
pub struct Size {
pub width: u32,
pub height: u32,
}
impl FromStr for Size {
type Err = &'static str;

fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = input.split('x').collect();
if parts.len() != 2 {
return Err("Invalid format for Size: expected format <width>x<height>");
}
let width = parts[0]
.parse::<u32>()
.map_err(|_| "Invalid width: not a valid integer")?;
let height = parts[1]
.parse::<u32>()
.map_err(|_| "Invalid height: not a valid integer")?;
Ok(Size { width, height })
}
}

#[derive(Debug, PartialEq, Clone, Parser)]
#[command(version, about, arg_required_else_help(true))]
#[clap(args_conflicts_with_subcommands = true)]
Expand Down
50 changes: 1 addition & 49 deletions src/opts/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::fs::{create_dir_all, read_to_string};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use super::ThemeType;
use super::{Position, Size, ThemeType};
use crate::color;
use crate::keybindings::Keybindings;

Expand Down Expand Up @@ -89,53 +88,6 @@ pub struct DebugSection {
pub metrics: Option<MetricsExporter>,
}

#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
pub struct Position {
pub x: i32,
pub y: i32,
}

impl FromStr for Position {
type Err = &'static str;

fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = input.split(',').collect();
if parts.len() != 2 {
return Err("Invalid format for Position: expected format <x>,<y>");
}
let x = parts[0]
.parse::<i32>()
.map_err(|_| "Invalid x-coordinate: not a valid integer")?;
let y = parts[1]
.parse::<i32>()
.map_err(|_| "Invalid y-coordinate: not a valid integer")?;
Ok(Position { x, y })
}
}

#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
pub struct Size {
pub width: u32,
pub height: u32,
}
impl FromStr for Size {
type Err = &'static str;

fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = input.split('x').collect();
if parts.len() != 2 {
return Err("Invalid format for Size: expected format <width>x<height>");
}
let width = parts[0]
.parse::<u32>()
.map_err(|_| "Invalid width: not a valid integer")?;
let height = parts[1]
.parse::<u32>()
.map_err(|_| "Invalid height: not a valid integer")?;
Ok(Size { width, height })
}
}

#[derive(Deserialize, Debug, Default, PartialEq)]
#[serde(default, rename_all = "kebab-case")]
pub struct Config {
Expand Down
6 changes: 2 additions & 4 deletions src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ mod tests;
use std::path::Path;

use crate::color;
pub use cli::{Cli, Commands, ConfigCmd, ThemeType, View};
pub use config::{
Config, DebugSection, FontOptions, KeybindingsSection, MetricsExporter, Position, Size,
};
pub use cli::{Cli, Commands, ConfigCmd, Position, Size, ThemeType, View};
pub use config::{Config, DebugSection, FontOptions, KeybindingsSection, MetricsExporter};

use crate::history::History;
use anyhow::Result;
Expand Down

0 comments on commit ba98ebd

Please sign in to comment.