mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
Use term_size instead of ioctl
This commit is contained in:
parent
f3d822c00c
commit
26e5f51192
@ -24,10 +24,7 @@ unicode-width = "0.1"
|
|||||||
xi-unicode = "0.1.0"
|
xi-unicode = "0.1.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
chan = "0.1"
|
chan = "0.1"
|
||||||
|
term_size = { version = "0.3.1", optional = true }
|
||||||
[dependencies.ioctl-rs]
|
|
||||||
optional = true
|
|
||||||
version = "0.2"
|
|
||||||
|
|
||||||
[dependencies.num]
|
[dependencies.num]
|
||||||
default-features = false
|
default-features = false
|
||||||
@ -71,8 +68,8 @@ pretty-bytes = "0.2.2"
|
|||||||
blt-backend = ["bear-lib-terminal"]
|
blt-backend = ["bear-lib-terminal"]
|
||||||
default = ["ncurses-backend"]
|
default = ["ncurses-backend"]
|
||||||
markdown = ["pulldown-cmark"]
|
markdown = ["pulldown-cmark"]
|
||||||
ncurses-backend = ["ncurses", "maplit", "ioctl-rs"]
|
ncurses-backend = ["ncurses", "maplit", "term_size"]
|
||||||
pancurses-backend = ["pancurses", "maplit", "ioctl-rs"]
|
pancurses-backend = ["pancurses", "maplit", "term_size"]
|
||||||
termion-backend = ["termion"]
|
termion-backend = ["termion"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -1,20 +1,32 @@
|
|||||||
//! Common module for the ncurses and pancurses backends.
|
//! Common module for the ncurses and pancurses backends.
|
||||||
//!
|
//!
|
||||||
//! Requires either of `ncurses-backend` or `pancurses-backend`.
|
//! Requires either of `ncurses-backend` or `pancurses-backend`.
|
||||||
#![cfg(any(feature = "ncurses", feature = "pancurses"))]
|
#![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))]
|
||||||
|
|
||||||
|
extern crate term_size;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use event::{Event, Key};
|
use event::{Event, Key};
|
||||||
use std::collections::HashMap;
|
|
||||||
use theme::{BaseColor, Color, ColorPair};
|
use theme::{BaseColor, Color, ColorPair};
|
||||||
|
|
||||||
mod sizes;
|
use vec::Vec2;
|
||||||
|
|
||||||
#[cfg(feature = "ncurses")]
|
#[cfg(feature = "ncurses-backend")]
|
||||||
pub mod n;
|
pub mod n;
|
||||||
|
|
||||||
#[cfg(feature = "pancurses")]
|
#[cfg(feature = "pancurses-backend")]
|
||||||
pub mod pan;
|
pub mod pan;
|
||||||
|
|
||||||
|
/// Get the size of the terminal.
|
||||||
|
///
|
||||||
|
/// Usually ncurses can do that by himself, but because we're playing with
|
||||||
|
/// threads, ncurses' signal handler is confused and he can't keep track of
|
||||||
|
/// the terminal size. Poor ncurses.
|
||||||
|
fn terminal_size() -> Vec2 {
|
||||||
|
term_size::dimensions().unwrap_or((0,0)).into()
|
||||||
|
}
|
||||||
|
|
||||||
fn split_i32(code: i32) -> Vec<u8> {
|
fn split_i32(code: i32) -> Vec<u8> {
|
||||||
(0..4).map(|i| ((code >> (8 * i)) & 0xFF) as u8).collect()
|
(0..4).map(|i| ((code >> (8 * i)) & 0xFF) as u8).collect()
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,8 @@ impl Backend {
|
|||||||
///
|
///
|
||||||
/// We need to have ncurses update its representation of the screen.
|
/// We need to have ncurses update its representation of the screen.
|
||||||
fn on_resize() {
|
fn on_resize() {
|
||||||
// Get size using ioctl
|
// Get size
|
||||||
let size = super::sizes::terminal_size();
|
let size = super::terminal_size();
|
||||||
|
|
||||||
// Send the size to ncurses
|
// Send the size to ncurses
|
||||||
ncurses::resize_term(size.y as i32, size.x as i32);
|
ncurses::resize_term(size.y as i32, size.x as i32);
|
||||||
|
@ -357,8 +357,8 @@ impl Backend {
|
|||||||
///
|
///
|
||||||
/// We need to have ncurses update its representation of the screen.
|
/// We need to have ncurses update its representation of the screen.
|
||||||
fn on_resize() {
|
fn on_resize() {
|
||||||
// Get size using ioctl
|
// Get size
|
||||||
let size = super::sizes::terminal_size();
|
let size = super::terminal_size();
|
||||||
|
|
||||||
// Send the size to ncurses
|
// Send the size to ncurses
|
||||||
pancurses::resize_term(size.y as i32, size.x as i32);
|
pancurses::resize_term(size.y as i32, size.x as i32);
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
extern crate ioctl_rs as ioctl;
|
|
||||||
|
|
||||||
use libc::{c_ushort, STDOUT_FILENO};
|
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
use vec::Vec2;
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
struct TermSize {
|
|
||||||
row: c_ushort,
|
|
||||||
col: c_ushort,
|
|
||||||
_x: c_ushort,
|
|
||||||
_y: c_ushort,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the size of the terminal.
|
|
||||||
pub fn terminal_size() -> Vec2 {
|
|
||||||
unsafe {
|
|
||||||
let mut size: TermSize = mem::zeroed();
|
|
||||||
ioctl::ioctl(STDOUT_FILENO, ioctl::TIOCGWINSZ, &mut size as *mut _);
|
|
||||||
Vec2::new(size.col as usize, size.row as usize)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user