pager function respects cli option and user config files, PAGER env var

ammkrn
Apr 8, 2022, 6:06 PM
U6TQX5Z2NF6GX3SRLUBQGCZ7WAXNYMWWZ2YMADUSG4EWVKNV2BIAC

Dependencies

  • [2] JRFPXWID Checking whether the output is a tty is done before checking whether the pager was on, so colours were wrong for some setups
  • [3] 6U42MTEZ Fixing log -- filters, along with performance improvements
  • [4] FDEVV5NG Tag check
  • [5] CCLLB7OI Upgrading to Sanakirja 0.15 + version bump
  • [6] 5YDI33C4 Fixing pager on OSX
  • [7] I24UEJQL Various post-fire fixes
  • [8] SMMBFECL Converting to the new patch format "online"
  • [9] 5BB266P6 Optional colours in the global config file
  • [10] EUZFFJSO Updating Pijul with the latest changes in Libpijul
  • [11] OU6JOR3C Add path filtering for log, add json output for log
  • [12] AAXP2534 Tags: completing the subcommand
  • [13] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [14] GLRGFBCW Checking the version of less we have
  • [15] SFJ3XRTF Proper escaping of UTF-8 filenames in the patch text format
  • [16] NAUECZW3 Fixing the map between keys and identities
  • [17] ZRUPLBBT Colours in diff and change: separating concerns and dependencies
  • [18] F2S6XETO Fixing log --hash-only
  • [19] 6F6AAHK4 Simplifying pijul::commands::log, and fixing Broken Pipe errors
  • [20] RAS4PCNU "Touch" the channel after `pijul diff` if the diff and the prefixes are both empty
  • [21] A3RM526Y Integrating identity malleability
  • [22] Q4SVMHAE Removing --channel from the changes command
  • [23] 2K7JLB4Z No pager on Windows
  • [24] VIHXB7SG commands: set up pager for diff, change, and credit
  • [*] QL6K2ZM3 Tags

