From 9866e178d837e13b5aa568566ff167672ca13478 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 10 Feb 2023 22:18:09 -0600 Subject: [PATCH] somehow it works lmao --- flake.lock | 18 +++++++++--------- flake.nix | 13 ++++++++++--- rustfmt.toml | 1 + src/lib.rs | 2 +- src/main.rs | 1 - src/raw_term.rs | 1 + src/recorder.rs | 21 +++++++++------------ src/term.rs | 1 - 8 files changed, 31 insertions(+), 27 deletions(-) delete mode 100644 src/term.rs diff --git a/flake.lock b/flake.lock index a35d60c..40f42c5 100644 --- a/flake.lock +++ b/flake.lock @@ -6,11 +6,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1673072488, - "narHash": "sha256-oSlrgIlaZEcBrH9o6ujCtuzvULB7w5MrQl1Xccsl9Is=", + "lastModified": 1675491720, + "narHash": "sha256-GvCVyzK3QDB0zI5tT+Y2Ih17K7SyFdiOIC+89e4Rz18=", "owner": "nix-community", "repo": "fenix", - "rev": "2fa6ef94550e2e8b5e47fa3b0655edcacbb65cb6", + "rev": "0d5be3409a8558919aaff62370fee8e3b65425b9", "type": "github" }, "original": { @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1672953546, - "narHash": "sha256-oz757DnJ1ITvwyTovuwG3l9cX6j9j6/DH9eH+cXFJmc=", + "lastModified": 1675362331, + "narHash": "sha256-VmcnKPj5gJLxWK7Bxlhg2LoQvhKRss7Ax+uoFjd3qKY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a518c77148585023ff56022f09c4b2c418a51ef5", + "rev": "a100acd7bbf105915b0004427802286c37738fef", "type": "github" }, "original": { @@ -73,11 +73,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1673025936, - "narHash": "sha256-Dm2qLfxAEqrfz9CE6w1jlEZdfNLFeAkC/mcb4xwUQQE=", + "lastModified": 1675422954, + "narHash": "sha256-rvfDelP5ev3STKLofL6EfFAce1umPRnMvR6JbCL0b/s=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "f1a99014b356c6aa41a69ceecf1f8cc68d901006", + "rev": "3bc33c7e9f041c5aef69a5c33b3d29d19a341ece", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 0ee3612..059f5f0 100644 --- a/flake.nix +++ b/flake.nix @@ -20,9 +20,16 @@ devShell = pkgs.mkShell { inputsFrom = with packages; [ asciinema ]; - packages = (with pkgs; [ cargo-watch cargo-deny cargo-edit ]) - ++ (with toolchain; [ cargo rustc rustfmt ]); - CARGO_UNSTABLE_SPARSE_REGISTRY = "true"; + + packages = (with pkgs; [ + asciinema + cargo-watch + cargo-deny + cargo-edit + + # Get the nightly version of rustfmt so we can wrap comments + pkgs.fenix.default.rustfmt + ]) ++ (with toolchain; [ cargo rustc rustfmt ]); }; }); } diff --git a/rustfmt.toml b/rustfmt.toml index 4c1eefa..a3be6a8 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,3 @@ max_width = 80 tab_spaces = 2 +wrap_comments = true diff --git a/src/lib.rs b/src/lib.rs index 09fcfe6..1f1e247 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,8 @@ extern crate serde_derive; extern crate tracing; pub mod asciicast; -pub mod recorder; mod raw_term; +pub mod recorder; // pub mod recorder; // pub mod term; // pub mod writer; diff --git a/src/main.rs b/src/main.rs index 9e30572..750d48d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,6 @@ fn record() -> Result<()> { let mut file = File::create("output.cast")?; let mut command = Command::new("zsh"); - // command.arg("bash"); command.env("TERM", "xterm-256color"); // Write header diff --git a/src/raw_term.rs b/src/raw_term.rs index 9423dcf..f24a24a 100644 --- a/src/raw_term.rs +++ b/src/raw_term.rs @@ -7,6 +7,7 @@ use nix::sys::termios::Termios; pub struct RawTerm(RawFd, Termios); impl RawTerm { + /// Put the terminal into raw mode. pub fn init(fd: RawFd) -> Result { use nix::sys::termios::*; let saved_mode = tcgetattr(fd)?; diff --git a/src/recorder.rs b/src/recorder.rs index ff49b73..6974cf5 100644 --- a/src/recorder.rs +++ b/src/recorder.rs @@ -3,25 +3,22 @@ use std::env; use std::ffi::CString; use std::io::stdin; -use std::os::unix::prelude::{AsFd, AsRawFd, OsStrExt, RawFd}; -use std::process::{Command, Stdio}; +use std::os::unix::prelude::{AsRawFd, OsStrExt}; +use std::process::Command; use std::sync::mpsc::{self, Receiver, Sender}; use std::time::Instant; use anyhow::{Context, Result}; -use libc::{O_RDWR, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO}; +use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO}; use nix::fcntl::{open, OFlag}; -use nix::pty::{openpty, OpenptyResult}; -use nix::sys::termios::{ - ControlFlags, InputFlags, LocalFlags, OutputFlags, SetArg, -}; +use nix::pty::openpty; + use nix::sys::{ select::{select, FdSet}, stat::Mode, - termios, }; use nix::unistd::{ - close, dup, dup2, execvp, execvpe, fork, fsync, read, setsid, ttyname, write, + close, dup, dup2, execvpe, fork, fsync, read, setsid, ttyname, write, ForkResult, }; @@ -81,7 +78,7 @@ impl Terminal { eprintln!("Starting child process..."); // Spawn the child - let child_pid = match unsafe { fork() } { + let _child_pid = match unsafe { fork() } { Ok(ForkResult::Parent { child }) => { info!( child_pid = child.as_raw(), @@ -147,8 +144,8 @@ impl Terminal { // Master is ready for read, which means child process stdout has data // (child process stdout) -> (pty.slave) -> (pty.master) if read_fd_set.contains(pty.master) { - // TODO: This line trips if the child process dies from, say, Ctrl+D. Need to catch this - // somehow and gracefully react to it. + // TODO: This line trips if the child process dies from, say, Ctrl+D. + // Need to catch this somehow and gracefully react to it. // Possibly signals would be a good solution here? let bytes_read = read(pty.master, &mut buf).context("Read from master")?; diff --git a/src/term.rs b/src/term.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/term.rs +++ /dev/null @@ -1 +0,0 @@ -