Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ tokio = { version = "1", features = ["process", "time"] }
# Extra syntax highlighting
syntect = "5.2.0"
two-face = "0.4.3"
# CLI arguments
clap_lex = "0.7"
# Internationalization
icu_collator = "1.5"
icu_provider = { version = "1.5", features = ["sync"] }
Expand Down
43 changes: 42 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ mod tab;
use self::text_box::text_box;
mod text_box;

use clap_lex::RawArgs;

use std::error::Error;

static ICON_CACHE: OnceLock<Mutex<IconCache>> = OnceLock::new();
static LINE_NUMBER_CACHE: OnceLock<Mutex<LineNumberCache>> = OnceLock::new();
static SWASH_CACHE: OnceLock<Mutex<SwashCache>> = OnceLock::new();
Expand All @@ -79,7 +83,29 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> icon::Icon {
icon_cache.get(name, size)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() -> Result<(), Box<dyn Error>> {
let raw_args = RawArgs::from_args();
let mut cursor = raw_args.cursor();

// Parse the arguments
while let Some(arg) = raw_args.next_os(&mut cursor) {
match arg.to_str() {
Some("--help") | Some("-h") => {
print_help(env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA"));
return Ok(());
}
Some("--version") | Some("-V") => {
println!(
"cosmic-edit {} (git commit {})",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA")
);
return Ok(());
}
_ => {}
}
}

#[cfg(all(unix, not(target_os = "redox")))]
match fork::daemon(true, true) {
Ok(fork::Fork::Child) => (),
Expand Down Expand Up @@ -182,6 +208,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn print_help(version: &str, git_rev: &str) {
println!(
r#"cosmic-edit {version} (git commit {git_rev})
System76 <[email protected]>

Designed for the COSMIC™ desktop environment, cosmic-edit is a libcosmic-based text editor.

Project home page: https://github.com/pop-os/cosmic-edit

Options:
-h, --help Show this message
-v, --version Show the version of cosmic-edit"#
);
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum Action {
Todo,
Expand Down