mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
rust: cleanup
- remove deprecated functions ncplane_new & nctablet_ncplane - fix some comments - run rustfmt
This commit is contained in:
parent
8ab9bd4687
commit
1f77571174
@ -361,7 +361,6 @@ pub use bindgen::{
|
||||
ncplane_move_bottom,
|
||||
ncplane_move_top,
|
||||
ncplane_move_yx,
|
||||
ncplane_new,
|
||||
ncplane_notcurses,
|
||||
ncplane_notcurses_const,
|
||||
ncplane_off_styles,
|
||||
@ -588,7 +587,6 @@ pub(crate) use bindgen::{
|
||||
#[doc(inline)]
|
||||
pub use bindgen::{
|
||||
// functions
|
||||
nctablet_ncplane,
|
||||
nctablet_plane,
|
||||
nctablet_userptr,
|
||||
};
|
||||
|
@ -11,7 +11,7 @@
|
||||
//# notcurses_canutf8
|
||||
// notcurses_cursor_disable
|
||||
// notcurses_cursor_enable
|
||||
// notcurses_debug
|
||||
//# notcurses_debug
|
||||
// notcurses_drop_planes
|
||||
// notcurses_getc
|
||||
//# notcurses_init
|
||||
@ -65,7 +65,7 @@ use crate::{
|
||||
notcurses_stdplane_const,
|
||||
types::{
|
||||
NcAlign, NcInput, NcLogLevel, NcPlane, Notcurses, NotcursesOptions, NCALIGN_CENTER,
|
||||
NCALIGN_LEFT, NCOPTION_SUPPRESS_BANNERS, NCOPTION_NO_ALTERNATE_SCREEN,
|
||||
NCALIGN_LEFT, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
|
||||
},
|
||||
};
|
||||
|
||||
@ -157,8 +157,8 @@ impl Notcurses {
|
||||
|
||||
/// `Notcurses` simple constructor without an alternate screen
|
||||
pub unsafe fn without_altscreen_nor_banners<'a>() -> &'a mut Notcurses {
|
||||
let options = NotcursesOptions::with_flags(
|
||||
NCOPTION_NO_ALTERNATE_SCREEN | NCOPTION_SUPPRESS_BANNERS);
|
||||
let options =
|
||||
NotcursesOptions::with_flags(NCOPTION_NO_ALTERNATE_SCREEN | NCOPTION_SUPPRESS_BANNERS);
|
||||
&mut *notcurses_init(&options, null_mut())
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ mod test {
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
use crate::{notcurses_stop, Notcurses, NcFile};
|
||||
use crate::{notcurses_stop, NcFile, Notcurses};
|
||||
|
||||
/*
|
||||
#[test]
|
||||
@ -276,9 +276,10 @@ mod test {
|
||||
let mut string1 = String::new();
|
||||
let _result = file.read_to_string(&mut string1);
|
||||
|
||||
let string2 = " ************************** notcurses debug state *****************************";
|
||||
let string2 =
|
||||
" ************************** notcurses debug state *****************************";
|
||||
|
||||
assert_eq![&string1[0..string2.len()], &string2[..]];
|
||||
assert_eq![&string1[0..string2.len()], &string2[..]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,5 +359,4 @@ mod test {
|
||||
print!("[{}] ", res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -153,21 +153,21 @@ use core::{
|
||||
ffi::c_void,
|
||||
ptr::{null, null_mut},
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use libc::free;
|
||||
use std::ffi::CString;
|
||||
|
||||
use crate::{
|
||||
bindgen::__va_list_tag,
|
||||
cell_load, cell_release, cells_double_box, cells_rounded_box, channels_bchannel,
|
||||
channels_bg_alpha, channels_bg_default_p, channels_bg_rgb, channels_bg_rgb8, channels_fchannel,
|
||||
channels_fg_alpha, channels_fg_default_p, channels_fg_rgb, channels_fg_rgb8, ncplane_at_cursor,
|
||||
ncplane_at_yx, ncplane_box, ncplane_channels, ncplane_cursor_move_yx, ncplane_cursor_yx,
|
||||
ncplane_dim_yx, ncplane_gradient, ncplane_hline_interp, ncplane_putc_yx, ncplane_putegc_yx,
|
||||
ncplane_putnstr_yx, ncplane_putstr_yx, ncplane_resize, ncplane_vline_interp,
|
||||
ncplane_vprintf_yx, notcurses_align, ncplane_create,
|
||||
ncplane_at_yx, ncplane_box, ncplane_channels, ncplane_create, ncplane_cursor_move_yx,
|
||||
ncplane_cursor_yx, ncplane_dim_yx, ncplane_gradient, ncplane_hline_interp, ncplane_putc_yx,
|
||||
ncplane_putegc_yx, ncplane_putnstr_yx, ncplane_putstr_yx, ncplane_resize, ncplane_vline_interp,
|
||||
ncplane_vprintf_yx, notcurses_align,
|
||||
types::{
|
||||
AlphaBits, Cell, Channel, Channels, Color, EgcBackstop, IntResult, NcAlign, NcPlane,
|
||||
StyleMask, NcPlaneOptions, NcPlaneOptionHoriz, NcHoriz, NCPLANE_OPTION_HORALIGNED,
|
||||
AlphaBits, Cell, Channel, Channels, Color, EgcBackstop, IntResult, NcAlign, NcHoriz,
|
||||
NcPlane, NcPlaneOptionHoriz, NcPlaneOptions, StyleMask, NCPLANE_OPTION_HORALIGNED,
|
||||
},
|
||||
};
|
||||
|
||||
@ -181,39 +181,42 @@ impl NcPlaneOptions {
|
||||
|
||||
/// `NcPlaneOptions` simple constructor with horizontal alignment
|
||||
pub fn new_halign(y: i32, align: NcAlign, rows: u32, cols: u32) -> Self {
|
||||
Self::with_all_options(y, NcHoriz::align(align), rows, cols, NCPLANE_OPTION_HORALIGNED)
|
||||
Self::with_all_options(
|
||||
y,
|
||||
NcHoriz::align(align),
|
||||
rows,
|
||||
cols,
|
||||
NCPLANE_OPTION_HORALIGNED,
|
||||
)
|
||||
}
|
||||
|
||||
/// `NcplaneOptions` constructor
|
||||
pub fn with_all_options(y: i32, horiz: NcHoriz, rows: u32, cols: u32, flags: u64) -> Self {
|
||||
NcPlaneOptions {
|
||||
y,
|
||||
horiz: {
|
||||
match horiz {
|
||||
NcHoriz::x(data) => NcPlaneOptionHoriz {x: data},
|
||||
NcHoriz::align(data) => NcPlaneOptionHoriz {align: data},
|
||||
}
|
||||
|
||||
},
|
||||
rows: rows as i32,
|
||||
cols: cols as i32,
|
||||
userptr: null_mut(),
|
||||
name: null(),
|
||||
resizecb: None,
|
||||
flags,
|
||||
y,
|
||||
horiz: {
|
||||
match horiz {
|
||||
NcHoriz::x(data) => NcPlaneOptionHoriz { x: data },
|
||||
NcHoriz::align(data) => NcPlaneOptionHoriz { align: data },
|
||||
}
|
||||
},
|
||||
rows: rows as i32,
|
||||
cols: cols as i32,
|
||||
userptr: null_mut(),
|
||||
name: null(),
|
||||
resizecb: None,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NcPlane {
|
||||
|
||||
/// `NcPlane` constructor
|
||||
pub unsafe fn new<'a>(bound_to: &mut NcPlane, options: &NcPlaneOptions) -> &'a mut NcPlane {
|
||||
&mut *ncplane_create(bound_to, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Static Functions ------------------------------------------------------------
|
||||
|
||||
/// Return the column at which 'cols' columns ought start in order to be aligned
|
||||
|
@ -5,10 +5,7 @@
|
||||
|
||||
use core::ptr::{null_mut, NonNull};
|
||||
|
||||
use std::{
|
||||
// ffi::CString,
|
||||
io::{Error, ErrorKind, Read, Seek, SeekFrom},
|
||||
};
|
||||
use std::io::{Error, ErrorKind, Read, Seek, SeekFrom};
|
||||
|
||||
pub use libc::{
|
||||
c_long, c_void, fclose, feof, fread, fseek, ftell, FILE as LIBC_FILE, SEEK_CUR, SEEK_END,
|
||||
@ -56,7 +53,7 @@ fn get_error<T>() -> Result<T, Error> {
|
||||
Err(Error::last_os_error())
|
||||
}
|
||||
|
||||
/// A wrapper struct around libc::FILE for
|
||||
/// A wrapper struct around libc::FILE
|
||||
///
|
||||
/// The notcurses FILE type `NC_FILE` is imported through bindgen as a struct,
|
||||
/// while the equivalent Rust libc::FILE (`LIBC_FILE`) is an opaque enum.
|
||||
@ -236,17 +233,15 @@ impl Read for NcFile {
|
||||
}
|
||||
|
||||
let result = std::str::from_utf8(&buffer);
|
||||
|
||||
|
||||
if let Ok(strslice) = result {
|
||||
*strbuf = strslice.to_string();
|
||||
Ok(bytes_read)
|
||||
} else {
|
||||
get_error()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Reads exactly the number of bytes required to fill buf.
|
||||
///
|
||||
/// # Errors
|
||||
@ -328,12 +323,3 @@ impl Drop for NcFile {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /// A utility function that creates a "buffer" of len bytes.
|
||||
// // TODO: NcBuffer::new(size) .expand()?
|
||||
// pub fn buffer(len: usize) -> Vec<u8> {
|
||||
// vec![0u8; len]
|
||||
// }
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user