Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use minus for pagination when watching #3642

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 83 additions & 22 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ciborium = "0.2.1"
clap = { version = "4.4", features = ["derive", "env"] }
clap_complete = "4.2.1"
clap_mangen = "0.2.10"
ctrlc = "3.4.1"
crossterm = "0.27.0"
codespan-reporting = "0.11"
comemo = "0.4"
csv = "1"
Expand All @@ -64,6 +64,7 @@ libfuzzer-sys = "0.4"
lipsum = "0.9"
log = "0.4"
miniz_oxide = "0.7"
minus = "5.5.3"
native-tls = "0.2"
notify = "6"
once_cell = "1"
Expand Down
3 changes: 2 additions & 1 deletion crates/typst-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ chrono = { workspace = true }
clap = { workspace = true }
codespan-reporting = { workspace = true }
comemo = { workspace = true }
ctrlc = { workspace = true }
crossterm = { workspace = true }
dirs = { workspace = true }
ecow = { workspace = true }
env_proxy = { workspace = true }
flate2 = { workspace = true }
fontdb = { workspace = true, features = ["memmap", "fontconfig"] }
fs_extra = { workspace = true }
minus = { workspace = true, features = ["dynamic_output"] }
native-tls = { workspace = true }
notify = { workspace = true }
once_cell = { workspace = true }
Expand Down
23 changes: 21 additions & 2 deletions crates/typst-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub struct CliArguments {
#[command(subcommand)]
pub command: Command,

/// Set when to use color.
/// auto = use color if a capable terminal is detected
/// Decide when to use color.
#[clap(
long,
value_name = "WHEN",
Expand All @@ -29,11 +28,31 @@ pub struct CliArguments {
)]
pub color: ColorChoice,

/// Decide when a pager should be used.
#[clap(long, value_name = "WHEN", default_value_t = PaginationChoice::Auto)]
pub pager: PaginationChoice,

/// Path to a custom CA certificate to use when making network requests.
#[clap(long = "cert", env = "TYPST_CERT")]
pub cert: Option<PathBuf>,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum PaginationChoice {
Auto,
Never,
Always,
}

impl fmt::Display for PaginationChoice {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}

/// What to do.
#[derive(Debug, Clone, Subcommand)]
#[command()]
Expand Down
11 changes: 3 additions & 8 deletions crates/typst-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::process::ExitCode;
use clap::Parser;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::WriteColor;
use ecow::eco_format;
use once_cell::sync::Lazy;

use crate::args::{CliArguments, Command};
Expand All @@ -37,6 +36,8 @@ static ARGS: Lazy<CliArguments> = Lazy::new(CliArguments::parse);
fn main() -> ExitCode {
let timer = Timer::new(&ARGS);

terminal::init();

let res = match &ARGS.command {
Command::Compile(command) => crate::compile::compile(timer, command.clone()),
Command::Watch(command) => crate::watch::watch(timer, command.clone()),
Expand All @@ -46,13 +47,7 @@ fn main() -> ExitCode {
Command::Update(command) => crate::update::update(command),
};

// Leave the alternate screen if it was opened. This operation is done here
// so that it is executed prior to printing the final error.
let res_leave = terminal::out()
.leave_alternate_screen()
.map_err(|err| eco_format!("failed to leave alternate screen ({err})"));

if let Some(msg) = res.err().or(res_leave.err()) {
if let Err(msg) = res {
set_failed();
print_error(&msg).expect("failed to print error");
}
Expand Down