diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ansi.rs | 99 | ||||
-rw-r--r-- | src/main.rs | 63 | ||||
-rw-r--r-- | src/renderer/mod.rs | 18 | ||||
-rw-r--r-- | src/term.rs | 24 | ||||
-rw-r--r-- | src/tty.rs | 21 | ||||
-rw-r--r-- | src/util.rs | 2 |
6 files changed, 71 insertions, 156 deletions
diff --git a/src/ansi.rs b/src/ansi.rs index c1829f19..5f4419b5 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -17,7 +17,7 @@ //! should be, feel free to add it. Please try not to become overzealous and adding support for //! sequences only used by folks trapped in 1988. -use std::io::{Cursor, Read, Write, Chars}; +use std::io::Write; use ::Rgb; /// A CSI Escape sequence @@ -32,38 +32,6 @@ pub trait TermInfo { fn cols(&self) -> usize; } -/// Control requiring action -#[derive(Debug, Eq, PartialEq)] -pub enum Control { - PutTab(u8), - Backspace(u8), - CarriageReturn, - Newline, - Bell, - SwitchG0, - SwitchG1, - Substitute, - LineFeed, - SetHorizontalTabStop, - ReverseIndex, - IdentifyTerminal, - ResetState, -} - -/// Something parsed from the pty stream -#[derive(Debug, Eq, PartialEq)] -pub enum Item { - /// CSI escape - Escape(Escape), - - /// Control character, - Control(Control), - - /// Plain character - Char(char), -} - - pub const CSI_ATTR_MAX: usize = 16; pub struct Parser { @@ -244,46 +212,46 @@ pub enum Attr { /// writing specific handler impls for tests far easier. pub trait Handler { /// A character to be displayed - fn input(&mut self, c: char) {} + fn input(&mut self, _c: char) {} /// Set cursor to position - fn goto(&mut self, x: i64, y: i64) {} + fn goto(&mut self, _x: i64, _y: i64) {} /// Set cursor to specific row - fn goto_row(&mut self, y: i64) {} + fn goto_row(&mut self, _y: i64) {} /// Set cursor to specific column - fn goto_col(&mut self, x: i64) {} + fn goto_col(&mut self, _x: i64) {} /// Insert blank characters - fn insert_blank(&mut self, num: i64) {} + fn insert_blank(&mut self, _num: i64) {} /// Move cursor up `rows` - fn move_up(&mut self, rows: i64) {} + fn move_up(&mut self, _rows: i64) {} /// Move cursor down `rows` - fn move_down(&mut self, rows: i64) {} + fn move_down(&mut self, _rows: i64) {} /// Identify the terminal (should write back to the pty stream) fn identify_terminal(&mut self) {} /// Move cursor forward `cols` - fn move_forward(&mut self, cols: i64) {} + fn move_forward(&mut self, _cols: i64) {} /// Move cursor backward `cols` - fn move_backward(&mut self, cols: i64) {} + fn move_backward(&mut self, _cols: i64) {} /// Move cursor down `rows` and set to column 1 - fn move_down_and_cr(&mut self, rows: i64) {} + fn move_down_and_cr(&mut self, _rows: i64) {} /// Move cursor up `rows` and set to column 1 - fn move_up_and_cr(&mut self, rows: i64) {} + fn move_up_and_cr(&mut self, _rows: i64) {} /// Put `count` tabs - fn put_tab(&mut self, count: i64) {} + fn put_tab(&mut self, _count: i64) {} /// Backspace `count` characters - fn backspace(&mut self, count: i64) {} + fn backspace(&mut self, _count: i64) {} /// Carriage return fn carriage_return(&mut self) {} @@ -306,32 +274,32 @@ pub trait Handler { fn set_horizontal_tabstop(&mut self) {} /// Scroll up `rows` rows - fn scroll_up(&mut self, rows: i64) {} + fn scroll_up(&mut self, _rows: i64) {} /// Scroll down `rows` rows - fn scroll_down(&mut self, rows: i64) {} + fn scroll_down(&mut self, _rows: i64) {} /// Insert `count` blank lines - fn insert_blank_lines(&mut self, count: i64) {} + fn insert_blank_lines(&mut self, _count: i64) {} /// Delete `count` lines - fn delete_lines(&mut self, count: i64) {} + fn delete_lines(&mut self, _count: i64) {} /// Erase `count` chars /// /// TODO figure out AND comment what it means to "erase" chars - fn erase_chars(&mut self, count: i64) {} + fn erase_chars(&mut self, _count: i64) {} /// Delete `count` chars /// /// TODO figure out AND comment what it means to "delete" chars - fn delete_chars(&mut self, count: i64) {} + fn delete_chars(&mut self, _count: i64) {} /// Move backward `count` tabs - fn move_backward_tabs(&mut self, count: i64) {} + fn move_backward_tabs(&mut self, _count: i64) {} /// Move forward `count` tabs - fn move_forward_tabs(&mut self, count: i64) {} + fn move_forward_tabs(&mut self, _count: i64) {} /// Save current cursor position fn save_cursor_position(&mut self) {} @@ -340,13 +308,13 @@ pub trait Handler { fn restore_cursor_position(&mut self) {} /// Clear current line - fn clear_line(&mut self, mode: LineClearMode) {} + fn clear_line(&mut self, _mode: LineClearMode) {} /// Clear screen - fn clear_screen(&mut self, mode: ClearMode) {} + fn clear_screen(&mut self, _mode: ClearMode) {} /// Clear tab stops - fn clear_tabs(&mut self, mode: TabulationClearMode) {} + fn clear_tabs(&mut self, _mode: TabulationClearMode) {} /// Reset terminal state fn reset_state(&mut self) {} @@ -358,16 +326,16 @@ pub trait Handler { fn reverse_index(&mut self) {} /// set a terminal attribute - fn terminal_attribute(&mut self, attr: Attr) {} + fn terminal_attribute(&mut self, _attr: Attr) {} /// Set mode - fn set_mode(&mut self, Mode) {} + fn set_mode(&mut self, _mode: Mode) {} /// Unset mode fn unset_mode(&mut self, Mode) {} /// DECSTBM - Set the terminal scrolling region - fn set_scrolling_region(&mut self, top: i64, bot: i64) {} + fn set_scrolling_region(&mut self, _top: i64, _bot: i64) {} } /// An implementation of handler that just prints everything it gets @@ -471,7 +439,7 @@ impl Parser { handler.input(c); } - fn other<H>(&mut self, handler: &mut H, c: char) + fn other<H>(&mut self, _handler: &mut H, c: char) where H: Handler + TermInfo { if c == 0x07 as char || c == 0x18 as char || c == 0x1a as char || @@ -537,7 +505,6 @@ impl Parser { fn csi_parse<H>(&mut self, handler: &mut H) where H: Handler + TermInfo { - let mut idx = 0; let mut args = [0i64; CSI_ATTR_MAX]; let mut args_idx = 0; @@ -951,8 +918,8 @@ fn is_control_c1(c: char) -> bool { } /// C0 set of 7-bit control characters (from ANSI X3.4-1977). -#[allow(dead_code)] -mod C0 { +#[allow(non_snake_case)] +pub mod C0 { /// Null filler, terminal should ignore this character pub const NUL: char = 0x00 as char; /// Start of Header @@ -1027,8 +994,8 @@ mod C0 { /// 0x80 (@), 0x81 (A), 0x82 (B), 0x83 (C) are reserved /// 0x98 (X), 0x99 (Y) are reserved /// 0x9a (Z) is resezved, but causes DEC terminals to respond with DA codes -#[allow(dead_code)] -mod C1 { +#[allow(non_snake_case)] +pub mod C1 { /// Reserved pub const PAD: char = 0x80 as char; /// Reserved diff --git a/src/main.rs b/src/main.rs index ed62dac0..f3808e0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,7 @@ extern crate freetype; extern crate libc; extern crate glutin; extern crate cgmath; -extern crate euclid; extern crate notify; -extern crate arrayvec; #[macro_use] extern crate bitflags; @@ -23,24 +21,20 @@ mod macros; mod list_fonts; mod text; mod renderer; -mod grid; +pub mod grid; mod meter; mod tty; -mod ansi; +pub mod ansi; mod term; mod util; -use std::collections::HashMap; -use std::fs::File; -use std::io::{BufReader, Read, BufRead, Write, BufWriter}; +use std::io::{Read, Write, BufWriter}; use std::sync::Arc; use std::sync::mpsc; -use std::os::unix::io::{FromRawFd, AsRawFd}; - use grid::Grid; use meter::Meter; -use renderer::{QuadRenderer, GlyphCache, LoadGlyph}; +use renderer::{QuadRenderer, GlyphCache}; use term::Term; use text::FontDesc; use tty::process_should_exit; @@ -116,7 +110,7 @@ mod gl { } #[derive(Debug)] -struct TermProps { +pub struct TermProps { width: f32, height: f32, cell_width: f32, @@ -159,12 +153,12 @@ fn main() { let tty = tty::new(num_rows as u8, num_cols as u8); tty.resize(num_rows as usize, num_cols as usize, width as usize, height as usize); - let mut reader = tty.reader(); - let mut writer = tty.writer(); + let reader = tty.reader(); + let writer = tty.writer(); println!("num_cols, num_rows = {}, {}", num_cols, num_rows); - let mut grid = Grid::new(num_rows as usize, num_cols as usize); + let grid = Grid::new(num_rows as usize, num_cols as usize); let props = TermProps { cell_width: cell_width as f32, @@ -206,41 +200,44 @@ fn main() { let window_ref = window.clone(); let input_thread = thread::spawn_named("Input Thread", move || { for event in window_ref.wait_events() { - tx.send(Event::Glutin(event)); + tx.send(Event::Glutin(event)).unwrap(); if process_should_exit() { break; } } - }); 'main_loop: loop { - // Block waiting for next event - match rx.recv() { - Ok(e) => { - let res = handle_event(e, &mut writer, &mut terminal, &mut pty_parser); - if res == ShouldExit::Yes { - break; - } - }, - Err(mpsc::RecvError) => break, - } + { + let mut writer = BufWriter::new(&writer); - // Handle Any events that have been queued - loop { - match rx.try_recv() { + // Block waiting for next event + match rx.recv() { Ok(e) => { let res = handle_event(e, &mut writer, &mut terminal, &mut pty_parser); - if res == ShouldExit::Yes { break; } }, - Err(mpsc::TryRecvError::Disconnected) => break 'main_loop, - Err(mpsc::TryRecvError::Empty) => break, + Err(mpsc::RecvError) => break, } - // TODO make sure this doesn't block renders + // Handle Any events that have been queued + loop { + match rx.try_recv() { + Ok(e) => { + let res = handle_event(e, &mut writer, &mut terminal, &mut pty_parser); + + if res == ShouldExit::Yes { + break; + } + }, + Err(mpsc::TryRecvError::Disconnected) => break 'main_loop, + Err(mpsc::TryRecvError::Empty) => break, + } + + // TODO make sure this doesn't block renders + } } unsafe { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 87dfe84e..a0051aaa 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -3,13 +3,12 @@ use std::ffi::CString; use std::fs::File; use std::io::{self, Read}; use std::mem::size_of; -use std::path::{PathBuf, Path}; +use std::path::{PathBuf}; use std::ptr; use std::sync::Arc; use std::sync::atomic::{Ordering, AtomicBool}; -use cgmath::{self, Matrix}; -use euclid::{Rect, Size2D, Point2D}; +use cgmath; use gl::types::*; use gl; use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op}; @@ -185,12 +184,6 @@ pub struct PackedVertex { } #[derive(Debug)] -struct ElementIndex { - col: u32, // x - row: u32, // y -} - -#[derive(Debug)] pub struct Batch { tex: GLuint, instances: Vec<InstanceData>, @@ -616,13 +609,6 @@ impl<'a> Drop for RenderApi<'a> { } } -fn get_rect(glyph: &Glyph, x: f32, y: f32) -> Rect<f32> { - Rect::new( - Point2D::new(x + glyph.left as f32, y - (glyph.height - glyph.top) as f32), - Size2D::new(glyph.width as f32, glyph.height as f32) - ) -} - impl ShaderProgram { pub fn activate(&self) { unsafe { diff --git a/src/term.rs b/src/term.rs index 9d92e282..4c5e1424 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,8 +1,7 @@ /// Exports the `Term` type which is a high-level API for the Grid -use std::sync::Arc; use std::ops::Range; -use ansi::{self, Attr, DebugHandler}; +use ansi::{self, Attr}; use grid::{self, Grid, CellFlags}; use tty; use ::Rgb; @@ -70,10 +69,6 @@ impl Cursor { } } -struct Mover<'a> { - cursor: &'a mut Cursor, -} - pub struct Term { /// The grid grid: Grid, @@ -85,7 +80,7 @@ pub struct Term { alt: bool, /// Reference to the underlying tty - tty: tty::Tty, + _tty: tty::Tty, /// The cursor cursor: Cursor, @@ -130,7 +125,7 @@ impl Term { alt_cursor: Cursor::default(), fg: DEFAULT_FG, bg: DEFAULT_BG, - tty: tty, + _tty: tty, tabs: tabs, attr: CellFlags::empty(), mode: TermMode::empty(), @@ -157,10 +152,6 @@ impl Term { } } - pub fn resize(&mut self) { - unimplemented!(); - } - #[inline] pub fn cursor_x(&self) -> u16 { self.cursor.x @@ -195,13 +186,6 @@ impl Term { cell.flags = self.attr; } - /// Advance to next line - fn newline_c(&mut self, count: u16) { - // TODO handle scroll - self.cursor.x = 0; - self.cursor.y += 1; - } - /// Convenience function for scrolling fn scroll(&mut self, count: isize) { println!("[TERM] scrolling {} lines", count); @@ -299,6 +283,7 @@ impl ansi::Handler for Term { #[inline] fn backspace(&mut self, count: i64) { println!("backspace"); + // TODO this is incorrect; count unused self.cursor.x -= 1; self.set_char(' '); } @@ -357,7 +342,6 @@ impl ansi::Handler for Term { println!("clear_line: {:?}", mode); match mode { ansi::LineClearMode::Right => { - let cols = self.grid.num_cols(); let row = &mut self.grid[self.cursor.y as usize]; let start = self.cursor.x as usize; for cell in row[start..].iter_mut() { @@ -7,7 +7,7 @@ use std::mem; use std::os::unix::io::FromRawFd; use std::ptr; -use libc::{self, winsize, c_int, c_char, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD}; +use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD}; /// Process ID of child process /// @@ -21,7 +21,7 @@ static mut PID: pid_t = 0; /// cheked via `process_should_exit`. static mut SHOULD_EXIT: bool = false; -extern "C" fn sigchld(a: c_int) { +extern "C" fn sigchld(_a: c_int) { let mut status: c_int = 0; unsafe { let p = libc::waitpid(PID, &mut status, WNOHANG); @@ -45,23 +45,6 @@ pub fn process_should_exit() -> bool { unsafe { SHOULD_EXIT } } -pub enum Error { - /// TODO - Unknown, -} - -impl Error { - /// Build an Error from the current value of errno. - fn from_errno() -> Error { - let err = errno(); - match err { - _ => Error::Unknown - } - } -} - -pub type Result<T> = ::std::result::Result<T, Error>; - /// Get the current value of errno fn errno() -> c_int { unsafe { diff --git a/src/util.rs b/src/util.rs index aa382560..217f0b49 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,3 @@ -use std::iter::Iterator; - /// Threading utilities pub mod thread { /// Like `thread::spawn`, but with a `name` argument |