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"
},
"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": {

View file

@ -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 ]);
};
});
}

View file

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

View file

@ -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;

View file

@ -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

View file

@ -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<Self> {
use nix::sys::termios::*;
let saved_mode = tcgetattr(fd)?;

View file

@ -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")?;

View file

@ -1 +0,0 @@