small software-rendered rust tty
fix colors
bendn 9 months ago
parent adf2745 · commit 4bf05b6
-rw-r--r--src/colors.rs21
-rw-r--r--src/main.rs24
-rw-r--r--src/render.rs4
-rw-r--r--src/term.rs1
4 files changed, 15 insertions, 35 deletions
diff --git a/src/colors.rs b/src/colors.rs
index effec8d..2e487a2 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -1,3 +1,4 @@
+use atools::prelude::*;
pub const BACKGROUND: [u8; 3] = [33u8, 39u8, 51u8];
pub const FOREGROUND: [u8; 3] = [217u8, 215u8, 206u8];
pub const CURSOR: [u8; 3] = [255u8, 204u8, 102u8];
@@ -25,23 +26,7 @@ pub fn four(x: u16) -> [u8; 3] {
FOUR[x.min(0xf) as usize]
}
-pub const EIGHT: [[u8; 3]; 256] = [
- [0, 0, 0],
- [128, 0, 0],
- [0, 128, 0],
- [128, 128, 0],
- [0, 0, 128],
- [128, 0, 128],
- [0, 128, 128],
- [192, 192, 192],
- [128, 128, 128],
- [255, 0, 0],
- [0, 255, 0],
- [255, 255, 0],
- [0, 0, 255],
- [255, 0, 255],
- [0, 255, 255],
- [255, 255, 255],
+pub const EIGHT: [[u8; 3]; 256] = FOUR.couple([
[0, 0, 0],
[0, 0, 95],
[0, 0, 135],
@@ -282,4 +267,4 @@ pub const EIGHT: [[u8; 3]; 256] = [
[218, 218, 218],
[228, 228, 228],
[238, 238, 238],
-];
+]);
diff --git a/src/main.rs b/src/main.rs
index 90c7374..1ac0044 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
#![feature(
+ const_trait_impl,
generic_assert,
deadline_api,
deref_patterns,
@@ -7,6 +8,7 @@
if_let_guard,
import_trait_associated_functions
)]
+#![allow(incomplete_features)]
use std::fs::File;
use std::io::Write;
use std::iter::successors;
@@ -14,12 +16,11 @@ use std::os::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd};
use std::process::{Command, exit};
use std::sync::mpsc;
use std::thread::sleep;
-use std::time::{Duration, Instant};
+use std::time::Duration;
pub mod colors;
use anyhow::Result;
-use ctlfun::TerminalInputParser;
use fimg::Image;
use minifb::{InputCallback, Key, WindowOptions};
use nix::pty::{ForkptyResult, forkpty};
@@ -36,8 +37,7 @@ fn spawn(shell: &str) -> Result<(OwnedFd, Pid)> {
let x = unsafe { forkpty(None, None)? };
match x {
ForkptyResult::Child => {
- let sh =
- Command::new(shell).env("TERM", "xterm").spawn()?.wait();
+ _ = Command::new(shell).env("TERM", "xterm").spawn()?.wait();
exit(0);
}
ForkptyResult::Parent { child, master } => {
@@ -74,10 +74,6 @@ impl InputCallback for KeyPress {
self.0.send((key, state)).unwrap();
}
}
-enum Event {
- Read(Vec<u8>),
- Write(Key),
-}
fn main() -> Result<()> {
let mut w = minifb::Window::new(
"pattypan",
@@ -185,14 +181,15 @@ fn main() -> Result<()> {
// println!("recv");
ttx.send(x).unwrap();
}
- sleep(Duration::from_millis(10))
+ sleep(Duration::from_millis(10));
}
});
std::thread::spawn(move || {
loop {
- match waitpid(pid, None).unwrap() {
- nix::sys::wait::WaitStatus::Exited(..) => exit(0),
- _ => (),
+ if let nix::sys::wait::WaitStatus::Exited(..) =
+ waitpid(pid, None).unwrap()
+ {
+ exit(0)
}
}
});
@@ -232,13 +229,12 @@ fn main() -> Result<()> {
let x = Image::<Box<[u32]>, 1>::from(i.as_ref());
w.update_with_buffer(x.buffer(), w.get_size().0, w.get_size().1)?;
}
-
- Ok(())
}
#[test]
fn tpaxrse() {
println!("-------------------");
+ use ctlfun::TerminalInputParser;
let mut x = TerminalInputParser::new();
for c in "\x1b[6n".as_bytes() {
use ctlfun::TerminalInput::*;
diff --git a/src/render.rs b/src/render.rs
index 1a70232..1ae2793 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -164,13 +164,13 @@ fn t() {
FontRef::from_index(&include_bytes!("../cjk.ttc")[..], 0).unwrap();
dbg!(f.attributes());
- let m = f.metrics(&[f.charmap().map('行') as _]);
+ // let m = f.metrics(&[f.charmap().map('行') as _]);
let ppem = 30.0;
let d = dims(&FONT, ppem);
let sz = d.0;
let mut grid = Image::<_, 4>::alloc(2000, 500);
- unsafe { grid.chunked_mut().for_each(|x| *x = [0, 0, 0, 255]) };
+ grid.chunked_mut().for_each(|x| *x = [0, 0, 0, 255]);
for (letter, i) in "素早い茶色のキツネは怠け者の犬を飛び越えた"
.chars()
.zip(0..)
diff --git a/src/term.rs b/src/term.rs
index 20ac897..a9bd2af 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -1,4 +1,3 @@
-use std::iter::repeat_n;
use std::ops::Not;
use std::os::fd::BorrowedFd;
mod cells;