Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ winapi = { version = "0.3", features = [
"consoleapi", "handleapi", "minwindef", "ntdef", "processenv", "synchapi",
"winbase", "wincon", "winerror", "winnt", "winuser" ] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"

[dev-dependencies]
rand = "0.7"
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//! [`term_write!`]: macro.term_write.html
//! [`term_writeln!`]: macro.term_writeln.html

#![allow(unused_imports)]
#![deny(missing_docs)]

#[macro_use] extern crate bitflags;
Expand Down Expand Up @@ -69,6 +70,10 @@ mod sys;
#[path = "windows/mod.rs"]
mod sys;

#[cfg(target_arch = "wasm32")]
#[path = "wasm32/mod.rs"]
mod sys;

#[cfg(unix)]
pub use crate::sys::ext as unix;

Expand Down
Empty file added src/wasm32/ext.rs
Empty file.
11 changes: 11 additions & 0 deletions src/wasm32/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub use self::screen::{
Screen, ScreenReadGuard, ScreenWriteGuard,
};
pub use self::terminal::{
PrepareState,
Terminal, TerminalReadGuard, TerminalWriteGuard,
};

pub mod ext;
mod screen;
mod terminal;
163 changes: 163 additions & 0 deletions src/wasm32/screen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
use std::io;
use std::sync::{LockResult, Mutex, MutexGuard, TryLockResult};
use std::time::Duration;

use crate::buffer::ScreenBuffer;
use crate::priv_util::{
map2_lock_result, map2_try_lock_result, map_lock_result, map_try_lock_result,
};
use crate::sys::{PrepareState, Terminal, TerminalReadGuard, TerminalWriteGuard};
use crate::terminal::{Color, Cursor, CursorMode, Event, PrepareConfig, Size, Style};

pub struct Screen {
term: Terminal,

state: Option<PrepareState>,
writer: Mutex<Writer>,
}

pub struct ScreenReadGuard<'a> {
screen: &'a Screen,
reader: TerminalReadGuard<'a>,
}

pub struct ScreenWriteGuard<'a> {
writer: TerminalWriteGuard<'a>,
data: MutexGuard<'a, Writer>,
}

struct Writer {
buffer: ScreenBuffer,
clear_screen: bool,
real_cursor: Cursor,
}

impl Screen {
pub fn new(term: Terminal, config: PrepareConfig) -> io::Result<Screen> {
todo!()
}

pub fn stdout(config: PrepareConfig) -> io::Result<Screen> {
Screen::new(Terminal::stdout()?, config)
}

pub fn stderr(config: PrepareConfig) -> io::Result<Screen> {
Screen::new(Terminal::stderr()?, config)
}

forward_screen_buffer_methods!{ |slf| slf.lock_write_data().buffer }

pub fn lock_read(&self) -> LockResult<ScreenReadGuard> {
todo!()
}

pub fn try_lock_read(&self) -> TryLockResult<ScreenReadGuard> {
todo!()
}

pub fn lock_write(&self) -> LockResult<ScreenWriteGuard> {
todo!()
}

pub fn try_lock_write(&self) -> TryLockResult<ScreenWriteGuard> {
todo!()
}

fn lock_reader(&self) -> ScreenReadGuard {
todo!()
}

fn lock_writer(&self) -> ScreenWriteGuard {
todo!()
}

fn lock_write_data(&self) -> MutexGuard<Writer> {
todo!()
}

pub fn name(&self) -> &str {
todo!()
}

pub fn set_cursor_mode(&self, mode: CursorMode) -> io::Result<()> {
todo!()
}

pub fn wait_event(&self, timeout: Option<Duration>) -> io::Result<bool> {
todo!()
}

pub fn read_event(&self, timeout: Option<Duration>) -> io::Result<Option<Event>> {
todo!()
}

pub fn read_raw(&self, buf: &mut [u8], timeout: Option<Duration>) -> io::Result<Option<Event>> {
todo!()
}

pub fn refresh(&self) -> io::Result<()> {
todo!()
}
}

impl Drop for Screen {
fn drop(&mut self) {
todo!()
}
}
impl<'a> ScreenReadGuard<'a> {
fn new(screen: &'a Screen, reader: TerminalReadGuard<'a>) -> ScreenReadGuard<'a> {
todo!()
}

pub fn wait_event(&mut self, timeout: Option<Duration>) -> io::Result<bool> {
todo!()
}

pub fn read_event(&mut self, timeout: Option<Duration>) -> io::Result<Option<Event>> {
todo!()
}

pub fn read_raw(&mut self, buf: &mut [u8], timeout: Option<Duration>) -> io::Result<Option<Event>> {
todo!()
}
}

impl<'a> ScreenWriteGuard<'a> {
fn new(writer: TerminalWriteGuard<'a>, data: MutexGuard<'a, Writer>)
-> ScreenWriteGuard<'a> {
todo!()
}

forward_screen_buffer_mut_methods!{ |slf| slf.data.buffer }

pub fn set_cursor_mode(&mut self, mode: CursorMode) -> io::Result<()> {
todo!()
}

pub fn refresh(&mut self) -> io::Result<()> {
todo!()
}

fn move_cursor(&mut self, pos: Cursor) -> io::Result<()> {
todo!()
}

fn apply_attrs(&mut self,
(fg, bg, style): (Option<Color>, Option<Color>, Style))
-> io::Result<()> {
todo!()
}
}

impl<'a> Drop for ScreenWriteGuard<'a> {
fn drop(&mut self) {
todo!()
}
}

impl Writer {
fn update_size(&mut self, new_size: Size) {
todo!()
}
}
Loading