use clap::Parser;
#[derive(Parser, Debug)]
#[command(name = "nanorust")]
#[command(author, version, about = "A nano-like text editor written in Rust", long_about = None)]
struct Cli {
#[arg(short = 'm', long = "mouse")]
mouse: bool,
#[arg(short = 'i', long = "autoindent")]
autoindent: bool,
#[arg(short = 'l', long = "linenumbers")]
linenumbers: bool,
#[arg(short = 'c', long = "constantshow")]
constantshow: bool,
#[arg(short = '$', long = "softwrap")]
softwrap: bool,
#[arg(short = 'w', long = "nowrap")]
nowrap: bool,
#[arg(short = 'v', long = "view")]
view: bool,
#[arg(value_name = "FILE")]
filename: Option<String>,
}
#[derive(Debug, Clone)]
pub struct Config {
pub auto_indent: bool,
pub show_line_numbers: bool,
pub mouse_support: bool,
pub soft_wrap: bool,
pub no_wrap: bool,
pub tab_size: usize,
pub syntax_highlighting: bool,
pub view_only: bool,
pub show_cursor_position: bool,
pub line_width: usize,
pub use_spaces: bool,
}
impl Config {
pub fn new() -> Self {
Self::default()
}
pub fn default() -> Self {
Config {
auto_indent: false,
show_line_numbers: false,
mouse_support: false,
soft_wrap: false,
no_wrap: false,
tab_size: 4,
syntax_highlighting: true,
view_only: false,
show_cursor_position: false,
line_width: 80,
use_spaces: false,
}
}
pub fn from_args() -> (Self, Option<String>) {
let cli = Cli::parse();
let config = Config {
auto_indent: cli.autoindent,
show_line_numbers: cli.linenumbers,
mouse_support: cli.mouse,
soft_wrap: cli.softwrap,
no_wrap: cli.nowrap,
tab_size: 4,
syntax_highlighting: true,
view_only: cli.view,
show_cursor_position: cli.constantshow,
line_width: 80,
use_spaces: false,
};
(config, cli.filename)
}
}
impl Default for Config {
fn default() -> Self {
Self::default()
}
}