From d4c44512ecc415db7534219344c0d15a6e814c3e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 15 Oct 2024 13:55:55 +0200 Subject: Greet users who run `typst` for the first time (#5210) --- crates/typst-cli/src/args.rs | 31 ++++++++++++++++++-- crates/typst-cli/src/greet.rs | 66 +++++++++++++++++++++++++++++++++++++++++++ crates/typst-cli/src/main.rs | 13 +++++++-- 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 crates/typst-cli/src/greet.rs (limited to 'crates/typst-cli/src') diff --git a/crates/typst-cli/src/args.rs b/crates/typst-cli/src/args.rs index 65259ab7..7436d25c 100644 --- a/crates/typst-cli/src/args.rs +++ b/crates/typst-cli/src/args.rs @@ -13,9 +13,36 @@ use semver::Version; /// in environment variables. const ENV_PATH_SEP: char = if cfg!(windows) { ';' } else { ':' }; -/// The Typst compiler. +/// The overall structure of the help. +#[rustfmt::skip] +const HELP_TEMPLATE: &str = "\ +Typst {version} + +{usage-heading} {usage} + +{all-args}{after-help}\ +"; + +/// Adds a list of useful links after the normal help. +#[rustfmt::skip] +const AFTER_HELP: &str = color_print::cstr!("\ +Resources: + Tutorial: https://typst.app/docs/tutorial/ + Reference documentation: https://typst.app/docs/reference/ + Templates & Packages: https://typst.app/universe/ + Forum for questions: https://forum.typst.app/ +"); + +/// The Typst compiler #[derive(Debug, Clone, Parser)] -#[clap(name = "typst", version = crate::typst_version(), author)] +#[clap( + name = "typst", + version = crate::typst_version(), + author, + help_template = HELP_TEMPLATE, + after_help = AFTER_HELP, + max_term_width = 80, +)] pub struct CliArguments { /// The command to run #[command(subcommand)] diff --git a/crates/typst-cli/src/greet.rs b/crates/typst-cli/src/greet.rs new file mode 100644 index 00000000..01f273fc --- /dev/null +++ b/crates/typst-cli/src/greet.rs @@ -0,0 +1,66 @@ +use std::io::{self, Read}; + +/// This is shown to users who just type `typst` the first time. +#[rustfmt::skip] +const GREETING: &str = color_print::cstr!("\ +Welcome to Typst, we are glad to have you here! ❤️ + +If you are new to Typst, start with the tutorial at \ +https://typst.app/docs/tutorial/. To get a quick start with your first \ +project, choose a template on https://typst.app/universe/. + +Here are the most important commands you will be using: + +- Compile a file once: typst compile file.typ +- Compile a file on every change: typst watch file.typ +- Set up a project from a template: typst init @preview/<