Skip to main content

write_program_resume

Function write_program_resume 

Source
pub fn write_program_resume<W: Write>(
    w: &mut W,
    report: &ProgramResume<'_>,
    pid: u32,
    time: u64,
    token: &str,
) -> Result<()>
Expand description

Write one program resume report without flushing.

pid is the process that report brings back. It is usually std::process::id, but a wrapper can report for the process it starts. time is the current time in seconds since the Unix epoch. Terminals ignore a report whose time is far from their clock, so build each report when it is sent. token is the value of TOKEN_ENV.

All inputs are validated before any bytes are written. An invalid token, a zero pid or time, an invalid command or directory, or a sequence beyond MAX_SEQUENCE_LEN bytes or MAX_ARGV elements returns io::ErrorKind::InvalidInput. When the command changes to one that this function rejects, send write_program_resume_clear so that the terminal does not resume the earlier command.

use uncurses::ansi::program_resume::{ProgramResume, write_program_resume};

let report = ProgramResume::new(&["resume-wrap", "ssh", "devbox"]);
let mut bytes = Vec::new();
write_program_resume(&mut bytes, &report, 90412, 1795543200, "dummy-token-replace-me")
    .unwrap();
assert_eq!(
    bytes,
    b"\x1b]7577;pid=90412:time=1795543200:argv=cmVzdW1lLXdyYXA=,c3No,ZGV2Ym94\
      :mac=e76149d0ba54a83570ffab0583867dacdfa23928ba9d18604f0badea88b62b65\x1b\\",
);