Skip to content

Commit

Permalink
Merge pull request #4538 from wasmerio/deps-termsize
Browse files Browse the repository at this point in the history
deps: Switch from unmaintained term_size to terminal_size
  • Loading branch information
syrusakbary authored Apr 15, 2024
2 parents 03a31f7 + f5c6056 commit d08f2d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion lib/wasix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ serde_json = { version = "^1" }
serde_yaml = { version = "^0.9" }
weezl = { version = "^0.1" }
hex = { version = "^0.4" }
term_size = { version = "0.3" }
linked_hash_set = { version = "0.1" }
http = "0.2.8"
heapless = "0.7.16"
Expand Down Expand Up @@ -121,6 +120,9 @@ termios = { version = "0.3" }
[target.'cfg(windows)'.dependencies]
winapi = "0.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
terminal_size = { version = "0.3.0" }

[dev-dependencies]
wasmer = { path = "../api", version = "=4.2.8", default-features = false, features = ["wat", "js-serializable-module"] }
tokio = { version = "1", features = [ "sync", "macros", "rt" ], default_features = false }
Expand Down
60 changes: 33 additions & 27 deletions lib/wasix/src/os/tty/tty_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,19 @@ impl TtyBridge for SysTty {
let stdin_tty = sys::is_stdin_tty();
let stdout_tty = sys::is_stdout_tty();
let stderr_tty = sys::is_stderr_tty();

if let Some((w, h)) = term_size::dimensions() {
WasiTtyState {
cols: w as u32,
rows: h as u32,
width: 800,
height: 600,
stdin_tty,
stdout_tty,
stderr_tty,
echo,
line_buffered,
line_feeds,
}
} else {
WasiTtyState {
rows: 80,
cols: 25,
width: 800,
height: 600,
stdin_tty,
stdout_tty,
stderr_tty,
echo,
line_buffered,
line_feeds,
}
let (cols, rows) = sys_terminal_size::get_terminal_size();

WasiTtyState {
cols,
rows,
width: 800,
height: 600,
stdin_tty,
stdout_tty,
stderr_tty,
echo,
line_buffered,
line_feeds,
}
}

Expand All @@ -66,6 +52,26 @@ impl TtyBridge for SysTty {
}
}

mod sys_terminal_size {
static DEFAULT_SIZE: (u32, u32) = (80, 25);

#[cfg(not(target_arch = "wasm32"))]
pub fn get_terminal_size() -> (u32, u32) {
if let Some((terminal_size::Width(width), terminal_size::Height(height))) =
terminal_size::terminal_size()
{
(width.into(), height.into())
} else {
DEFAULT_SIZE
}
}

#[cfg(target_arch = "wasm32")]
pub fn get_terminal_size() -> (u32, u32) {
DEFAULT_SIZE
}
}

#[allow(unused_mut)]
#[cfg(all(unix, not(target_os = "ios")))]
mod sys {
Expand Down

0 comments on commit d08f2d9

Please sign in to comment.