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
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vt100"
version = "0.16.2"
version = "0.16.3"
authors = ["Jesse Luehrs <doy@tozt.net>"]
edition = "2021"
rust-version = "1.70"
Expand All @@ -15,9 +15,10 @@ license = "MIT"
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

[dependencies]
embedded-io = { version = "0.7.1", optional = true }
itoa = "1.0.15"
unicode-width = "0.2.1"
vte = "0.15.0"
vte = { version = "0.15.0", default-features = false }

[dev-dependencies]
nix = { version = "0.30.1", features = ["term"] }
Expand All @@ -26,3 +27,7 @@ rand = "0.9"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
terminal_size = "0.4.2"

[features]
default = ["std"]
std = ["vte/std"]
1 change: 1 addition & 0 deletions src/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::term::BufWrite as _;
use alloc::vec::Vec;

/// Represents a foreground or background color for cells.
#[derive(Eq, PartialEq, Debug, Copy, Clone, Default)]
Expand Down
4 changes: 2 additions & 2 deletions src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Cell {
len: u8,
attrs: crate::attrs::Attrs,
}
const _: () = assert!(std::mem::size_of::<Cell>() == 32);
const _: () = assert!(core::mem::size_of::<Cell>() == 32);

impl PartialEq<Self> for Cell {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Cell {
#[allow(clippy::missing_panics_doc)]
#[must_use]
pub fn contents(&self) -> &str {
std::str::from_utf8(&self.contents[..self.len()]).unwrap()
core::str::from_utf8(&self.contents[..self.len()]).unwrap()
}

/// Returns whether the cell contains any text data.
Expand Down
7 changes: 4 additions & 3 deletions src/grid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::term::BufWrite as _;
use alloc::{collections::VecDeque, string::String, vec::Vec};

#[derive(Clone, Debug)]
pub struct Grid {
Expand All @@ -10,7 +11,7 @@ pub struct Grid {
scroll_bottom: u16,
origin_mode: bool,
saved_origin_mode: bool,
scrollback: std::collections::VecDeque<crate::row::Row>,
scrollback: VecDeque<crate::row::Row>,
scrollback_len: usize,
scrollback_offset: usize,
}
Expand All @@ -26,7 +27,7 @@ impl Grid {
scroll_bottom: size.rows - 1,
origin_mode: false,
saved_origin_mode: false,
scrollback: std::collections::VecDeque::new(),
scrollback: VecDeque::new(),
scrollback_len,
scrollback_offset: 0,
}
Expand All @@ -35,7 +36,7 @@ impl Grid {
pub fn allocate_rows(&mut self) {
if self.rows.is_empty() {
self.rows.extend(
std::iter::repeat_with(|| {
core::iter::repeat_with(|| {
crate::row::Row::new(self.size.cols)
})
.take(usize::from(self.size.rows)),
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! );
//! ```

#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
#![warn(clippy::cargo)]
#![warn(clippy::pedantic)]
Expand All @@ -47,6 +48,9 @@
#![allow(clippy::too_many_lines)]
#![allow(clippy::type_complexity)]

#[macro_use]
extern crate alloc;

mod attrs;
mod callbacks;
mod cell;
Expand Down
28 changes: 28 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl Default for Parser {
}
}

#[cfg(feature = "std")]
impl std::io::Write for Parser {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.process(buf);
Expand All @@ -94,3 +95,30 @@ impl std::io::Write for Parser {
Ok(())
}
}

#[cfg(feature = "embedded-io")]
impl embedded_io::ErrorType for Parser {
type Error = core::convert::Infallible;
}

#[cfg(feature = "embedded-io")]
impl embedded_io::Write for Parser {
fn write(
&mut self,
buf: &[u8],
) -> core::result::Result<usize, Self::Error> {
self.process(buf);
Ok(buf.len())
}

fn flush(&mut self) -> core::result::Result<(), Self::Error> {
Ok(())
}
}

#[cfg(feature = "embedded-io")]
impl embedded_io::WriteReady for Parser {
fn write_ready(&mut self) -> core::result::Result<bool, Self::Error> {
Ok(true)
}
}
2 changes: 2 additions & 0 deletions src/perform.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

const BASE64: &[u8] =
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const CLIPBOARD_SELECTOR: &[u8] = b"cpqs01234567";
Expand Down
1 change: 1 addition & 0 deletions src/row.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::term::BufWrite as _;
use alloc::{string::String, vec::Vec};

#[derive(Clone, Debug)]
pub struct Row {
Expand Down
7 changes: 4 additions & 3 deletions src/screen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::term::BufWrite as _;
use alloc::{string::String, vec::Vec};
use unicode_width::UnicodeWidthChar as _;

const MODE_APPLICATION_KEYPAD: u8 = 0b0000_0001;
Expand Down Expand Up @@ -172,7 +173,7 @@ impl Screen {
end_col: u16,
) -> String {
match start_row.cmp(&end_row) {
std::cmp::Ordering::Less => {
core::cmp::Ordering::Less => {
let (_, cols) = self.size();
let mut contents = String::new();
for (i, row) in self
Expand Down Expand Up @@ -203,7 +204,7 @@ impl Screen {
}
contents
}
std::cmp::Ordering::Equal => {
core::cmp::Ordering::Equal => {
if start_col < end_col {
self.rows(start_col, end_col - start_col)
.nth(usize::from(start_row))
Expand All @@ -212,7 +213,7 @@ impl Screen {
String::new()
}
}
std::cmp::Ordering::Greater => String::new(),
core::cmp::Ordering::Greater => String::new(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/term.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// TODO: read all of this from terminfo

use alloc::vec::Vec;

pub trait BufWrite {
fn write_buf(&self, buf: &mut Vec<u8>);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/write.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#![cfg(any(feature = "std", feature = "embedded-io"))]

#[cfg(feature = "std")]
use std::io::Write as _;

// Caveat: if both embedded-io and std features are specified, we only test
// the std feature.
#[cfg(all(feature = "embedded-io", not(feature = "std")))]
use embedded_io::Write as _;

#[test]
fn write_text() {
let mut parser = vt100::Parser::default();
Expand Down