Change contents

  • replacement in pijul/src/commands/tag.rs at line 250
    [4.620][5.817:849](),[5.817][5.817:849]()
    super::pager();
    [4.620]
    [5.3129]
    super::pager(repo.config.pager.as_ref());
  • edit in pijul/src/commands/mod.rs at line 123
    [5.3]
    [5.0]
    /// Respect the `pager` key/value pair in both the user's repository config, and their global config.
    /// The global configuration requires no additional arguments, but the other two are optional to cover
    /// cases in which that information is not available. Users can also disable the pager by not setting
    /// the `PAGER` environment variable.
  • replacement in pijul/src/commands/mod.rs at line 128
    [5.13][5.0:21](),[5.21][5.14:71](),[5.29][5.14:71](),[5.71][5.71:119]()
    fn pager() -> bool {
    if let Ok(less) = std::process::Command::new("less")
    .args(&["--version"])
    .output()
    [5.13]
    [5.119]
    fn pager(repo_config_pager: Option<&crate::config::Choice>) -> bool {
    if let Some(crate::config::Choice::Never) = repo_config_pager {
    return false;
    } else if let Some(crate::config::Choice::Never) = crate::config::Global::load()
    .ok()
    .and_then(|(global, _)| global.pager)
  • replacement in pijul/src/commands/mod.rs at line 135
    [5.125][5.125:424](),[5.424][5.22:113](),[5.113][5.485:506](),[5.485][5.485:506](),[5.506][5.114:159]()
    let regex = regex::bytes::Regex::new("less ([0-9]+)").unwrap();
    if let Some(caps) = regex.captures(&less.stdout) {
    if std::str::from_utf8(&caps[1])
    .unwrap()
    .parse::<usize>()
    .unwrap()
    >= 530
    {
    pager::Pager::with_pager("less -RF").setup();
    return true;
    } else {
    pager::Pager::new().setup();
    [5.125]
    [5.550]
    return false;
    } else if let Ok(pager_env_var) = std::env::var("PAGER") {
    if !pager_env_var.is_empty() {
    match pager_env_var.as_str() {
    "less" => {
    if let Ok(pager_output) = std::process::Command::new(pager_env_var)
    .args(&["--version"])
    .output()
    {
    let regex = regex::bytes::Regex::new("less ([0-9]+)").unwrap();
    if let Some(caps) = regex.captures(&pager_output.stdout) {
    if std::str::from_utf8(&caps[1])
    .unwrap()
    .parse::<usize>()
    .unwrap()
    >= 530
    {
    pager::Pager::with_pager("less -RF").setup();
    return true;
    } else {
    pager::Pager::new().setup();
    }
    }
    }
    }
    owise => {
    pager::Pager::with_pager(owise).setup();
    }
  • edit in pijul/src/commands/log.rs at line 58
    [5.311][5.311:354]()
    let repo_path = repo.path.clone();
  • edit in pijul/src/commands/log.rs at line 78
    [5.1253][5.1253:1289]()
    let changes = repo.changes;
  • edit in pijul/src/commands/log.rs at line 92
    [5.1526]
    [5.1526]
    repo,
  • edit in pijul/src/commands/log.rs at line 94
    [5.1543][5.1543:1587]()
    changes,
    repo_path,
  • edit in pijul/src/commands/log.rs at line 269
    [5.7288]
    [5.7288]
    /// The parsed CLI command
    cmd: Log,
  • replacement in pijul/src/commands/log.rs at line 272
    [5.7302][5.7302:7400]()
    changes: libpijul::changestore::filesystem::FileSystem,
    cmd: Log,
    repo_path: PathBuf,
    [5.7302]
    [5.7400]
    repo: Repository,
  • replacement in pijul/src/commands/log.rs at line 326
    [5.10703][3.410:491]()
    let inodes = get_inodes(&self.txn, &self.repo_path, &self.cmd.filters)?;
    [5.10703]
    [3.491]
    let inodes = get_inodes(&self.txn, &self.repo.path, &self.cmd.filters)?;
  • replacement in pijul/src/commands/log.rs at line 380
    [5.2264][5.12512:12570](),[5.12512][5.12512:12570]()
    let header = self.changes.get_header(&h.into())?;
    [5.2264]
    [5.12570]
    let header = self.repo.changes.get_header(&h.into())?;
  • edit in pijul/src/commands/log.rs at line 451
    [5.14264]
    [5.14264]
    let log_iter = LogIterator::try_from(self)?;
  • replacement in pijul/src/commands/log.rs at line 453
    [5.14308][5.14308:14372]()
    match self.output_format.as_ref().map(|s| s.as_str()) {
    [5.14308]
    [5.14372]
    super::pager(log_iter.repo.config.pager.as_ref());
    match log_iter.cmd.output_format.as_ref().map(|s| s.as_str()) {
  • replacement in pijul/src/commands/log.rs at line 458
    [5.14431][5.14431:14521]()
    serde_json::to_writer_pretty(&mut stdout, &LogIterator::try_from(self)?)?
    [5.14431]
    [5.14521]
    serde_json::to_writer_pretty(&mut stdout, &log_iter)?
  • replacement in pijul/src/commands/log.rs at line 460
    [5.14535][5.14535:14586](),[5.14586][5.3950:4288](),[5.4288][5.136485:136499](),[5.14683][5.136485:136499](),[5.136485][5.136485:136499]()
    _ => {
    super::pager();
    LogIterator::try_from(self)?.for_each(|entry| {
    match write!(&mut stdout, "{}", entry) {
    Ok(_) => Ok(()),
    Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()),
    Err(e) => Err(e),
    }
    })?
    }
    [5.14535]
    [5.136499]
    _ => log_iter.for_each(|entry| match write!(&mut stdout, "{}", entry) {
    Ok(_) => Ok(()),
    Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()),
    Err(e) => Err(e),
    })?,
  • replacement in pijul/src/commands/diff.rs at line 135
    [5.175777][5.316:351]()
    let colors = is_colored();
    [5.175777]
    [5.175777]
    let colors = is_colored(repo.config.pager.as_ref());
  • replacement in pijul/src/commands/diff.rs at line 339
    [5.400][5.400:430]()
    pub fn is_colored() -> bool {
    [5.400]
    [5.430]
    pub fn is_colored(repo_config_pager: Option<&crate::config::Choice>) -> bool {
  • replacement in pijul/src/commands/diff.rs at line 350
    [5.845][5.845:877]()
    super::pager();
    [5.845]
    [5.877]
    super::pager(repo_config_pager);
  • replacement in pijul/src/commands/diff.rs at line 354
    [5.905][2.0:34]()
    colors &= super::pager();
    [5.905]
    [5.2096]
    colors &= super::pager(repo_config_pager);
  • replacement in pijul/src/commands/credit.rs at line 52
    [5.180284][5.213:237]()
    super::pager();
    [5.180243]
    [5.16703]
    super::pager(repo.config.pager.as_ref());
  • replacement in pijul/src/commands/change.rs at line 42
    [5.419][5.952:1000]()
    let colors = super::diff::is_colored();
    [5.190342]
    [5.2150]
    let colors = super::diff::is_colored(repo.config.pager.as_ref());