somehow it works lmao

This commit is contained in:
Michael Zhang 2023-02-10 22:18:09 -06:00
parent 250793b330
commit 9866e178d8
8 changed files with 31 additions and 27 deletions

View file

@ -6,11 +6,11 @@
"rust-analyzer-src": "rust-analyzer-src" "rust-analyzer-src": "rust-analyzer-src"
}, },
"locked": { "locked": {
"lastModified": 1673072488, "lastModified": 1675491720,
"narHash": "sha256-oSlrgIlaZEcBrH9o6ujCtuzvULB7w5MrQl1Xccsl9Is=", "narHash": "sha256-GvCVyzK3QDB0zI5tT+Y2Ih17K7SyFdiOIC+89e4Rz18=",
"owner": "nix-community", "owner": "nix-community",
"repo": "fenix", "repo": "fenix",
"rev": "2fa6ef94550e2e8b5e47fa3b0655edcacbb65cb6", "rev": "0d5be3409a8558919aaff62370fee8e3b65425b9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -35,11 +35,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1672953546, "lastModified": 1675362331,
"narHash": "sha256-oz757DnJ1ITvwyTovuwG3l9cX6j9j6/DH9eH+cXFJmc=", "narHash": "sha256-VmcnKPj5gJLxWK7Bxlhg2LoQvhKRss7Ax+uoFjd3qKY=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "a518c77148585023ff56022f09c4b2c418a51ef5", "rev": "a100acd7bbf105915b0004427802286c37738fef",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -73,11 +73,11 @@
"rust-analyzer-src": { "rust-analyzer-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1673025936, "lastModified": 1675422954,
"narHash": "sha256-Dm2qLfxAEqrfz9CE6w1jlEZdfNLFeAkC/mcb4xwUQQE=", "narHash": "sha256-rvfDelP5ev3STKLofL6EfFAce1umPRnMvR6JbCL0b/s=",
"owner": "rust-lang", "owner": "rust-lang",
"repo": "rust-analyzer", "repo": "rust-analyzer",
"rev": "f1a99014b356c6aa41a69ceecf1f8cc68d901006", "rev": "3bc33c7e9f041c5aef69a5c33b3d29d19a341ece",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -20,9 +20,16 @@
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
inputsFrom = with packages; [ asciinema ]; inputsFrom = with packages; [ asciinema ];
packages = (with pkgs; [ cargo-watch cargo-deny cargo-edit ])
++ (with toolchain; [ cargo rustc rustfmt ]); packages = (with pkgs; [
CARGO_UNSTABLE_SPARSE_REGISTRY = "true"; 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 ]);
}; };
}); });
} }

View file

@ -1,2 +1,3 @@
max_width = 80 max_width = 80
tab_spaces = 2 tab_spaces = 2
wrap_comments = true

View file

@ -6,8 +6,8 @@ extern crate serde_derive;
extern crate tracing; extern crate tracing;
pub mod asciicast; pub mod asciicast;
pub mod recorder;
mod raw_term; mod raw_term;
pub mod recorder;
// pub mod recorder; // pub mod recorder;
// pub mod term; // pub mod term;
// pub mod writer; // pub mod writer;

View file

@ -30,7 +30,6 @@ fn record() -> Result<()> {
let mut file = File::create("output.cast")?; let mut file = File::create("output.cast")?;
let mut command = Command::new("zsh"); let mut command = Command::new("zsh");
// command.arg("bash");
command.env("TERM", "xterm-256color"); command.env("TERM", "xterm-256color");
// Write header // Write header

View file

@ -7,6 +7,7 @@ use nix::sys::termios::Termios;
pub struct RawTerm(RawFd, Termios); pub struct RawTerm(RawFd, Termios);
impl RawTerm { impl RawTerm {
/// Put the terminal into raw mode.
pub fn init(fd: RawFd) -> Result<Self> { pub fn init(fd: RawFd) -> Result<Self> {
use nix::sys::termios::*; use nix::sys::termios::*;
let saved_mode = tcgetattr(fd)?; let saved_mode = tcgetattr(fd)?;

View file

@ -3,25 +3,22 @@
use std::env; use std::env;
use std::ffi::CString; use std::ffi::CString;
use std::io::stdin; use std::io::stdin;
use std::os::unix::prelude::{AsFd, AsRawFd, OsStrExt, RawFd}; use std::os::unix::prelude::{AsRawFd, OsStrExt};
use std::process::{Command, Stdio}; use std::process::Command;
use std::sync::mpsc::{self, Receiver, Sender}; use std::sync::mpsc::{self, Receiver, Sender};
use std::time::Instant; use std::time::Instant;
use anyhow::{Context, Result}; 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::fcntl::{open, OFlag};
use nix::pty::{openpty, OpenptyResult}; use nix::pty::openpty;
use nix::sys::termios::{
ControlFlags, InputFlags, LocalFlags, OutputFlags, SetArg,
};
use nix::sys::{ use nix::sys::{
select::{select, FdSet}, select::{select, FdSet},
stat::Mode, stat::Mode,
termios,
}; };
use nix::unistd::{ 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, ForkResult,
}; };
@ -81,7 +78,7 @@ impl Terminal {
eprintln!("Starting child process..."); eprintln!("Starting child process...");
// Spawn the child // Spawn the child
let child_pid = match unsafe { fork() } { let _child_pid = match unsafe { fork() } {
Ok(ForkResult::Parent { child }) => { Ok(ForkResult::Parent { child }) => {
info!( info!(
child_pid = child.as_raw(), child_pid = child.as_raw(),
@ -147,8 +144,8 @@ impl Terminal {
// Master is ready for read, which means child process stdout has data // Master is ready for read, which means child process stdout has data
// (child process stdout) -> (pty.slave) -> (pty.master) // (child process stdout) -> (pty.slave) -> (pty.master)
if read_fd_set.contains(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 // TODO: This line trips if the child process dies from, say, Ctrl+D.
// somehow and gracefully react to it. // Need to catch this somehow and gracefully react to it.
// Possibly signals would be a good solution here? // Possibly signals would be a good solution here?
let bytes_read = let bytes_read =
read(pty.master, &mut buf).context("Read from master")?; read(pty.master, &mut buf).context("Read from master")?;

View file

@ -1 +0,0 @@