ncurses-5.99.0/.gitignore010064400017500000144000000000371303406142000134760ustar0000000000000000target bin Cargo.lock .* *.swp ncurses-5.99.0/.travis.yml010064400017500000144000000003331333215756300136350ustar0000000000000000language: rust rust: - stable - beta - nightly matrix: allow_failures: - rust: nightly fast_finish: true script: - cargo build --verbose - cargo test --verbose - cargo test --verbose --features wide ncurses-5.99.0/Cargo.toml.orig010064400017500000144000000014221343463742600144170ustar0000000000000000[package] name = "ncurses" version = "5.99.0" authors = [ "contact@jeaye.com" ] description = "A very thin wrapper around the ncurses TUI library" documentation = "https://github.com/jeaye/ncurses-rs" homepage = "https://github.com/jeaye/ncurses-rs" repository = "https://github.com/jeaye/ncurses-rs" readme = "README.md" keywords = ["ncurses","TUI"] license = "MIT" build = "build.rs" [build-dependencies] cc = "1.0.18" pkg-config = "0.3" [dependencies] libc = "0.2" [features] default=[] wide = [] panel = [] menu = [] # Uses a 64-bit type for `chtype` (otherwise a 32-bit type is used). # This should be set automagically (when needed) by build.rs wide_chtype = [] # Uses legacy values for mouse-related constants. mouse_v1 = [] extended_colors = ["wide"] [lib] name = "ncurses" ncurses-5.99.0/Cargo.toml0000644000000022270000000000000106620ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "ncurses" version = "5.99.0" authors = ["contact@jeaye.com"] build = "build.rs" description = "A very thin wrapper around the ncurses TUI library" homepage = "https://github.com/jeaye/ncurses-rs" documentation = "https://github.com/jeaye/ncurses-rs" readme = "README.md" keywords = ["ncurses", "TUI"] license = "MIT" repository = "https://github.com/jeaye/ncurses-rs" [lib] name = "ncurses" [dependencies.libc] version = "0.2" [build-dependencies.cc] version = "1.0.18" [build-dependencies.pkg-config] version = "0.3" [features] default = [] extended_colors = ["wide"] menu = [] mouse_v1 = [] panel = [] wide = [] wide_chtype = [] ncurses-5.99.0/LICENSE010064400017500000144000000024121270033604400125200ustar0000000000000000Copyright (c) 2016 Jesse 'Jeaye' Wilkerson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization. ncurses-5.99.0/Makefile010064400017500000144000000014501251120676500131620ustar0000000000000000# Sources LIB_SRC = src/ncurses.rs LIB_DEPS = $(shell head -n1 target/.ncurses.deps 2> /dev/null) EXAMPLES_SRC = $(wildcard examples/*.rs) # Objects LIB = target/$(shell rustc --print file-names ${LIB_SRC}) EXAMPLES_BIN = $(EXAMPLES_SRC:examples/%.rs=bin/%) # CFG Directive Options CFG_OPT ?= -O SED_OPT=-i ifeq ($(shell uname),Darwin) SED_OPT=-i '' endif all: ${LIB} ${EXAMPLES_BIN} lib: ${LIB} link-ncursesw: CFG_OPT = --cfg ncursesw link-ncursesw: all ${LIB}: ${LIB_DEPS} @mkdir -p target rustc ${CFG_OPT} --out-dir target ${LIB_SRC} @rustc --emit dep-info target/.ncurses.deps ${LIB_SRC} @sed ${SED_OPT} 's/.*: //' target/.ncurses.deps ${EXAMPLES_BIN}: bin/%: examples/%.rs ${LIB} @mkdir -p bin rustc --out-dir bin -L target $< clean: rm -rf target bin .PHONY: all clean link-ncursesw ncurses-5.99.0/README.md010064400017500000144000000036361343463741600130170ustar0000000000000000ncurses-rs [![Build Status](https://travis-ci.org/jeaye/ncurses-rs.png)](https://travis-ci.org/jeaye/ncurses-rs) ========== This is a very thin wrapper around the ncurses TUI lib. ## Building The compiled library will go to the `target` directory. ``` cargo build ``` Note that you must to have the ncurses library installed and linkable for ncurses-rs to work. On Linux, this should be trivial. On OS X, consider installing ncurses using Homebrew. (Note that you have to force Homebrew to link the library to `/usr/local/lib`: `brew link --force ncurses` and set that path to `LIBRARY_PATH` environmental variable.) ## Examples Examples are built by `cargo build`. To run them, use `cargo run --example ex_`. Example numbers increase along with the complexity of the example. Current examples: **1.** [Hello World](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_1.rs) **2.** [Basic Input & Attributes](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_2.rs) **3.** [Simple Pager](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_3.rs) **4.** [Window Movement](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_4.rs) **5.** [Menu Library](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_5.rs) (requires rust nightly) **6.** [Pager & Syntax Highlighting](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_6.rs) **7.** [Basic Input & Attributes (Unicode)](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_7.rs) **8.** [Special ACS Characters](https://github.com/jeaye/ncurses-rs/blob/master/examples/ex_8.rs) ## Environment variables Some environment variables are read by `build.rs`: If set, `NCURSES_RS_RUSTC_LINK_LIB` will be used for `NCURSES_RS_RUSTC_LINK_LIB`. If set, `NCURSES_RS_RUSTC_FLAGS` will be used for `cargo:rustc-flags`. If set, `NCURSES_RS_CFLAGS` will be used for the compilation of the test program `chtype_size.c`. ncurses-5.99.0/build.rs010064400017500000144000000062041343463741600131770ustar0000000000000000extern crate cc; extern crate pkg_config; use pkg_config::Library; use std::env; use std::fs::File; use std::io::Write; use std::path::Path; use std::process::Command; fn find_library(names: &[&str]) -> Option { for name in names { if let Ok(lib) = pkg_config::probe_library(name) { return Some(lib); } } None } fn main() { println!("cargo:rerun-if-env-changed=PKG_CONFIG_PATH"); let wide = cfg!(all(feature = "wide", not(target_os = "macos"))); let ncurses_lib_names = if wide { &["ncursesw5", "ncursesw"] } else { &["ncurses5", "ncurses"] }; let ncurses_lib = find_library(ncurses_lib_names); if cfg!(feature = "menu") { if wide { find_library(&["menuw5", "menuw"]); } else { find_library(&["menu5", "menu"]); } } if cfg!(feature = "panel") { if wide { find_library(&["panelw5", "panelw"]); } else { find_library(&["panel5", "panel"]); } } match std::env::var("NCURSES_RS_RUSTC_LINK_LIB") { Ok(x) => println!("cargo:rustc-link-lib={}", x), _ => if ncurses_lib.is_none() { println!("cargo:rustc-link-lib={}", ncurses_lib_names.last().unwrap()) } } if let Ok(x) = std::env::var("NCURSES_RS_RUSTC_FLAGS") { println!("cargo:rustc-flags={}", x); } check_chtype_size(&ncurses_lib); } fn check_chtype_size(ncurses_lib: &Option) { let out_dir = env::var("OUT_DIR").expect("cannot get OUT_DIR"); let src = format!("{}", Path::new(&out_dir).join("chtype_size.c").display()); let bin = format!("{}", Path::new(&out_dir).join("chtype_size").display()); let mut fp = File::create(&src).expect(&format!("cannot create {}", src)); fp.write_all(b" #include #include #include #include int main(void) { if (sizeof(chtype)*CHAR_BIT == 64) { puts(\"cargo:rustc-cfg=feature=\\\"wide_chtype\\\"\"); } else { /* We only support 32-bit and 64-bit chtype. */ assert(sizeof(chtype)*CHAR_BIT == 32 && \"unsupported size for chtype\"); } if (NCURSES_MOUSE_VERSION == 1) { puts(\"cargo:rustc-cfg=feature=\\\"mouse_v1\\\"\"); } return 0; } ").expect(&format!("cannot write into {}", src)); let mut build = cc::Build::new(); if let Some(lib) = ncurses_lib { for path in lib.include_paths.iter() { build.include(path); } } let compiler = build.try_get_compiler().expect("Failed Build::try_get_compiler"); let mut command = compiler.to_command(); if let Ok(x) = std::env::var("NCURSES_RS_CFLAGS") { command.args(x.split(" ")); } command.arg("-o").arg(&bin).arg(&src); assert!(command.status().expect("compilation failed").success()); let features = Command::new(&bin).output() .expect(&format!("{} failed", bin)); print!("{}", String::from_utf8_lossy(&features.stdout)); std::fs::remove_file(&src).expect(&format!("cannot delete {}", src)); std::fs::remove_file(&bin).expect(&format!("cannot delete {}", bin)); } ncurses-5.99.0/examples/ex_1.rs010064400017500000144000000014521330701501000145250ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_1.rs Author: Jesse 'Jeaye' Wilkerson Description: Simple "Hello, world" example. */ extern crate ncurses; use ncurses::*; fn main() { /* If your locale env is unicode, you should use `setlocale`. */ // let locale_conf = LcCategory::all; // setlocale(locale_conf, "zh_CN.UTF-8"); // if your locale is like mine(zh_CN.UTF-8). /* Start ncurses. */ initscr(); /* Print to the back buffer. */ printw("Hello, world!"); /* Print some unicode(Chinese) string. */ // printw("Great Firewall dislike VPN protocol.\nGFW 不喜欢 VPN 协议。"); /* Update the screen. */ refresh(); /* Wait for a key press. */ getch(); /* Terminate ncurses. */ endwin(); } ncurses-5.99.0/examples/ex_2.rs010064400017500000144000000021151277656001100145420ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_2.rs Author: Jesse 'Jeaye' Wilkerson Description: Basic input and attribute example. */ extern crate ncurses; use std::char; use ncurses::*; fn main() { /* Setup ncurses. */ initscr(); raw(); /* Allow for extended keyboard (like F1). */ keypad(stdscr(), true); noecho(); /* Prompt for a character. */ printw("Enter a character: "); /* Wait for input. */ let ch = getch(); if ch == KEY_F1 { /* Enable attributes and output message. */ attron(A_BOLD() | A_BLINK()); printw("\nF1"); attroff(A_BOLD() | A_BLINK()); printw(" pressed"); } else { /* Enable attributes and output message. */ printw("\nKey pressed: "); attron(A_BOLD() | A_BLINK()); printw(format!("{}\n", char::from_u32(ch as u32).expect("Invalid char")).as_ref()); attroff(A_BOLD() | A_BLINK()); } /* Refresh, showing the previous message. */ refresh(); /* Wait for one more character before exiting. */ getch(); endwin(); } ncurses-5.99.0/examples/ex_3.rs010064400017500000144000000031161312722617100145420ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_3.rs Author: Jesse 'Jeaye' Wilkerson Description: Implementation of a very simple pager. Usage: ./bin/ex_3 Example: ./bin/ex_3 examples/ex_3.rs */ extern crate ncurses; use std::env; use std::io::Read; use std::fs; use std::path::Path; use ncurses::*; fn open_file() -> fs::File { let args : Vec<_> = env::args().collect(); if args.len() != 2 { println!("Usage:\n\t{} ", args[0]); println!("Example:\n\t{} examples/ex_3.rs", args[0]); panic!("Exiting"); } let reader = fs::File::open(Path::new(&args[1])); reader.ok().expect("Unable to open file") } fn prompt() { printw("<-Press Any Key->"); getch(); } fn main() { let reader = open_file().bytes(); /* Start ncurses. */ initscr(); keypad(stdscr(), true); noecho(); /* Get the screen bounds. */ let mut max_x = 0; let mut max_y = 0; getmaxyx(stdscr(), &mut max_y, &mut max_x); /* Read the whole file. */ for ch in reader { if ch.is_err() { break; } let ch = ch.unwrap(); /* Get the current position on the screen. */ let mut cur_x = 0; let mut cur_y = 0; getyx(stdscr(), &mut cur_y, &mut cur_x); if cur_y == (max_y - 1) { /* Status bar at the bottom. */ prompt(); /* Once a key is pressed, clear the screen and continue. */ clear(); mv(0, 0); } addch(ch as chtype); } /* Terminate ncurses. */ mv(max_y -1, 0); prompt(); endwin(); } ncurses-5.99.0/examples/ex_4.rs010064400017500000144000000037031277656001100145500ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_4.rs Author: Jesse 'Jeaye' Wilkerson Description: Window creation and input example. Use the cursor keys to move the window around the screen. */ extern crate ncurses; use ncurses::*; static WINDOW_HEIGHT: i32 = 3; static WINDOW_WIDTH: i32 = 10; fn main() { /* Setup ncurses. */ initscr(); raw(); /* Allow for extended keyboard (like F1). */ keypad(stdscr(), true); noecho(); /* Invisible cursor. */ curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE); /* Status/help info. */ printw("Use the arrow keys to move"); mvprintw(LINES() - 1, 0, "Press F1 to exit"); refresh(); /* Get the screen bounds. */ let mut max_x = 0; let mut max_y = 0; getmaxyx(stdscr(), &mut max_y, &mut max_x); /* Start in the center. */ let mut start_y = (max_y - WINDOW_HEIGHT) / 2; let mut start_x = (max_x - WINDOW_WIDTH) / 2; let mut win = create_win(start_y, start_x); let mut ch = getch(); while ch != KEY_F(1) { match ch { KEY_LEFT => { start_x -= 1; destroy_win(win); win = create_win(start_y, start_x); }, KEY_RIGHT => { start_x += 1; destroy_win(win); win = create_win(start_y, start_x); }, KEY_UP => { start_y -= 1; destroy_win(win); win = create_win(start_y, start_x); }, KEY_DOWN => { start_y += 1; destroy_win(win); win = create_win(start_y, start_x); }, _ => { } } ch = getch(); } endwin(); } fn create_win(start_y: i32, start_x: i32) -> WINDOW { let win = newwin(WINDOW_HEIGHT, WINDOW_WIDTH, start_y, start_x); box_(win, 0, 0); wrefresh(win); win } fn destroy_win(win: WINDOW) { let ch = ' ' as chtype; wborder(win, ch, ch, ch, ch, ch, ch, ch, ch); wrefresh(win); delwin(win); } ncurses-5.99.0/examples/ex_5.rs010064400017500000144000000036621303406142000145410ustar0000000000000000#[allow(unused_imports)] extern crate ncurses; use ncurses::*; #[cfg(feature="menu")] fn main() { /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE); keypad(stdscr(), true); init_pair(1, COLOR_RED, COLOR_BLACK); /* Create items */ let mut items: Vec = Vec::new(); items.push(new_item("Choice 1", "Choice 1 description")); items.push(new_item("Choice 2", "Choice 2 description")); items.push(new_item("Choice 3", "Choice 3 description")); items.push(new_item("Choice 4", "Choice 4 description")); items.push(new_item("Exit", "Exit description")); /* Crate menu */ let my_menu = new_menu(&mut items); menu_opts_off(my_menu, O_SHOWDESC); let my_menu_win = newwin(9, 18, 4, 4); keypad(my_menu_win, true); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 5, 0, 2, 2)); /* Set menu mark to the string " * " */ set_menu_mark(my_menu, " * "); /* Print a border around the main window */ box_(my_menu_win, 0, 0); mvprintw(LINES() - 3, 0, "Press to see the option selected"); mvprintw(LINES() - 2, 0, "F1 to exit"); refresh(); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); let mut ch = getch(); while ch != KEY_F(1) { match ch { KEY_UP => { menu_driver(my_menu, REQ_UP_ITEM); }, KEY_DOWN => { menu_driver(my_menu, REQ_DOWN_ITEM); }, 10 => {/* Enter */ mv(20, 0); clrtoeol(); mvprintw(20, 0, &format!("Item selected is : {}", item_name(current_item(my_menu)))[..]); pos_menu_cursor(my_menu); }, _ => {} } wrefresh(my_menu_win); ch = getch(); } unpost_menu(my_menu); /* free items */ for &item in items.iter() { free_item(item); } free_menu(my_menu); endwin(); } #[cfg(not(feature="menu"))] fn main() { } ncurses-5.99.0/examples/ex_6.rs010064400017500000144000000234211277656001100145510ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_6.rs Author: Jesse 'Jeaye' Wilkerson Description: Extension of ex_3 that adds naive syntax highlighting to showcase attributes. Usage: ./bin/ex_6 Example: ./bin/ex_6 examples/ex_6.rs */ extern crate ncurses; use std::{ char, env, fs }; use std::path::Path; use std::io::{Read, Bytes}; use std::iter::Peekable; use ncurses::*; /* Individual color handles. */ static COLOR_BACKGROUND: i16 = 16; static COLOR_FOREGROUND: i16 = 17; static COLOR_KEYWORD: i16 = 18; static COLOR_TYPE: i16 = 19; static COLOR_STORAGE: i16 = 20; static COLOR_COMMENT: i16 = 21; static COLOR_STRING: i16 = 22; static COLOR_CHAR: i16 = 23; static COLOR_NUMBER: i16 = 24; /* Color pairs; foreground && background. */ static COLOR_PAIR_DEFAULT: i16 = 1; static COLOR_PAIR_KEYWORD: i16 = 2; static COLOR_PAIR_TYPE: i16 = 3; static COLOR_PAIR_STORAGE: i16 = 4; static COLOR_PAIR_COMMENT: i16 = 5; static COLOR_PAIR_STRING: i16 = 6; static COLOR_PAIR_CHAR: i16 = 7; static COLOR_PAIR_NUMBER: i16 = 8; /* Word delimiters. */ static WORD_LIMITS: &'static [u8] = & [ ' ' as u8, '(' as u8, ')' as u8, ':' as u8, ';' as u8, '&' as u8, '+' as u8, '-' as u8, ',' as u8, '.' as u8, '@' as u8, '~' as u8, '\\' as u8, '\n' as u8, '\r' as u8, '\0' as u8, !0 as u8, ]; struct Pager { file_reader: Peekable>, in_comment: bool, in_string: bool, in_char: bool, screen_width: i32, screen_height: i32, curr_x: i32, curr_y: i32, } impl Pager { pub fn new() -> Pager { Pager { file_reader: open_file().bytes().peekable(), in_comment: false, in_string: false, in_char: false, screen_width: 0, screen_height: 0, curr_x: 0, curr_y: 0, } } pub fn initialize(&mut self) { /* Start ncurses. */ initscr(); keypad(stdscr(), true); noecho(); /* Start colors. */ start_color(); init_color(COLOR_BACKGROUND, 0, 43 * 4, 54 * 4); init_color(COLOR_FOREGROUND, 142 * 4, 161 * 4, 161 * 4); init_color(COLOR_KEYWORD, 130 * 4, 151 * 4, 0); init_color(COLOR_TYPE, 197 * 4, 73 * 4, 27 * 4); init_color(COLOR_STORAGE, 219 * 4, 51 * 4, 47 * 4); init_color(COLOR_COMMENT, 33 * 4, 138 * 4, 206 * 4); init_color(COLOR_STRING, 34 * 4, 154 * 4, 142 * 4); init_color(COLOR_CHAR, 34 * 4, 154 * 4, 142 * 4); init_color(COLOR_NUMBER, 236 * 4, 107 * 4, 83 * 4); init_pair(COLOR_PAIR_DEFAULT, COLOR_FOREGROUND, COLOR_BACKGROUND); init_pair(COLOR_PAIR_KEYWORD, COLOR_KEYWORD, COLOR_BACKGROUND); init_pair(COLOR_PAIR_TYPE, COLOR_TYPE, COLOR_BACKGROUND); init_pair(COLOR_PAIR_STORAGE, COLOR_STORAGE, COLOR_BACKGROUND); init_pair(COLOR_PAIR_COMMENT, COLOR_COMMENT, COLOR_BACKGROUND); init_pair(COLOR_PAIR_STRING, COLOR_STRING, COLOR_BACKGROUND); init_pair(COLOR_PAIR_CHAR, COLOR_CHAR, COLOR_BACKGROUND); init_pair(COLOR_PAIR_NUMBER, COLOR_NUMBER, COLOR_BACKGROUND); /* Set the window's background color. */ bkgd(' ' as chtype | COLOR_PAIR(COLOR_PAIR_DEFAULT) as chtype); /* Get the screen bounds. */ getmaxyx(stdscr(), &mut self.screen_height, &mut self.screen_width); } /* Returns the word and delimiter following it. */ pub fn read_word(&mut self) -> (String, char) { let mut s: Vec = vec![]; let mut ch : u8 = self.file_reader.next().unwrap().ok().expect("Unable to read byte"); /* Read until we hit a word delimiter. */ while !WORD_LIMITS.contains(&ch) { s.push(ch); ch = self.file_reader.next().unwrap().ok().expect("Unable to read byte"); } /* Return the word string and the terminating delimiter. */ match char::from_u32(ch as u32) { Some(ch) => (String::from_utf8(s).ok().expect("utf-8 conversion failed"), ch), None => (String::from_utf8(s).ok().expect("utf-8 conversion failed"), ' '), } } /* Retuns the attribute the given word requires. */ pub fn highlight_word(&mut self, word: &str) -> attr_t { /* Comments. */ if self.in_comment && !word.contains("*/") { return COLOR_PAIR(COLOR_PAIR_COMMENT); } else if self.in_comment && word.contains("*/") { self.in_comment = false; return COLOR_PAIR(COLOR_PAIR_COMMENT); } else if !self.in_comment && word.contains("/*") { self.in_comment = true; return COLOR_PAIR(COLOR_PAIR_COMMENT); } /* Strings. */ if !self.in_char { if self.in_string && !word.contains("\"") { return COLOR_PAIR(COLOR_PAIR_STRING); } else if self.in_string && word.contains("\"") { self.in_string = false; return COLOR_PAIR(COLOR_PAIR_STRING); } else if !self.in_string && word.contains("\"") { /* If the same quote is found from either direction * then it's the only quote in the string. */ if word.find('\"') == word.rfind('\"') { self.in_string = true; } return COLOR_PAIR(COLOR_PAIR_STRING); } } /* Chars. */ if self.in_char && !word.contains("\'") { return COLOR_PAIR(COLOR_PAIR_CHAR); } else if self.in_char && word.contains("\'") { self.in_char = false; return COLOR_PAIR(COLOR_PAIR_CHAR); } else if !self.in_char && word.contains("\'") && !word.contains("static") { /* If the same quote is found from either direction * then it's the only quote in the string. */ if word.find('\'') == word.rfind('\'') { self.in_char = true; } return COLOR_PAIR(COLOR_PAIR_CHAR); } /* Trim the word of all delimiters. */ let word = word.trim_matches(|ch: char| { WORD_LIMITS.contains(&(ch as u8)) }); if word.len() == 0 { return 0; } /* If it starts with a number, it is a number. */ if word.as_bytes()[0] >= '0' as u8 && word.as_bytes()[0] <= '9' as u8 { return COLOR_PAIR(COLOR_PAIR_NUMBER); } match word { /* Key words. */ "break" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "continue" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "do" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "else" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "extern" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "in" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "if" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "impl" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "let" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "log" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "loop" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "match" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "once" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "priv" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "pub" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "return" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "unsafe" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "while" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "use" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "mod" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "trait" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "struct" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "enum" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "type" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, "fn" => { COLOR_PAIR(COLOR_PAIR_KEYWORD) }, /* Types. */ "int" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "uint" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "char" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "bool" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "u8" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "u16" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "u32" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "u64" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "i16" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "i32" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "i64" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "f32" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "f64" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "str" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "self" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, "Self" => { COLOR_PAIR(COLOR_PAIR_TYPE) }, /* Storage. */ "const" => { COLOR_PAIR(COLOR_PAIR_STORAGE) }, "mut" => { COLOR_PAIR(COLOR_PAIR_STORAGE) }, "ref" => { COLOR_PAIR(COLOR_PAIR_STORAGE) }, "static" => { COLOR_PAIR(COLOR_PAIR_STORAGE) }, /* Not something we need to highlight. */ _ => 0, } } } impl Drop for Pager { fn drop(&mut self) { /* Final prompt before closing. */ mv(self.screen_height - 1, 0); prompt(); endwin(); } } fn main() { let mut pager = Pager::new(); pager.initialize(); /* Read the whole file. */ while pager.file_reader.peek().is_some() { /* Read a word at a time. */ let (word, leftover) = pager.read_word(); let attr = pager.highlight_word(word.as_ref()); let leftover_attr = pager.highlight_word(format!("{}", leftover).as_ref()); /* Get the current position on the screen. */ getyx(stdscr(), &mut pager.curr_y, &mut pager.curr_x); if pager.curr_y == (pager.screen_height - 1) { /* Status bar at the bottom. */ prompt(); /* Once a key is pressed, clear the screen and continue. */ clear(); mv(0, 0); } else { attron(attr); printw(word.as_ref()); attroff(attr); attron(leftover_attr); addch(leftover as chtype); attroff(leftover_attr); } } } fn prompt() { attron(A_BOLD()); printw("<-Press Space->"); while getch() != ' ' as i32 { } attroff(A_BOLD()); } fn open_file() -> fs::File { let args : Vec<_> = env::args().collect(); if args.len() != 2 { println!("Usage:\n\t{} ", args[0]); println!("Example:\n\t{} examples/ex_5.rs", args[0]); panic!("Exiting"); } let reader = fs::File::open(Path::new(&args[1])); reader.ok().expect("Unable to open file") } ncurses-5.99.0/examples/ex_7.rs010064400017500000144000000036741333215756300145650ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: examples/ex_7.rs Author: Jesse 'Jeaye' Wilkerson Description: Basic input and attribute example, using the Unicode-aware get_wch functions. */ extern crate ncurses; use std::char; use ncurses::*; #[cfg(feature = "wide")] fn main() { let locale_conf = LcCategory::all; setlocale(locale_conf, "en_US.UTF-8"); /* Setup ncurses. */ initscr(); raw(); /* Require input within 2 seconds. */ halfdelay(20); /* Enable mouse events. */ mousemask(ALL_MOUSE_EVENTS as mmask_t, None); /* Allow for extended keyboard (like F1). */ keypad(stdscr(), true); noecho(); /* Prompt for a character. */ printw("Enter a character within 2 seconds: "); /* Wait for input. */ let ch = wget_wch(stdscr()); match ch { Some(WchResult::KeyCode(KEY_MOUSE)) => { /* Enable attributes and output message. */ attron(A_BOLD() | A_BLINK()); printw("\nMouse"); attroff(A_BOLD() | A_BLINK()); printw(" pressed"); } Some(WchResult::KeyCode(_)) => { /* Enable attributes and output message. */ attron(A_BOLD() | A_BLINK()); printw("\nKeycode"); attroff(A_BOLD() | A_BLINK()); printw(" pressed"); } Some(WchResult::Char(c)) => { /* Enable attributes and output message. */ printw("\nKey pressed: "); attron(A_BOLD() | A_BLINK()); printw(format!("{}\n", char::from_u32(c as u32).expect("Invalid char")).as_ref()); attroff(A_BOLD() | A_BLINK()); } None => { printw("\nYou didn't enter a character in time!"); } } /* Refresh, showing the previous message. */ refresh(); /* Wait for one more character before exiting. Disable the input timeout. */ nocbreak(); getch(); endwin(); } #[cfg(not(feature = "wide"))] fn main() { initscr(); printw("This example requires wide character support."); getch(); endwin(); } ncurses-5.99.0/examples/ex_8.rs010064400017500000144000000063311300725604200145460ustar0000000000000000// Derived from the ncurses Programming Howto, used under the // following license: // Copyright © 2001 by Pradeep Padala. // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without // restriction, including without limitation the rights to use, copy, // modify, merge, publish, distribute, distribute with modifications, // sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. extern crate ncurses; use ncurses::*; fn main() { initscr(); printw("Upper left corner "); addch(ACS_ULCORNER()); printw("\n"); printw("Lower left corner "); addch(ACS_LLCORNER()); printw("\n"); printw("Lower right corner "); addch(ACS_LRCORNER()); printw("\n"); printw("Tee pointing right "); addch(ACS_LTEE()); printw("\n"); printw("Tee pointing left "); addch(ACS_RTEE()); printw("\n"); printw("Tee pointing up "); addch(ACS_BTEE()); printw("\n"); printw("Tee pointing down "); addch(ACS_TTEE()); printw("\n"); printw("Horizontal line "); addch(ACS_HLINE()); printw("\n"); printw("Vertical line "); addch(ACS_VLINE()); printw("\n"); printw("Large Plus or cross over "); addch(ACS_PLUS()); printw("\n"); printw("Scan Line 1 "); addch(ACS_S1()); printw("\n"); printw("Scan Line 3 "); addch(ACS_S3()); printw("\n"); printw("Scan Line 7 "); addch(ACS_S7()); printw("\n"); printw("Scan Line 9 "); addch(ACS_S9()); printw("\n"); printw("Diamond "); addch(ACS_DIAMOND()); printw("\n"); printw("Checker board (stipple) "); addch(ACS_CKBOARD()); printw("\n"); printw("Degree Symbol "); addch(ACS_DEGREE()); printw("\n"); printw("Plus/Minus Symbol "); addch(ACS_PLMINUS()); printw("\n"); printw("Bullet "); addch(ACS_BULLET()); printw("\n"); printw("Arrow Pointing Left "); addch(ACS_LARROW()); printw("\n"); printw("Arrow Pointing Right "); addch(ACS_RARROW()); printw("\n"); printw("Arrow Pointing Down "); addch(ACS_DARROW()); printw("\n"); printw("Arrow Pointing Up "); addch(ACS_UARROW()); printw("\n"); printw("Board of squares "); addch(ACS_BOARD()); printw("\n"); printw("Lantern Symbol "); addch(ACS_LANTERN()); printw("\n"); printw("Solid Square Block "); addch(ACS_BLOCK()); printw("\n"); printw("Less/Equal sign "); addch(ACS_LEQUAL()); printw("\n"); printw("Greater/Equal sign "); addch(ACS_GEQUAL()); printw("\n"); printw("Pi "); addch(ACS_PI()); printw("\n"); printw("Not equal "); addch(ACS_NEQUAL()); printw("\n"); printw("UK pound sign "); addch(ACS_STERLING()); printw("\n"); refresh(); getch(); endwin(); } ncurses-5.99.0/src/constants.rs010064400017500000144000000302071343463741600147030ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: constants.rs Author: Jesse 'Jeaye' Wilkerson Description: Constants that follow the ncurses library for use with the safe wrappers. */ use libc::{ c_char, c_int }; use super::ll::*; mod wrapped { use libc::{ c_char, c_int }; use ll::chtype; use ll::WINDOW; extern "C" { pub static curscr: WINDOW; pub static newscr: WINDOW; pub static stdscr: WINDOW; pub static ttytype: *mut c_char; pub static COLORS: c_int; pub static COLOR_PAIRS: c_int; pub static COLS: c_int; pub static ESCDELAY: c_int; pub static LINES: c_int; pub static TABSIZE: c_int; /* Line graphics */ pub static mut acs_map: [chtype; 0]; } } macro_rules! wrap_extern { ($name:ident: $t:ty) => { pub fn $name() -> $t { unsafe { wrapped::$name } } } } wrap_extern!(curscr: WINDOW); wrap_extern!(newscr: WINDOW); wrap_extern!(stdscr: WINDOW); wrap_extern!(ttytype: *mut c_char); wrap_extern!(COLORS: c_int); wrap_extern!(COLOR_PAIRS: c_int); wrap_extern!(COLS: c_int); wrap_extern!(ESCDELAY: c_int); wrap_extern!(LINES: c_int); wrap_extern!(TABSIZE: c_int); pub fn acs_map() -> *const chtype { unsafe { &wrapped::acs_map as *const chtype } } /* Success/Failure. */ pub const ERR: i32 = -1; pub const OK: i32 = 0; pub const TRUE: c_bool = 1; pub const FALSE: c_bool = 0; /* Attributes. */ pub const NCURSES_ATTR_SHIFT: u32 = 8u32; /* Colors */ pub const COLOR_BLACK: i16 = 0; pub const COLOR_RED: i16 = 1; pub const COLOR_GREEN: i16 = 2; pub const COLOR_YELLOW: i16 = 3; pub const COLOR_BLUE: i16 = 4; pub const COLOR_MAGENTA: i16 = 5; pub const COLOR_CYAN: i16 = 6; pub const COLOR_WHITE: i16 = 7; /* Values for the _flags member */ pub const _SUBWIN: i32 = 0x01; /* is this a sub-window? */ pub const _ENDLINE: i32 = 0x02; /* is the window flush right? */ pub const _FULLWIN: i32 = 0x04; /* is the window full-screen? */ pub const _SCROLLWIN: i32 = 0x08; /* bottom edge is at screen bottom? */ pub const _ISPAD: i32 = 0x10; /* is this window a pad? */ pub const _HASMOVED: i32 = 0x20; /* has cursor moved since last refresh? */ pub const _WRAPPED: i32 = 0x40; /* cursor was just wrappped */ /* * This value is used in the firstchar and lastchar fields to mark * unchanged lines */ pub const _NOCHANGE: i32 = -1; /* * This value is used in the oldindex field to mark lines created by insertions * and scrolls. */ pub const _NEWINDEX: i32 = -1; /* Keys */ pub const KEY_CODE_YES: i32 = 0x100; /* A wchar_t contains a key code */ pub const KEY_MIN: i32 = 0x101; /* Minimum curses key */ pub const KEY_BREAK: i32 = 0x101; /* Break key(unreliable) */ pub const KEY_SRESET: i32 = 0x158; /* Soft(partial) reset(unreliable) */ pub const KEY_RESET: i32 = 0x159; /* Reset or hard reset(unreliable) */ pub const KEY_DOWN: i32 = 0x102; /* down-arrow key */ pub const KEY_UP: i32= 0x103; /* up-arrow key */ pub const KEY_LEFT: i32= 0x104; /* left-arrow key */ pub const KEY_RIGHT: i32= 0x105; /* right-arrow key */ pub const KEY_HOME: i32= 0x106; /* home key */ pub const KEY_BACKSPACE: i32= 0x107; /* backspace key */ pub const KEY_F0: i32= 0x108; /* Function keys. Space for 64 */ pub const KEY_F1: i32= 0x109; pub const KEY_F2: i32= 0x10a; pub const KEY_F3: i32= 0x10b; pub const KEY_F4: i32= 0x10c; pub const KEY_F5: i32= 0x10d; pub const KEY_F6: i32= 0x10e; pub const KEY_F7: i32= 0x10f; pub const KEY_F8: i32= 0x110; pub const KEY_F9: i32= 0x111; pub const KEY_F10: i32= 0x112; pub const KEY_F11: i32= 0x113; pub const KEY_F12: i32= 0x114; pub const KEY_F13: i32= 0x115; pub const KEY_F14: i32= 0x116; pub const KEY_F15: i32= 0x117; pub const KEY_DL: i32= 0x148; /* delete-line key */ pub const KEY_IL: i32= 0x149; /* insert-line key */ pub const KEY_DC: i32= 0x14a; /* delete-character key */ pub const KEY_IC: i32= 0x14b; /* insert-character key */ pub const KEY_EIC: i32= 0x14c; /* sent by rmir or smir in insert mode */ pub const KEY_CLEAR: i32= 0x14d; /* clear-screen or erase key */ pub const KEY_EOS: i32= 0x14e; /* clear-to-end-of-screen key */ pub const KEY_EOL: i32= 0x14f; /* clear-to-end-of-line key */ pub const KEY_SF: i32= 0x150; /* scroll-forward key */ pub const KEY_SR: i32= 0x151; /* scroll-backward key */ pub const KEY_NPAGE: i32= 0x152; /* next-page key */ pub const KEY_PPAGE: i32= 0x153; /* previous-page key */ pub const KEY_STAB: i32= 0x154; /* set-tab key */ pub const KEY_CTAB: i32= 0x155; /* clear-tab key */ pub const KEY_CATAB: i32= 0x156; /* clear-all-tabs key */ pub const KEY_ENTER: i32= 0x157; /* enter/send key */ pub const KEY_PRINT: i32= 0x15a; /* print key */ pub const KEY_LL: i32= 0x15b; /* lower-left key(home down) */ pub const KEY_A1: i32= 0x15c; /* upper left of keypad */ pub const KEY_A3: i32= 0x15d; /* upper right of keypad */ pub const KEY_B2: i32= 0x15e; /* center of keypad */ pub const KEY_C1: i32= 0x15f; /* lower left of keypad */ pub const KEY_C3: i32= 0x160; /* lower right of keypad */ pub const KEY_BTAB: i32= 0x161; /* back-tab key */ pub const KEY_BEG: i32= 0x162; /* begin key */ pub const KEY_CANCEL: i32= 0x163; /* cancel key */ pub const KEY_CLOSE: i32= 0x164; /* close key */ pub const KEY_COMMAND: i32= 0x165; /* command key */ pub const KEY_COPY: i32= 0x166; /* copy key */ pub const KEY_CREATE: i32= 0x167; /* create key */ pub const KEY_END: i32= 0x168; /* end key */ pub const KEY_EXIT: i32= 0x169; /* exit key */ pub const KEY_FIND: i32= 0x16a; /* find key */ pub const KEY_HELP: i32= 0x16b; /* help key */ pub const KEY_MARK: i32= 0x16c; /* mark key */ pub const KEY_MESSAGE: i32= 0x16d; /* message key */ pub const KEY_MOVE: i32= 0x16e; /* move key */ pub const KEY_NEXT: i32= 0x16f; /* next key */ pub const KEY_OPEN: i32= 0x170; /* open key */ pub const KEY_OPTIONS: i32= 0x171; /* options key */ pub const KEY_PREVIOUS: i32= 0x172; /* previous key */ pub const KEY_REDO: i32= 0x173; /* redo key */ pub const KEY_REFERENCE: i32= 0x174; /* reference key */ pub const KEY_REFRESH: i32= 0x175; /* refresh key */ pub const KEY_REPLACE: i32= 0x176; /* replace key */ pub const KEY_RESTART: i32= 0x177; /* restart key */ pub const KEY_RESUME: i32= 0x178; /* resume key */ pub const KEY_SAVE: i32= 0x179; /* save key */ pub const KEY_SBEG: i32= 0x17a; /* shifted begin key */ pub const KEY_SCANCEL: i32= 0x17b; /* shifted cancel key */ pub const KEY_SCOMMAND: i32= 0x17c; /* shifted command key */ pub const KEY_SCOPY: i32= 0x17d; /* shifted copy key */ pub const KEY_SCREATE: i32= 0x17e; /* shifted create key */ pub const KEY_SDC : i32= 0x17f; /* shifted delete-character key */ pub const KEY_SDL : i32= 0x180; /* shifted delete-line key */ pub const KEY_SELECT: i32= 0x181; /* select key */ pub const KEY_SEND: i32= 0x182; /* shifted end key */ pub const KEY_SEOL: i32= 0x183; /* shifted clear-to-end-of-line key */ pub const KEY_SEXIT: i32= 0x184; /* shifted exit key */ pub const KEY_SFIND: i32= 0x185; /* shifted find key */ pub const KEY_SHELP: i32= 0x186; /* shifted help key */ pub const KEY_SHOME: i32= 0x187; /* shifted home key */ pub const KEY_SIC : i32= 0x188; /* shifted insert-character key */ pub const KEY_SLEFT: i32= 0x189; /* shifted left-arrow key */ pub const KEY_SMESSAGE: i32= 0x18a; /* shifted message key */ pub const KEY_SMOVE: i32= 0x18b; /* shifted move key */ pub const KEY_SNEXT: i32= 0x18c; /* shifted next key */ pub const KEY_SOPTIONS: i32= 0x18d; /* shifted options key */ pub const KEY_SPREVIOUS: i32= 0x18e; /* shifted previous key */ pub const KEY_SPRINT: i32= 0x18f; /* shifted print key */ pub const KEY_SREDO: i32= 0x190; /* shifted redo key */ pub const KEY_SREPLACE: i32= 0x191; /* shifted replace key */ pub const KEY_SRIGHT: i32= 0x192; /* shifted right-arrow key */ pub const KEY_SRSUME: i32= 0x193; /* shifted resume key */ pub const KEY_SSAVE: i32= 0x194; /* shifted save key */ pub const KEY_SSUSPEND: i32= 0x195; /* shifted suspend key */ pub const KEY_SUNDO: i32= 0x196; /* shifted undo key */ pub const KEY_SUSPEND: i32= 0x197; /* suspend key */ pub const KEY_UNDO: i32= 0x198; /* undo key */ pub const KEY_MOUSE: i32= 0x199; /* Mouse event has occurred */ pub const KEY_RESIZE: i32= 0x19a; /* Terminal resize event */ pub const KEY_EVENT: i32= 0x19b; /* We were interrupted by an event */ pub const KEY_MAX: i32= 0x1ff; /* Maximum key value is 0633 */ #[cfg(feature="mouse_v1")] pub const NCURSES_MOUSE_VERSION: i32= 1; #[cfg(not(feature="mouse_v1"))] pub const NCURSES_MOUSE_VERSION: i32= 2; #[cfg(feature = "mouse_v1")] const MASK_SHIFT: i32 = 6; #[cfg(not(feature = "mouse_v1"))] const MASK_SHIFT: i32 = 5; #[cfg(feature = "mouse_v1")] const MODIFIER_SHIFT: i32 = 5; #[cfg(not(feature = "mouse_v1"))] const MODIFIER_SHIFT: i32 = 6; /* Mouse Support */ macro_rules! ncurses_mouse_mask( ($b:expr, $m:expr) => ($m << (($b - 1) * MASK_SHIFT)); ); pub const NCURSES_BUTTON_RELEASED: i32= 0x001; pub const NCURSES_BUTTON_PRESSED: i32= 0x002; pub const NCURSES_BUTTON_CLICKED: i32= 0x004; pub const NCURSES_DOUBLE_CLICKED: i32= 0x008; pub const NCURSES_TRIPLE_CLICKED: i32= 0x010; pub const NCURSES_RESERVED_EVENT: i32= 0x020; /* event masks */ pub const BUTTON1_RELEASED: i32= ncurses_mouse_mask!(1, NCURSES_BUTTON_RELEASED); pub const BUTTON1_PRESSED: i32= ncurses_mouse_mask!(1, NCURSES_BUTTON_PRESSED); pub const BUTTON1_CLICKED: i32= ncurses_mouse_mask!(1, NCURSES_BUTTON_CLICKED); pub const BUTTON1_DOUBLE_CLICKED: i32= ncurses_mouse_mask!(1, NCURSES_DOUBLE_CLICKED); pub const BUTTON1_TRIPLE_CLICKED: i32= ncurses_mouse_mask!(1, NCURSES_TRIPLE_CLICKED); pub const BUTTON2_RELEASED: i32= ncurses_mouse_mask!(2, NCURSES_BUTTON_RELEASED); pub const BUTTON2_PRESSED: i32= ncurses_mouse_mask!(2, NCURSES_BUTTON_PRESSED); pub const BUTTON2_CLICKED: i32= ncurses_mouse_mask!(2, NCURSES_BUTTON_CLICKED); pub const BUTTON2_DOUBLE_CLICKED: i32= ncurses_mouse_mask!(2, NCURSES_DOUBLE_CLICKED); pub const BUTTON2_TRIPLE_CLICKED: i32= ncurses_mouse_mask!(2, NCURSES_TRIPLE_CLICKED); pub const BUTTON3_RELEASED: i32= ncurses_mouse_mask!(3, NCURSES_BUTTON_RELEASED); pub const BUTTON3_PRESSED: i32= ncurses_mouse_mask!(3, NCURSES_BUTTON_PRESSED); pub const BUTTON3_CLICKED: i32= ncurses_mouse_mask!(3, NCURSES_BUTTON_CLICKED); pub const BUTTON3_DOUBLE_CLICKED: i32= ncurses_mouse_mask!(3, NCURSES_DOUBLE_CLICKED); pub const BUTTON3_TRIPLE_CLICKED: i32= ncurses_mouse_mask!(3, NCURSES_TRIPLE_CLICKED); pub const BUTTON4_RELEASED: i32= ncurses_mouse_mask!(4, NCURSES_BUTTON_RELEASED); pub const BUTTON4_PRESSED: i32= ncurses_mouse_mask!(4, NCURSES_BUTTON_PRESSED); pub const BUTTON4_CLICKED: i32= ncurses_mouse_mask!(4, NCURSES_BUTTON_CLICKED); pub const BUTTON4_DOUBLE_CLICKED: i32= ncurses_mouse_mask!(4, NCURSES_DOUBLE_CLICKED); pub const BUTTON4_TRIPLE_CLICKED: i32= ncurses_mouse_mask!(4, NCURSES_TRIPLE_CLICKED); pub const BUTTON5_RELEASED: i32= ncurses_mouse_mask!(5, NCURSES_BUTTON_RELEASED); pub const BUTTON5_PRESSED: i32= ncurses_mouse_mask!(5, NCURSES_BUTTON_PRESSED); pub const BUTTON5_CLICKED: i32= ncurses_mouse_mask!(5, NCURSES_BUTTON_CLICKED); pub const BUTTON5_DOUBLE_CLICKED: i32= ncurses_mouse_mask!(5, NCURSES_DOUBLE_CLICKED); pub const BUTTON5_TRIPLE_CLICKED: i32= ncurses_mouse_mask!(5, NCURSES_TRIPLE_CLICKED); pub const BUTTON_CTRL: i32 = ncurses_mouse_mask!(MODIFIER_SHIFT, 0x001); pub const BUTTON_SHIFT: i32 = ncurses_mouse_mask!(MODIFIER_SHIFT, 0x002); pub const BUTTON_ALT: i32 = ncurses_mouse_mask!(MODIFIER_SHIFT, 0x004); pub const REPORT_MOUSE_POSITION: i32 = ncurses_mouse_mask!(MODIFIER_SHIFT, 0x008); pub const ALL_MOUSE_EVENTS: i32= REPORT_MOUSE_POSITION - 1; /* locales */ pub const LC_ALL: c_int = 0; pub const LC_COLLATE: c_int = 1; pub const LC_CTYPE: c_int = 2; pub const LC_MONETARY: c_int = 3; pub const LC_NUMERIC: c_int = 4; pub const LC_TIME: c_int = 5; pub const LC_MESSAGES: c_int = 6; #[derive(Debug)] #[repr(i32)] pub enum LcCategory { all = LC_ALL, collate = LC_COLLATE, ctype = LC_CTYPE, monetary = LC_MONETARY, numeric = LC_NUMERIC, time = LC_TIME, messages = LC_MESSAGES, } ncurses-5.99.0/src/lib.rs010064400017500000144000001226541343463741600134450ustar0000000000000000/* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: lib.rs Author: Jesse 'Jeaye' Wilkerson Description: Safe wrappers for ncurses functions. */ #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![warn(missing_debug_implementations)] extern crate libc; use std::mem; use std::{ char, ptr }; use std::ffi::{CString, CStr}; use self::ll::{FILE_p}; pub use self::constants::*; pub use self::panel::wrapper::*; pub use self::menu::wrapper::*; pub use self::menu::constants::*; pub type chtype = self::ll::chtype; pub type winttype = u32; pub type mmask_t = chtype; pub type attr_t = chtype; pub type NCURSES_ATTR_T = attr_t; pub mod ll; pub mod constants; pub mod panel; pub mod menu; trait FromCStr { unsafe fn from_c_str(s: *const libc::c_char) -> Self; } impl FromCStr for String { unsafe fn from_c_str(s: *const libc::c_char) -> String { let bytes = CStr::from_ptr(s).to_bytes(); String::from_utf8_unchecked(bytes.to_vec()) } } impl FromCStr for Option { unsafe fn from_c_str(s: *const libc::c_char) -> Option { if s.is_null() { None } else { Some(FromCStr::from_c_str(s)) } } } trait ToCStr { fn to_c_str(&self) -> CString; } impl <'a>ToCStr for &'a str { fn to_c_str(&self) -> CString { CString::new(*self).unwrap() } } #[derive(Debug, Clone, Copy)] pub enum CURSOR_VISIBILITY { CURSOR_INVISIBLE = 0, CURSOR_VISIBLE, CURSOR_VERY_VISIBLE } pub type WINDOW = self::ll::WINDOW; pub type SCREEN = self::ll::SCREEN; pub type mmaskt = self::ll::mmask_t; pub type MEVENT = self::ll::MEVENT; pub fn addch(ch: chtype) -> i32 { unsafe { ll::addch(ch) } } pub fn addchnstr(s: &[chtype], n: i32) -> i32 { unsafe { ll::addchnstr(s.as_ptr(), n) } } pub fn addchstr(s: &[chtype]) -> i32 { unsafe { ll::addchstr(s.as_ptr()) } } pub fn addnstr(s: &str, n: i32) -> i32 { unsafe { ll::addnstr(s.to_c_str().as_ptr(), n) } } pub fn addstr(s: &str) -> i32 { unsafe { ll::addstr(s.to_c_str().as_ptr()) } } pub fn assume_default_colors(fg: i32, bg: i32) -> i32 { unsafe { ll::assume_default_colors(fg, bg) } } pub fn attroff(a: NCURSES_ATTR_T) -> i32 { unsafe { ll::attroff(a) } } pub fn attron(a: NCURSES_ATTR_T) -> i32 { unsafe { ll::attron(a) } } pub fn attrset(a: NCURSES_ATTR_T) -> i32 { unsafe { ll::attrset(a) } } pub fn attr_get(attrs: &mut attr_t, pair: &mut i16) -> i32 { unsafe { ll::attr_get(&mut* attrs as *mut attr_t, &mut* pair as *mut i16, ptr::null()) } } pub fn attr_off(a: attr_t) -> i32 { unsafe { ll::attr_off(a, ptr::null()) } } pub fn attr_on(a: attr_t) -> i32 { unsafe { ll::attr_on(a, ptr::null()) } } pub fn attr_set(attr: attr_t, pair: i16) -> i32 { unsafe { ll::attr_set(attr, pair, ptr::null()) } } pub fn baudrate() -> i32 { unsafe { ll::baudrate() } } pub fn beep() -> i32 { unsafe { ll::beep() } } pub fn bkgd(ch: chtype) -> i32 { unsafe { ll::bkgd(ch) } } pub fn bkgdset(ch: chtype) { unsafe { ll::bkgdset(ch) } } pub fn border(ls: chtype, rs: chtype, ts: chtype, bs: chtype, tl: chtype, tr: chtype, bl: chtype, br: chtype) -> i32 { unsafe { ll::border(ls, rs, ts, bs, tl, tr, bl, br) } } #[link_name="box"] pub fn box_(w: WINDOW, v: chtype, h: chtype) -> i32 { wborder(w, v, v, h, h, 0, 0, 0, 0) } pub fn can_change_color() -> bool { unsafe { ll::can_change_color() == TRUE } } pub fn cbreak() -> i32 { unsafe { ll::cbreak() } } pub fn chgat(n: i32, attr: attr_t, color: i16) -> i32 { unsafe { ll::chgat(n, attr, color, ptr::null()) } } pub fn clear() -> i32 { unsafe { ll::clear() } } pub fn clearok(w: WINDOW, ok: bool) -> i32 { unsafe { ll::clearok(w, ok as ll::c_bool) } } pub fn clrtobot() -> i32 { unsafe { ll::clrtobot() } } pub fn clrtoeol() -> i32 { unsafe { ll::clrtoeol() } } pub fn color_content(color: i16, r: &mut i16, g: &mut i16, b: &mut i16) -> i32 { unsafe { ll::color_content(color, &mut*r as *mut i16, &mut*g as *mut i16, &mut*b as *mut i16) } } pub fn color_set(pair: i16) -> i32 { unsafe { ll::color_set(pair, ptr::null()) } } pub fn copywin(src_win: WINDOW, dest_win: WINDOW, src_min_row: i32, src_min_col: i32, dest_min_row: i32, dest_min_col: i32, dest_max_row: i32, dest_max_col: i32, overlay: i32) -> i32 { unsafe { ll::copywin(src_win, dest_win, src_min_row, src_min_col, dest_min_row, dest_min_col, dest_max_row, dest_max_col, overlay) } } pub fn curs_set(visibility: CURSOR_VISIBILITY) -> Option { unsafe { match ll::curs_set(visibility as i32) { ERR => None, ret => Some(mem::transmute::(ret as i8)), } } } pub fn def_prog_mode() -> i32 { unsafe { ll::def_prog_mode() } } pub fn def_shell_mode() -> i32 { unsafe { ll::def_shell_mode() } } pub fn delay_output(ms: i32) -> i32 { unsafe { ll::delay_output(ms) } } pub fn delch() -> i32 { unsafe { ll::delch() } } pub fn delscreen(s: SCREEN) { unsafe { ll::delscreen(s) } } pub fn delwin(w: WINDOW) -> i32 { unsafe { ll::delwin(w) } } pub fn deleteln() -> i32 { unsafe { ll::deleteln() } } pub fn derwin(w: WINDOW, lines: i32, cols: i32, x: i32, y: i32) -> WINDOW { unsafe { ll::derwin(w, lines, cols, x, y) } } pub fn doupdate() -> i32 { unsafe { ll::doupdate() } } pub fn dupwin(w: WINDOW) -> WINDOW { unsafe { ll::dupwin(w) } } pub fn echo() -> i32 { unsafe { ll::echo() } } pub fn echochar(c: chtype) -> i32 { unsafe { ll::echochar(c) } } pub fn erase() -> i32 { unsafe { ll::erase() } } pub fn endwin() -> i32 { unsafe { ll::endwin() } } pub fn erasechar() -> char { unsafe { char::from_u32(ll::erasechar() as u32).expect("Invalid char") } } pub fn filter() { unsafe { ll::filter() } } pub fn flash() -> i32 { unsafe { ll::flash() } } pub fn flushinp() -> i32 { unsafe { ll::flushinp() } } pub fn getbkgd(w: WINDOW) -> chtype { unsafe { ll::getbkgd(w) } } pub fn getch() -> i32 { unsafe { ll::getch() } } #[derive(Debug)] pub enum WchResult { KeyCode(i32), Char(winttype), } pub fn get_wch() -> Option { unsafe { let mut x = 0; match ll::get_wch(&mut x) { OK => { Some(WchResult::Char(x)) } KEY_CODE_YES => { Some(WchResult::KeyCode(x as i32)) } _ => { None } } } } pub fn mvget_wch(y: i32, x: i32) -> Option { unsafe { let mut result = 0; match ll::mvget_wch(y, x, &mut result) { OK => { Some(WchResult::Char(result)) } KEY_CODE_YES => { Some(WchResult::KeyCode(result as i32)) } _ => { None } } } } #[cfg(feature = "wide")] pub fn wget_wch(w: WINDOW) -> Option { unsafe { let mut result = 0; match ll::wget_wch(w, &mut result) { OK => { Some(WchResult::Char(result)) } KEY_CODE_YES => { Some(WchResult::KeyCode(result as i32)) } _ => { None } } } } #[cfg(feature = "wide")] pub fn mvwget_wch(w: WINDOW, y: i32, x: i32) -> Option { unsafe { let mut result = 0; match ll::mvwget_wch(w, y, x, &mut result) { OK => { Some(WchResult::Char(result)) } KEY_CODE_YES => { Some(WchResult::KeyCode(result as i32)) } _ => { None } } } } pub fn unget_wch(ch: u32) -> i32 { unsafe { ll::unget_wch(ch) } } pub fn getnstr(s: &mut String, n: i32) -> i32 { wgetnstr(stdscr(), s, n) } pub fn getstr(s: &mut String) -> i32 { /* XXX: This is probably broken. */ let mut ch = getch(); while ch != '\n' as i32 && ch != '\r' as i32 { unsafe { s.as_mut_vec().push(ch as u8); } ch = getch(); } OK } pub fn getwin(reader: *mut libc::FILE) -> WINDOW { unsafe { ll::getwin(reader) } } /* TODO: Make this safe. */ pub fn getattrs(w: WINDOW) -> i32 { unsafe { ll::getattrs(w) } } pub fn getcurx(w: WINDOW) -> i32 { unsafe { ll::getcurx(w) } } pub fn getcury(w: WINDOW) -> i32 { unsafe { ll::getcury(w) } } pub fn getbegx(w: WINDOW) -> i32 { unsafe { ll::getbegx(w) } } pub fn getbegy(w: WINDOW) -> i32 { unsafe { ll::getbegy(w) } } pub fn getmaxx(w: WINDOW) -> i32 { unsafe { ll::getmaxx(w) } } pub fn getmaxy(w: WINDOW) -> i32 { unsafe { ll::getmaxy(w) } } pub fn getparx(w: WINDOW) -> i32 { unsafe { ll::getparx(w) } } pub fn getpary(w: WINDOW) -> i32 { unsafe { ll::getpary(w) } } pub fn halfdelay(tenths: i32) -> i32 { unsafe { ll::halfdelay(tenths) } } pub fn has_colors() -> bool { unsafe { ll::has_colors() == TRUE } } pub fn has_ic() -> bool { unsafe { ll::has_ic() == TRUE } } pub fn has_il() -> bool { unsafe { ll::has_il() == TRUE } } pub fn hline(ch: chtype, n: i32) -> i32 { unsafe { ll::hline(ch, n) } } pub fn idcok(w: WINDOW, bf: bool) { unsafe { ll::idcok(w, bf as ll::c_bool) } } pub fn idlok(w: WINDOW, bf: bool) -> i32 { unsafe { ll::idlok(w, bf as ll::c_bool) } } pub fn immedok(w: WINDOW, bf: bool) { unsafe { ll::immedok(w, bf as ll::c_bool) } } pub fn inch() -> chtype { unsafe { ll::inch() } } pub fn inchnstr(s: &mut Vec, n: i32) -> i32 { /* XXX: This is probably broken. */ s.clear(); s.reserve(n as usize); unsafe { let ret = ll::inchnstr(s.as_ptr(), n); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn inchstr(s: &mut Vec) -> i32 { /* XXX: This is probably broken. */ unsafe { let ret = ll::inchstr(s.as_ptr()); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn initscr() -> WINDOW { unsafe { ll::initscr() } } pub fn init_color(color: i16, r: i16, g: i16, b: i16) -> i32 { unsafe { ll::init_color(color, r, g, b) } } pub fn init_pair(pair: i16, f: i16, b: i16) -> i32 { unsafe { ll::init_pair(pair, f, b) } } pub fn innstr(s: &mut String, n: i32) -> i32 { /* XXX: This is probably broken. */ unsafe { s.as_mut_vec().clear(); s.reserve(n as usize); let buf = s.as_bytes().as_ptr(); let ret = ll::innstr(mem::transmute(buf), n); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn insch(ch: chtype) -> i32 { unsafe { ll::insch(ch) } } pub fn insdelln(n: i32) -> i32 { unsafe { ll::insdelln(n) } } pub fn insertln() -> i32 { unsafe { ll::insertln() } } pub fn insnstr(s: &str, n: i32) -> i32 { unsafe { let buf = s.as_ptr(); ll::insnstr(mem::transmute(buf), n) } } pub fn insstr(s: &str) -> i32 { unsafe { let buf = s.as_ptr(); ll::insstr(mem::transmute(buf)) } } pub fn instr(s: &mut String) -> i32 { /* XXX: This is probably broken. */ unsafe { let buf = s.as_bytes().as_ptr(); let ret = ll::instr(mem::transmute(buf)); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn intrflush(w: WINDOW, bf: bool) -> i32 { unsafe { ll::intrflush(w, bf as ll::c_bool) } } pub fn isendwin() -> bool { unsafe { ll::isendwin() == TRUE } } pub fn is_linetouched(w: WINDOW, l: i32) -> bool { unsafe { ll::is_linetouched(w, l) == TRUE } } pub fn is_wintouched(w: WINDOW) -> bool { unsafe { ll::is_wintouched(w) == TRUE } } pub fn is_term_resized(lines: i32, cols: i32) -> bool { unsafe { ll::is_term_resized(lines, cols) == TRUE } } pub fn is_cleared(w: WINDOW) -> bool { unsafe { ll::is_cleared(w) == TRUE } } pub fn is_idcok(w: WINDOW) -> bool { unsafe { ll::is_idcok(w) == TRUE } } pub fn is_idlok(w: WINDOW) -> bool { unsafe { ll::is_idlok(w) == TRUE } } pub fn is_immedok(w: WINDOW) -> bool { unsafe { ll::is_immedok(w) == TRUE } } pub fn is_keypad(w: WINDOW) -> bool { unsafe { ll::is_keypad(w) == TRUE } } pub fn is_leaveok(w: WINDOW) -> bool { unsafe { ll::is_leaveok(w) == TRUE } } pub fn is_nodelay(w: WINDOW) -> bool { unsafe { ll::is_nodelay(w) == TRUE } } pub fn is_notimeout(w: WINDOW) -> bool { unsafe { ll::is_notimeout(w) == TRUE } } pub fn is_scrollok(w: WINDOW) -> bool { unsafe { ll::is_scrollok(w) == TRUE } } pub fn is_syncok(w: WINDOW) -> bool { unsafe { ll::is_syncok(w) == TRUE }} pub fn keyname(c: i32) -> Option { unsafe { FromCStr::from_c_str(ll::keyname(c)) } } pub fn keypad(w: WINDOW, bf: bool) -> i32 { unsafe { ll::keypad(w, bf as ll::c_bool) } } pub fn killchar() -> char { unsafe { char::from_u32(ll::killchar() as u32).expect("Invalid char") } } pub fn leaveok(w: WINDOW, bf: bool) -> i32 { unsafe { ll::leaveok(w, bf as ll::c_bool) } } pub fn longname() -> String { unsafe { FromCStr::from_c_str(ll::longname()) } } pub fn meta(w: WINDOW, bf: bool) -> i32 { unsafe { ll::meta(w, bf as ll::c_bool) } } pub fn mv(y: i32, x: i32) -> i32 { unsafe { ll::mv(y, x) } } pub fn mvaddch(y: i32, x: i32, c: chtype) -> i32 { unsafe { ll::mvaddch(y, x, c) } } pub fn mvaddchnstr(y: i32, x: i32, s: &[chtype], n: i32) -> i32 { if mv(y, x) == ERR { return ERR; } addchnstr(s, n) } pub fn mvaddchstr(y: i32, x: i32, s: &[chtype]) -> i32 { if mv(y, x) == ERR { return ERR; } addchstr(s) } pub fn mvaddnstr(y: i32, x: i32, s: &str, n: i32) -> i32 { if mv(y, x) == ERR { return ERR; } addnstr(s, n) } pub fn mvaddstr(y: i32, x: i32, s: &str) -> i32 { if mv(y, x) == ERR { return ERR; } addstr(s) } pub fn mvchgat(y: i32, x: i32, n: i32, attr: attr_t, color: i16) -> i32 { unsafe { ll::mvchgat(y, x, n, attr, color, ptr::null()) } } pub fn mvcur(old_y: i32, old_x: i32, new_y: i32, new_x: i32) -> i32 { unsafe { ll::mvcur(old_y, old_x, new_y, new_x) } } pub fn mvdelch(y: i32, x: i32) -> i32 { unsafe { ll::mvdelch(y, x) } } pub fn mvderwin(w: WINDOW, y: i32, x: i32) -> i32 { unsafe { ll::mvderwin(w, y, x) } } pub fn mvgetch(y: i32, x: i32) -> i32 { unsafe { ll::mvgetch(y, x) } } pub fn mvgetnstr(y: i32, x: i32, s: &mut String, n: i32) -> i32 { match mv(y, x) { OK => getnstr(s, n), _ => ERR, } } pub fn mvgetstr(y: i32, x: i32, s: &mut String) -> i32 { if mv(y, x) == ERR { return ERR; } getstr(s) } pub fn mvhline(y: i32, x: i32, ch: chtype, n: i32) -> i32 { unsafe { ll::mvhline(y, x, ch, n) } } pub fn mvinch(y: i32, x: i32) -> chtype { unsafe { ll::mvinch(y, x) } } pub fn mvinchnstr(y: i32, x: i32, s: &mut Vec, n: i32) -> i32 { if mv(y, x) == ERR { return ERR; } inchnstr(s, n) } pub fn mvinchstr(y: i32, x: i32, s: &mut Vec) -> i32 { if mv(y, x) == ERR { return ERR; } inchstr(s) } pub fn mvinnstr(y: i32, x: i32, s: &mut String, n: i32) -> i32 { if mv(y, x) == ERR { return ERR; } innstr(s, n) } pub fn mvinsch(y: i32, x: i32, ch: chtype) -> i32 { unsafe { ll::mvinsch(y, x, ch) } } pub fn mvinsnstr(y: i32, x: i32, s: &str, n: i32) -> i32 { if mv(y, x) == ERR { return ERR; } insnstr(s, n) } pub fn mvinsstr(y: i32, x: i32, s: &str) -> i32 { if mv(y, x) == ERR { return ERR; } insstr(s) } pub fn mvinstr(y: i32, x: i32, s: &mut String) -> i32 { if mv(y, x) == ERR { return ERR; } instr(s) } pub fn mvprintw(y: i32, x: i32, s: &str) -> i32 { if mv(y, x) == ERR { return ERR; } printw(s) } pub fn mvvline(y: i32, x: i32, ch: chtype, n: i32) -> i32 { unsafe { ll::mvvline(y, x, ch, n) } } pub fn mvwaddch(w: WINDOW, y: i32, x: i32, ch: chtype) -> i32 { unsafe { ll::mvwaddch(w, y, x, ch) } } pub fn mvwaddchnstr(w: WINDOW, y: i32, x: i32, s: &[chtype], n: i32) -> i32 { unsafe { ll::mvwaddchnstr(w, y, x, s.as_ptr(), n) } } pub fn mvwaddchstr(w: WINDOW, y: i32, x: i32, s: &[chtype]) -> i32 { unsafe { ll::mvwaddchstr(w, y, x, s.as_ptr()) } } pub fn mvwaddnstr(w: WINDOW, y: i32, x: i32, s: &str, n: i32) -> i32 { unsafe { ll::mvwaddnstr(w, y, x, s.to_c_str().as_ptr(), n) } } pub fn mvwaddstr(w: WINDOW, y: i32, x: i32, s: &str) -> i32 { unsafe { ll::mvwaddstr(w, y, x, s.to_c_str().as_ptr()) } } pub fn mvwchgat(w: WINDOW, y: i32, x: i32, n: i32, attr: attr_t, color: i16) -> i32 { unsafe { ll::mvwchgat(w, y, x, n, attr, color, ptr::null()) } } pub fn mvwdelch(w: WINDOW, y: i32, x: i32) -> i32 { unsafe { ll::mvwdelch(w, y, x) } } pub fn mvwgetch(w: WINDOW, y: i32, x: i32) -> i32 { unsafe { ll::mvwgetch(w, y, x) } } pub fn mvwgetnstr(w: WINDOW, y: i32, x: i32, s: &mut String, n: i32) -> i32 { match wmove(w, y, x) { OK => wgetnstr(w, s, n), _ => ERR, } } pub fn mvwgetstr(w: WINDOW, y: i32, x: i32, s: &mut String) -> i32 { if mv(y, x) == ERR { return ERR; } /* XXX: This is probably broken. */ let mut ch = wgetch(w); while ch != '\n' as i32 && ch != '\r' as i32 { unsafe { s.as_mut_vec().push(ch as u8); } ch = wgetch(w); } OK } pub fn mvwhline(w: WINDOW, y: i32, x: i32, ch: chtype, n: i32) -> i32 { unsafe { ll::mvwhline(w, y, x, ch, n) } } pub fn mvwin(w: WINDOW, y: i32, x: i32) -> i32 { unsafe { ll::mvwin(w, y, x) } } pub fn mvwinch(w: WINDOW, y: i32, x: i32) -> chtype { unsafe { ll::mvwinch(w, y, x) } } pub fn mvwinchnstr(w: WINDOW, y: i32, x: i32, s: &mut Vec, n: i32) -> i32 { /* XXX: This is probably broken. */ s.clear(); s.reserve(n as usize); unsafe { let ret = ll::mvwinchnstr(w, y, x, s.as_ptr(), n); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn mvwinchstr(w: WINDOW, y: i32, x: i32, s: &mut Vec) -> i32 { /* XXX: This is probably broken. */ unsafe { let ret = ll::mvwinchstr(w, y, x, s.as_ptr()); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn mvwinnstr(w: WINDOW, y: i32, x: i32, s: &mut String, n: i32) -> i32 { /* XXX: This is probably broken. */ unsafe { s.as_mut_vec().clear(); s.reserve(n as usize); let buf = s.as_bytes().as_ptr(); let ret = ll::mvwinnstr(w, y, x, mem::transmute(buf), n); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn mvwinsch(w: WINDOW, y: i32, x: i32, ch: chtype) -> i32 { unsafe { ll::mvwinsch(w, y, x, ch) } } pub fn mvwinsnstr(w: WINDOW, y: i32, x: i32, s: &str, n: i32) -> i32 { unsafe { ll::mvwinsnstr(w, y, x, s.to_c_str().as_ptr(), n) } } pub fn mvwinsstr(w: WINDOW, y: i32, x: i32, s: &str) -> i32 { unsafe { ll::mvwinsstr(w, y, x, s.to_c_str().as_ptr()) } } pub fn mvwinstr(w: WINDOW, y: i32, x: i32, s: &mut String) -> i32 { /* XXX: This is probably broken. */ unsafe { let buf = s.as_bytes().as_ptr(); let ret = ll::mvwinstr(w, y, x, mem::transmute(buf)); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn mvwprintw(w: WINDOW, y: i32, x: i32, s: &str) -> i32 { unsafe { ll::mvwprintw(w, y, x, s.to_c_str().as_ptr()) } } pub fn mvwvline(w: WINDOW, y: i32, x: i32, ch: chtype, n: i32) -> i32 { unsafe { ll::mvwvline(w, y, x, ch, n) } } pub fn napms(ms: i32) -> i32 { unsafe { ll::napms(ms) } } pub fn newpad(lines: i32, cols: i32) -> WINDOW { unsafe { ll::newpad(lines, cols) } } pub fn newterm(ty: Option<&str>, out_fd: FILE_p, in_fd: FILE_p) -> SCREEN { unsafe { match ty { Some(s) => ll::newterm(s.to_c_str().as_ptr(), out_fd, in_fd), None => ll::newterm(std::ptr::null(), out_fd, in_fd), } } } pub fn newwin(lines: i32, cols: i32, y: i32, x: i32) -> WINDOW { unsafe { ll::newwin(lines, cols, y, x) } } pub fn nl() -> i32 { unsafe { ll::nl() } } pub fn nocbreak() -> i32 { unsafe { ll::nocbreak() } } pub fn nodelay(w: WINDOW, bf: bool) -> i32 { unsafe { ll::nodelay(w, bf as ll::c_bool) } } pub fn noecho() -> i32 { unsafe { ll::noecho() } } pub fn nonl() -> i32 { unsafe { ll::nonl() } } pub fn noqiflush() { unsafe { ll::noqiflush() } } pub fn noraw() -> i32 { unsafe { ll::noraw() } } pub fn notimeout(w: WINDOW, bf: bool) -> i32 { unsafe { ll::notimeout(w, bf as ll::c_bool) } } pub fn overlay(src: WINDOW, dst: WINDOW) -> i32 { unsafe { ll::overlay(src, dst) } } pub fn overwrite(src: WINDOW, dst: WINDOW) -> i32 { unsafe { ll::overwrite(src, dst) } } pub fn pair_content(pair: i16, f: &mut i16, b: &mut i16) -> i32 { unsafe { ll::pair_content(pair, &mut*f as *mut i16, &mut*b as *mut i16) } } pub fn PAIR_NUMBER(attr: i32) -> i32 { unsafe { ll::PAIR_NUMBER(attr) } } pub fn pechochar(pad: WINDOW, ch: chtype) -> i32 { unsafe { ll::pechochar(pad, ch) } } pub fn pnoutrefresh(pad: WINDOW, pmin_row: i32, pmin_col: i32, smin_row: i32, smin_col: i32, smax_row: i32, smax_col: i32) -> i32 { unsafe { ll::pnoutrefresh(pad, pmin_row, pmin_col, smin_row, smin_col, smax_row, smax_col) } } pub fn prefresh(pad: WINDOW, pmin_row: i32, pmin_col: i32, smin_row: i32, smin_col: i32, smax_row: i32, smax_col: i32) -> i32 { unsafe { ll::prefresh(pad, pmin_row, pmin_col, smin_row, smin_col, smax_row, smax_col) } } #[deprecated(since = "5.98.0", note = "printw can segfault when printing string that contains % sign. Use addstr instead")] pub fn printw(s: &str) -> i32 { unsafe { ll::printw(s.to_c_str().as_ptr()) } } pub fn putp(s: &str) -> i32 { unsafe { ll::putp(s.to_c_str().as_ptr()) } } pub fn putwin(w: WINDOW, f: FILE_p) -> i32 { unsafe { ll::putwin(w, f) } } pub fn qiflush() { unsafe { ll::qiflush() } } pub fn raw() -> i32 { unsafe { ll::raw() } } pub fn redrawwin(w: WINDOW) -> i32 { unsafe { ll::redrawwin(w) } } pub fn refresh() -> i32 { unsafe { ll::refresh() } } pub fn resetty() -> i32 { unsafe { ll::resetty() } } pub fn reset_prog_mode() -> i32 { unsafe { ll::reset_prog_mode() } } pub fn reset_shell_mode() -> i32 { unsafe { ll::reset_shell_mode() } } pub fn resizeterm(lines: i32, cols: i32) -> i32 { unsafe { ll::resizeterm(lines, cols) } } pub fn resize_term(lines: i32, cols: i32) -> i32 { unsafe { ll::resize_term(lines, cols) } } pub fn savetty() -> i32 { unsafe { ll::savetty() } } pub fn scr_dump(filename: &str) -> i32 { unsafe { ll::scr_dump(filename.to_c_str().as_ptr()) } } pub fn scr_init(filename: &str) -> i32 { unsafe { ll::scr_init(filename.to_c_str().as_ptr()) } } pub fn scrl(n: i32) -> i32 { unsafe { ll::scrl(n) } } pub fn scroll(w: WINDOW) -> i32 { unsafe { ll::scroll(w) } } pub fn scrollok(w: WINDOW, bf: bool) -> i32 { unsafe { ll::scrollok(w, bf as ll::c_bool) } } pub fn scr_restore(filename: &str) -> i32 { unsafe { ll::scr_restore(filename.to_c_str().as_ptr()) } } pub fn scr_set(filename: &str) -> i32 { unsafe { ll::scr_set(filename.to_c_str().as_ptr()) } } pub fn setlocale(lc: LcCategory, locale: &str) -> String { unsafe { let c_str = locale.to_c_str(); let buf = c_str.as_ptr(); let ret = ll::setlocale(lc as libc::c_int, buf); if ret == ptr::null() { String::new() } else { // The clone is necessary, as the returned pointer // can change at any time CStr::from_ptr(ret).to_string_lossy().into_owned() } } } pub fn setscrreg(top: i32, bot: i32) -> i32 { unsafe { ll::setscrreg(top, bot) } } pub fn set_term(s: SCREEN) -> SCREEN { unsafe { ll::set_term(s) } } pub fn set_escdelay(size: i32) -> i32 { unsafe { ll::set_escdelay(size) } } pub fn set_tabsize(size: i32) -> i32 { unsafe { ll::set_tabsize(size) } } pub fn slk_attroff(ch: chtype) -> i32 { unsafe { ll::slk_attroff(ch) } } // //pub fn slk_attr_off(ch: attr_t) -> i32 //{ unsafe { ll::slk_attr_off(ch, ptr::null()) } } pub fn slk_attron(ch: chtype) -> i32 { unsafe { ll::slk_attron(ch) } } // //pub fn slk_attr_on(ch: attr_t) -> i32 //{ unsafe { ll::slk_attr_on(ch, ptr::null()) } } pub fn slk_attrset(ch: chtype) -> i32 { unsafe { ll::slk_attrset(ch) } } pub fn slk_attr() -> attr_t { unsafe { ll::slk_attr() } } pub fn slk_attr_set(attrs: attr_t, pair: i16) -> i32 { unsafe { ll::slk_attr_set(attrs, pair, ptr::null()) } } pub fn slk_clear() -> i32 { unsafe { ll::slk_clear() } } pub fn slk_color(pair: i16) -> i32 { unsafe { ll::slk_color(pair) } } pub fn slk_init(fmt: i32) -> i32 { unsafe { ll::slk_init(fmt) } } pub fn slk_label(n: i32) -> String { unsafe { FromCStr::from_c_str(ll::slk_label(n)) } } pub fn slk_noutrefresh() -> i32 { unsafe { ll::slk_noutrefresh() } } pub fn slk_refresh() -> i32 { unsafe { ll::slk_refresh() } } pub fn slk_restore() -> i32 { unsafe { ll::slk_restore() } } pub fn slk_set(n: i32, s: &str, fmt: i32) -> i32 { unsafe { ll::slk_set(n, s.to_c_str().as_ptr(), fmt) } } pub fn slk_touch() -> i32 { unsafe { ll::slk_touch() }} pub fn standout() -> i32 { unsafe { ll::standout() } } pub fn standend() -> i32 { unsafe { ll::standend() } } pub fn start_color() -> i32 { unsafe { ll::start_color() } } pub fn subpad(w: WINDOW, lines: i32, cols: i32, y: i32, x: i32) -> WINDOW { unsafe { ll::subpad(w, lines, cols, y, x) } } pub fn subwin(w: WINDOW, lines: i32, cols: i32, y: i32, x: i32) -> WINDOW { unsafe { ll::subwin(w, lines, cols, y, x) } } pub fn syncok(w: WINDOW, bf: bool) -> i32 { unsafe { ll::syncok(w, bf as ll::c_bool) } } pub fn termattrs() -> chtype { unsafe { ll::termattrs() } } pub fn termname() -> String { unsafe { FromCStr::from_c_str(ll::termname()) } } pub fn timeout(delay: i32) { unsafe { ll::timeout(delay) } } pub fn touchline(w: WINDOW, start: i32, count: i32) -> i32 { unsafe { ll::touchline(w, start, count) } } pub fn touchwin(w: WINDOW) -> i32 { unsafe { ll::touchwin(w) } } pub fn typeahead(fd: i32) -> i32 { unsafe { ll::typeahead(fd) } } pub fn tigetflag(capname: &str) -> i32 { unsafe { ll::tigetflag(capname.to_c_str().as_ptr()) } } pub fn tigetnum(capname: &str) -> i32 { unsafe { ll::tigetnum(capname.to_c_str().as_ptr()) } } pub fn tigetstr(capname: &str) -> String { unsafe { { FromCStr::from_c_str(ll::tigetstr(capname.to_c_str().as_ptr())) } } } pub fn tparm(s: &str) -> String { unsafe { { FromCStr::from_c_str(ll::tparm(s.to_c_str().as_ptr())) } } } pub fn ungetch(ch: i32) -> i32 { unsafe { ll::ungetch(ch) } } pub fn untouchwin(w: WINDOW) -> i32 { unsafe { ll::untouchwin(w) } } pub fn use_env(f: bool) { unsafe { ll::use_env(f as ll::c_bool) } } pub fn use_default_colors() -> i32 { unsafe { ll::use_default_colors() } } pub fn vidattr(attrs: chtype) -> i32 { unsafe { ll::vidattr(attrs) } } pub fn vline(ch: chtype, n: i32) -> i32 { unsafe { ll::vline(ch, n) } } pub fn waddch(w: WINDOW, ch: chtype) -> i32 { unsafe { ll::waddch(w, ch) } } pub fn waddchnstr(w: WINDOW, s: &[chtype], n: i32) -> i32 { unsafe { ll::waddchnstr(w, s.as_ptr(), n) } } pub fn waddchstr(w: WINDOW, s: &[chtype]) -> i32 { unsafe { ll::waddchstr(w, s.as_ptr()) } } pub fn waddnstr(w: WINDOW, s: &str, n: i32) -> i32 { unsafe { ll::waddnstr(w, s.to_c_str().as_ptr(), n) } } pub fn waddstr(w: WINDOW, s: &str) -> i32 { unsafe { ll::waddstr(w, s.to_c_str().as_ptr()) } } pub fn wattron(w: WINDOW, attr: NCURSES_ATTR_T) -> i32 { unsafe { ll::wattron(w, attr) } } pub fn wattroff(w: WINDOW, attr: NCURSES_ATTR_T) -> i32 { unsafe { ll::wattroff(w, attr) } } pub fn wattrset(w: WINDOW, attr: NCURSES_ATTR_T) -> i32 { unsafe { ll::wattrset(w, attr) } } pub fn wattr_get(w: WINDOW, attrs: &mut attr_t, pair: &mut i16) -> i32 { unsafe { ll::wattr_get(w, &mut*attrs as *mut attr_t, &mut*pair as *mut i16, ptr::null()) } } pub fn wattr_on(w: WINDOW, attr: attr_t) -> i32 { unsafe { ll::wattr_on(w, attr, ptr::null()) } } pub fn wattr_off(w: WINDOW, attr: attr_t) -> i32 { unsafe { ll::wattr_off(w, attr, ptr::null()) } } pub fn wattr_set(w: WINDOW, attrs: attr_t, pair: i16) -> i32 { unsafe { ll::wattr_set(w, attrs, pair, ptr::null()) } } pub fn wbkgd(w: WINDOW, ch: chtype) -> i32 { unsafe { ll::wbkgd(w, ch) } } pub fn wbkgdset(w: WINDOW, ch: chtype) { unsafe { ll::wbkgdset(w, ch) } } pub fn wborder(w: WINDOW, ls: chtype, rs: chtype, ts: chtype, bs: chtype, tl: chtype, tr: chtype, bl: chtype, br: chtype) -> i32 { unsafe { ll::wborder(w, ls, rs, ts, bs, tl, tr, bl, br) } } pub fn wchgat(w: WINDOW, n: i32, attr: attr_t, color: i16) -> i32 { unsafe { ll::wchgat(w, n, attr, color, ptr::null()) } } pub fn wclear(w: WINDOW) -> i32 { unsafe { ll::wclear(w) } } pub fn wclrtobot(w: WINDOW) -> i32 { unsafe { ll::wclrtobot(w) } } pub fn wclrtoeol(w: WINDOW) -> i32 { unsafe { ll::wclrtoeol(w) } } pub fn wcolor_set(w: WINDOW, pair: i16) -> i32 { unsafe { ll::wcolor_set(w, pair, ptr::null()) } } pub fn wcursyncup(w: WINDOW) { unsafe { ll::wcursyncup(w) } } pub fn wdelch(w: WINDOW) -> i32 { unsafe { ll::wdelch(w) } } pub fn wdeleteln(w: WINDOW) -> i32 { unsafe { ll::wdeleteln(w) } } pub fn wechochar(w: WINDOW, ch: chtype) -> i32 { unsafe { ll::wechochar(w, ch) } } pub fn werase(w: WINDOW) -> i32 { unsafe { ll::werase(w) } } pub fn wgetch(w: WINDOW) -> i32 { unsafe { ll::wgetch(w) } } pub fn wgetnstr(w: WINDOW, s: &mut String, n: i32) -> i32 { let mut buff: Vec = Vec::with_capacity(n as usize); unsafe { buff.set_len(n as usize); } match unsafe { ll::wgetnstr(w, buff.as_ptr(), n) } { OK => { *s = buff.iter() .take_while(|ch| **ch != '\0' as u8 ) .map(|ch| *ch as char ) .collect(); OK }, _ => ERR, } } pub fn wgetstr(w: WINDOW, s: &mut String) -> i32 { /* XXX: This is probably broken. */ let mut ch = wgetch(w); while ch != '\n' as i32 && ch != '\r' as i32 { unsafe { s.as_mut_vec().push(ch as u8); } ch = wgetch(w); } OK } pub fn whline(w: WINDOW, ch: chtype, n: i32) -> i32 { unsafe { ll::whline(w, ch, n) } } pub fn winch(w: WINDOW) -> chtype { unsafe { ll::winch(w) } } pub fn winchnstr(w: WINDOW, s: &mut Vec, n: i32) -> i32 { /* XXX: This is probably broken. */ s.clear(); s.reserve(n as usize); unsafe { let ret = ll::winchnstr(w, s.as_ptr(), n); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn winchstr(w: WINDOW, s: &mut Vec) -> i32 { /* XXX: This is probably broken. */ unsafe { let ret = ll::winchstr(w, s.as_ptr()); let capacity = s.capacity(); match s.iter().position(|x| *x == 0) { Some(index) => s.set_len(index as usize), None => s.set_len(capacity), } ret } } pub fn winnstr(w: WINDOW, s: &mut String, n: i32) -> i32 { /* XXX: This is probably broken. */ unsafe { s.as_mut_vec().clear(); s.reserve(n as usize); let buf = s.as_bytes().as_ptr(); let ret = ll::winnstr(w, mem::transmute(buf), n); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn winsch(w: WINDOW, ch: chtype) -> i32 { unsafe { ll::winsch(w, ch) } } pub fn winsdelln(w: WINDOW, n: i32) -> i32 { unsafe { ll::winsdelln(w, n) } } pub fn winsertln(w: WINDOW) -> i32 { unsafe { ll::winsertln(w) } } pub fn winsnstr(w: WINDOW, s: &str, n: i32) -> i32 { unsafe { let buf = s.as_ptr(); ll::winsnstr(w, mem::transmute(buf), n) } } pub fn winsstr(w: WINDOW, s: &str) -> i32 { unsafe { let buf = s.as_ptr(); ll::winsstr(w, mem::transmute(buf)) } } pub fn winstr(w: WINDOW, s: &mut String) -> i32 { /* XXX: This is probably broken. */ unsafe { let buf = s.as_bytes().as_ptr(); let ret = ll::winstr(w, mem::transmute(buf)); let capacity = s.capacity(); match s.find('\0') { Some(index) => s.as_mut_vec().set_len(index as usize), None => s.as_mut_vec().set_len(capacity), } ret } } pub fn wmove(w: WINDOW, y: i32, x: i32) -> i32 { unsafe { ll::wmove(w, y, x) } } pub fn wnoutrefresh(w: WINDOW) -> i32 { unsafe { ll::wnoutrefresh(w) } } pub fn wprintw(w: WINDOW, s: &str) -> i32 { unsafe { ll::wprintw(w, s.to_c_str().as_ptr()) } } pub fn wredrawln(w: WINDOW, start: i32, n: i32) -> i32 { unsafe { ll::wredrawln(w, start, n) } } pub fn wrefresh(w: WINDOW) -> i32 { unsafe { ll::wrefresh(w) } } pub fn wresize(w: WINDOW, lines: i32, cols: i32) -> i32 { unsafe { ll::wresize(w, lines, cols) } } pub fn wscrl(w: WINDOW, n: i32) -> i32 { unsafe { ll::wscrl(w, n) } } pub fn wsetscrreg(w: WINDOW, top: i32, bot: i32) -> i32 { unsafe { ll::wsetscrreg(w, top, bot) } } pub fn wstandout(w: WINDOW) -> i32 { unsafe { ll::wstandout(w) } } pub fn wstandend(w: WINDOW) -> i32 { unsafe { ll::wstandend(w) } } pub fn wsyncdown(w: WINDOW) { unsafe { ll::wsyncdown(w) } } pub fn wsyncup(w: WINDOW) { unsafe { ll::wsyncup(w) } } pub fn wtimeout(w: WINDOW, delay: i32) { unsafe { ll::wtimeout(w, delay) } } pub fn wtouchln(w: WINDOW, y: i32, n: i32, changed: i32) -> i32 { unsafe { ll::wtouchln(w, y, n, changed) } } pub fn wvline(w: WINDOW, ch: chtype, n: i32) -> i32 { unsafe { ll::wvline(w, ch, n) } } pub fn wgetparent(w: WINDOW) -> WINDOW { unsafe { ll::wgetparent(w) } } pub fn wgetscrreg(w: WINDOW, top: &mut i32, bot: &mut i32) -> i32 { unsafe { ll::wgetscrreg(w, &mut*top as *mut i32, &mut*bot as *mut i32) } } /* Attributes */ pub const fn NCURSES_BITS(mask: u32, shift: u32) -> u32 { mask << (shift + NCURSES_ATTR_SHIFT) as usize } pub const fn A_NORMAL() -> attr_t { (1u32 - 1u32) as attr_t } pub const fn A_ATTRIBUTES() -> attr_t { NCURSES_BITS(!(1u32 - 1u32), 0u32) as attr_t } pub const fn A_CHARTEXT() -> attr_t {(NCURSES_BITS(1u32, 0u32) - 1u32) as attr_t } pub const fn A_COLOR() -> attr_t { NCURSES_BITS(((1u32) << 8) - 1u32, 0u32) as attr_t } pub const fn A_STANDOUT() -> attr_t { NCURSES_BITS(1u32, 8u32) as attr_t } pub const fn A_UNDERLINE() -> attr_t { NCURSES_BITS(1u32, 9u32) as attr_t } pub const fn A_REVERSE() -> attr_t { NCURSES_BITS(1u32, 10u32) as attr_t } pub const fn A_BLINK() -> attr_t { NCURSES_BITS(1u32, 11u32) as attr_t } pub const fn A_DIM() -> attr_t { NCURSES_BITS(1u32, 12u32) as attr_t } pub const fn A_BOLD() -> attr_t { NCURSES_BITS(1u32, 13u32) as attr_t } pub const fn A_ALTCHARSET() -> attr_t { NCURSES_BITS(1u32, 14u32) as attr_t } pub const fn A_INVIS() -> attr_t { NCURSES_BITS(1u32, 15u32) as attr_t } pub const fn A_PROTECT() -> attr_t { NCURSES_BITS(1u32, 16u32) as attr_t } pub const fn A_HORIZONTAL() -> attr_t { NCURSES_BITS(1u32, 17u32) as attr_t } pub const fn A_LEFT() -> attr_t { NCURSES_BITS(1u32, 18u32) as attr_t } pub const fn A_LOW() -> attr_t { NCURSES_BITS(1u32, 19u32) as attr_t } pub const fn A_RIGHT() -> attr_t { NCURSES_BITS(1u32, 20u32) as attr_t } pub const fn A_TOP() -> attr_t { NCURSES_BITS(1u32, 21u32) as attr_t } pub const fn A_VERTICAL() -> attr_t { NCURSES_BITS(1u32, 22u32) as attr_t } pub const fn A_ITALIC() -> attr_t { NCURSES_BITS(1u32, 23u32) as attr_t } /* Colors. */ pub fn COLOR_PAIR(n: i16) -> attr_t { NCURSES_BITS(n as u32, 0u32) as attr_t } /* * Most of the pseudo functions are macros that either provide compatibility * with older versions of curses, or provide inline functionality to improve * performance. */ pub fn getyx(win: WINDOW, y: &mut i32, x: &mut i32) { unsafe { *y = ll::getcury(win); *x = ll::getcurx(win); } } pub fn getbegyx(win: WINDOW, y: &mut i32, x: &mut i32) { unsafe { *y = ll::getbegy(win); *x = ll::getbegx(win) } } pub fn getmaxyx(win: WINDOW, y: &mut i32, x: &mut i32) { unsafe { *y = ll::getmaxy(win); *x = ll::getmaxx(win) } } pub fn getparyx(win: WINDOW, y: &mut i32, x: &mut i32) { unsafe { *y = ll::getpary(win); *x = ll::getparx(win) } } pub fn getsyx(y: &mut i32, x: &mut i32) { unsafe { if newscr() != ptr::null_mut() { if ll::is_leaveok(newscr()) == TRUE { *x = -1 as i32; *y = -1 as i32; } else { getyx(newscr(), y, x); } } } } pub fn setsyx(y: &mut i32, x: &mut i32) { unsafe { if newscr() !=(0 as WINDOW) { if *y == -1 && *x == -1 { ll::leaveok(newscr(), 1); } else { ll::leaveok(newscr(), 0); ll::wmove(newscr(), *y, *x); } } } } /* Line graphics */ pub fn NCURSES_ACS(c: char) -> chtype { unsafe { *acs_map().offset((c as libc::c_uchar) as isize) as chtype } } /* VT100 symbols begin here */ pub fn ACS_ULCORNER() -> chtype { NCURSES_ACS('l') } /* upper left corner */ pub fn ACS_LLCORNER() -> chtype { NCURSES_ACS('m') } /* lower left corner */ pub fn ACS_URCORNER() -> chtype { NCURSES_ACS('k') } /* upper right corner */ pub fn ACS_LRCORNER() -> chtype { NCURSES_ACS('j') } /* lower right corner */ pub fn ACS_LTEE() -> chtype { NCURSES_ACS('t') } /* tee pointing right */ pub fn ACS_RTEE() -> chtype { NCURSES_ACS('u') } /* tee pointing left */ pub fn ACS_BTEE() -> chtype { NCURSES_ACS('v') } /* tee pointing up */ pub fn ACS_TTEE() -> chtype { NCURSES_ACS('w') } /* tee pointing down */ pub fn ACS_HLINE() -> chtype { NCURSES_ACS('q') } /* horizontal line */ pub fn ACS_VLINE() -> chtype { NCURSES_ACS('x') } /* vertical line */ pub fn ACS_PLUS() -> chtype { NCURSES_ACS('n') } /* large plus or crossover */ pub fn ACS_S1() -> chtype { NCURSES_ACS('o') } /* scan line 1 */ pub fn ACS_S9() -> chtype { NCURSES_ACS('s') } /* scan line 9 */ pub fn ACS_DIAMOND() -> chtype { NCURSES_ACS('`') } /* diamond */ pub fn ACS_CKBOARD() -> chtype { NCURSES_ACS('a') } /* checker board(stipple) */ pub fn ACS_DEGREE() -> chtype { NCURSES_ACS('f') } /* degree symbol */ pub fn ACS_PLMINUS() -> chtype { NCURSES_ACS('g') } /* plus/minus */ pub fn ACS_BULLET() -> chtype { NCURSES_ACS('~') } /* bullet */ /* Teletype 5410v1 symbols begin here */ pub fn ACS_LARROW() -> chtype { NCURSES_ACS(',') } /* arrow pointing left */ pub fn ACS_RARROW() -> chtype { NCURSES_ACS('+') } /* arrow pointing right */ pub fn ACS_DARROW() -> chtype { NCURSES_ACS('.') } /* arrow pointing down */ pub fn ACS_UARROW() -> chtype { NCURSES_ACS('-') } /* arrow pointing up */ pub fn ACS_BOARD() -> chtype { NCURSES_ACS('h') } /* board of squares */ pub fn ACS_LANTERN() -> chtype { NCURSES_ACS('i') } /* lantern symbol */ pub fn ACS_BLOCK() -> chtype { NCURSES_ACS('0') } /* solid square block */ /* * These aren't documented, but a lot of System Vs have them anyway * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). * The ACS_names may not match AT&T's, our source didn't know them. */ pub fn ACS_S3() -> chtype { NCURSES_ACS('p') } /* scan line 3 */ pub fn ACS_S7() -> chtype { NCURSES_ACS('r') } /* scan line 7 */ pub fn ACS_LEQUAL() -> chtype { NCURSES_ACS('y') } /* less/equal */ pub fn ACS_GEQUAL() -> chtype { NCURSES_ACS('z') } /* greater/equal */ pub fn ACS_PI() -> chtype { NCURSES_ACS('{') } /* Pi */ pub fn ACS_NEQUAL() -> chtype { NCURSES_ACS('|') } /* not equal */ pub fn ACS_STERLING() -> chtype { NCURSES_ACS('}') } /* UK pound sign */ /* * Line drawing ACS names are of the form ACS_trbl, where t is the top, r * is the right, b is the bottom, and l is the left. t, r, b, and l might * be B(blank), S(single), D(double), or T(thick). The subset defined * here only uses B and S. */ pub fn ACS_BSSB() -> chtype { ACS_ULCORNER() } pub fn ACS_SSBB() -> chtype { ACS_LLCORNER() } pub fn ACS_BBSS() -> chtype { ACS_URCORNER() } pub fn ACS_SBBS() -> chtype { ACS_LRCORNER() } pub fn ACS_SBSS() -> chtype { ACS_RTEE() } pub fn ACS_SSSB() -> chtype { ACS_LTEE() } pub fn ACS_SSBS() -> chtype { ACS_BTEE() } pub fn ACS_BSSS() -> chtype { ACS_TTEE() } pub fn ACS_BSBS() -> chtype { ACS_HLINE() } pub fn ACS_SBSB() -> chtype { ACS_VLINE() } pub fn ACS_SSSS() -> chtype { ACS_PLUS() } pub fn KEY_F(n: u8) -> i32 { assert!(n < 16); KEY_F0 + n as i32 } /* * Added mouse support */ pub fn has_mouse() -> bool { unsafe { ll::has_mouse() == TRUE } } pub fn getmouse(event: *mut MEVENT) -> i32 { unsafe { ll::getmouse(event) } } pub fn ungetmouse(event: *mut MEVENT) -> i32 { unsafe { ll::ungetmouse(event) } } pub fn mouseinterval(n: i32) -> i32 { unsafe { ll::mouseinterval(n) } } pub fn mousemask(newmask: mmask_t, oldmask: Option<&mut mmask_t>) -> mmask_t { if oldmask.is_none() { unsafe { ll::mousemask(newmask, ptr::null_mut()) } } else { unsafe { ll::mousemask(newmask, oldmask.unwrap()) } } } pub fn wenclose(w: WINDOW, y: i32, x: i32) -> bool { unsafe { ll::wenclose(w, y as libc::c_int, x as libc::c_int) == TRUE } } pub fn wmouse_trafo(w: WINDOW, y: &mut[i32], x: &mut[i32], to_screen: bool) -> bool { unsafe { ll::wmouse_trafo(w, y.as_mut_ptr(), x.as_mut_ptr(), to_screen as ll::c_bool) == TRUE } } pub fn mouse_trafo(y: &mut[i32], x: &mut[i32], to_screen: bool) -> bool { unsafe { ll::mouse_trafo(y.as_mut_ptr(), x.as_mut_ptr(), to_screen as ll::c_bool) == TRUE } } #[cfg(feature = "extended_colors")] pub fn init_extended_color(color: i32, r: i32, g: i32, b: i32) -> i32 { unsafe { ll::init_extended_color(color, r, g, b) } } #[cfg(feature = "extended_colors")] pub fn init_extended_pair(color: i32, f: i32, b: i32) -> i32 { unsafe { ll::init_extended_pair(color, f, b) } } #[cfg(feature = "extended_colors")] pub fn extended_color_content(color: i32, r: &mut i32, g: &mut i32, b: &mut i32) -> i32 { unsafe { ll::extended_color_content(color, r, g, b) } } #[cfg(feature = "extended_colors")] pub fn extended_pair_content(pair: i32, f: &mut i32, b: &mut i32) -> i32 { unsafe { ll::extended_pair_content(pair, f, b) } } ncurses-5.99.0/src/ll.rs010064400017500000144000000415401340774735400133030ustar0000000000000000#![allow(dead_code)] #![allow(unused_imports)] /* Copyright © 2013 Free Software Foundation, Inc See licensing in LICENSE file File: ll.rs Author: Jesse 'Jeaye' Wilkerson Description: Low-level interface to foreign ncurses functions. */ use libc::{ c_char, c_int, c_short, c_uint, c_ulong, c_void, FILE }; pub type c_bool = ::libc::c_uchar; /* Intrinsic types. */ #[cfg(feature="wide_chtype")] pub type chtype = u64; #[cfg(not(feature="wide_chtype"))] pub type chtype = u32; pub type winttype = c_uint; pub type mmask_t = chtype; pub type attr_t = chtype; pub type NCURSES_ATTR_T = attr_t; /* Pointer types. */ pub type attr_t_p = *mut attr_t; pub type short_p = *mut c_short; pub type int_p = *mut c_int; pub type void_p = *const c_void; pub type char_p = *const c_char; pub type chtype_p = *const chtype; pub type WINDOW = *mut i8; pub type SCREEN = *mut i8; pub type FILE_p = *mut FILE; pub type va_list = *mut u8; /* Custom Types. */ #[repr(C)] #[derive(Debug, Clone, Copy)] pub struct MEVENT { pub id: c_short, pub x: c_int, pub y: c_int, pub z: c_int, pub bstate: mmask_t} extern { pub fn addch(_:chtype) -> c_int; pub fn addchnstr(_:*const chtype, _:c_int) -> c_int; pub fn addchstr(_:*const chtype) -> c_int; pub fn addnstr(_:*const c_char, _:c_int) -> c_int; pub fn addstr(_:*const c_char) -> c_int; pub fn assume_default_colors(_:c_int, _:c_int) -> c_int; pub fn attroff(_:NCURSES_ATTR_T) -> c_int; pub fn attron(_:NCURSES_ATTR_T) -> c_int; pub fn attrset(_:NCURSES_ATTR_T) -> c_int; pub fn attr_get(_:attr_t_p, _:short_p, _:void_p) -> c_int; pub fn attr_off(_:attr_t, _:void_p) -> c_int; pub fn attr_on(_:attr_t, _:void_p) -> c_int; pub fn attr_set(_:attr_t, _:c_short, _:void_p) -> c_int; pub fn baudrate() -> c_int; pub fn beep() -> c_int; pub fn bkgd(_:chtype) -> c_int; pub fn bkgdset(_:chtype); pub fn border(_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype) -> c_int; pub fn box_(_:WINDOW, _:chtype, _:chtype) -> c_int; pub fn can_change_color() -> c_bool; pub fn cbreak() -> c_int; pub fn chgat(_:c_int, _:attr_t, _:c_short, _:void_p) -> c_int; pub fn clear() -> c_int; pub fn clearok(_:WINDOW,_:c_bool) -> c_int; pub fn clrtobot() -> c_int; pub fn clrtoeol() -> c_int; pub fn color_content(_:c_short,_:short_p,_:short_p,_:short_p) -> c_int; pub fn color_set(_:c_short,_:void_p) -> c_int; pub fn COLOR_PAIR(_:c_int) -> c_int; pub fn copywin(_:WINDOW,_:WINDOW,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int) -> c_int; pub fn curs_set(_:c_int) -> c_int; pub fn def_prog_mode() -> c_int; pub fn def_shell_mode() -> c_int; pub fn delay_output(_:c_int) -> c_int; pub fn delch() -> c_int; pub fn delscreen(_:SCREEN); pub fn delwin(_:WINDOW) -> c_int; pub fn deleteln() -> c_int; pub fn derwin(_:WINDOW,_:c_int,_:c_int,_:c_int,_:c_int) -> WINDOW; pub fn doupdate() -> c_int; pub fn dupwin(_:WINDOW) -> WINDOW; pub fn echo() -> c_int; pub fn echochar(_:chtype) -> c_int; pub fn erase() -> c_int; pub fn endwin() -> c_int; pub fn erasechar() -> c_char; pub fn filter(); pub fn flash() -> c_int; pub fn flushinp() -> c_int; pub fn getbkgd(_:WINDOW) -> chtype; pub fn getch() -> c_int; pub fn getnstr(_:*mut c_char, _:c_int) -> c_int; pub fn getstr(_:char_p) -> c_int; pub fn getwin(_:FILE_p) -> WINDOW; pub fn halfdelay(_:c_int) -> c_int; pub fn has_colors() -> c_bool; pub fn has_ic() -> c_bool; pub fn has_il() -> c_bool; pub fn hline(_:chtype, _:c_int) -> c_int; pub fn idcok(_:WINDOW, _:c_bool); pub fn idlok(_:WINDOW, _:c_bool) -> c_int; pub fn immedok(_:WINDOW, _:c_bool); pub fn inch() -> chtype; pub fn inchnstr(_:chtype_p, _:c_int) -> c_int; pub fn inchstr(_:chtype_p) -> c_int; pub fn initscr() -> WINDOW; pub fn init_color(_:c_short,_:c_short,_:c_short,_:c_short) -> c_int; pub fn init_pair(_:c_short,_:c_short,_:c_short) -> c_int; pub fn innstr(_:char_p, _:c_int) -> c_int; pub fn insch(_:chtype) -> c_int; pub fn insdelln(_:c_int) -> c_int; pub fn insertln() -> c_int; pub fn insnstr(_:char_p, _:c_int) -> c_int; pub fn insstr(_:char_p) -> c_int; pub fn instr(_:char_p) -> c_int; pub fn intrflush(_:WINDOW,_:c_bool) -> c_int; pub fn isendwin() -> c_bool; pub fn is_linetouched(_:WINDOW,_:c_int) -> c_bool; pub fn is_term_resized(_:c_int, _:c_int) -> c_bool; pub fn is_wintouched(_:WINDOW) -> c_bool; pub fn keyname(_:c_int) -> *const c_char; pub fn keypad(_:WINDOW, _:c_bool) -> c_int; pub fn killchar() -> c_char; pub fn leaveok(_:WINDOW,_:c_bool) -> c_int; pub fn longname() -> *mut c_char; pub fn meta(_:WINDOW,_:c_bool) -> c_int; #[link_name = "move"] pub fn mv(_:c_int, _:c_int) -> c_int; pub fn mvaddch(_:c_int, _:c_int, _:chtype) -> c_int; pub fn mvaddchnstr(_:c_int, _:c_int, _:chtype_p, _:c_int) -> c_int; pub fn mvaddchstr(_:c_int, _:c_int, _:chtype_p) -> c_int; pub fn mvaddnstr(_:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvaddstr(_:c_int, _:c_int, _:char_p) -> c_int; pub fn mvchgat(_:c_int, _:c_int, _:c_int, _:attr_t, _:c_short, _:void_p) -> c_int; pub fn mvcur(_:c_int,_:c_int,_:c_int,_:c_int) -> c_int; pub fn mvdelch(_:c_int, _:c_int) -> c_int; pub fn mvderwin(_:WINDOW, _:c_int, _:c_int) -> c_int; pub fn mvgetch(_:c_int, _:c_int) -> c_int; pub fn mvgetnstr(_:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvgetstr(_:c_int, _:c_int, _:char_p) -> c_int; pub fn mvhline(_:c_int, _:c_int, _:chtype, _:c_int) -> c_int; pub fn mvinch(_:c_int, _:c_int) -> chtype; pub fn mvinchnstr(_:c_int, _:c_int, _:chtype_p, _:c_int) -> c_int; pub fn mvinchstr(_:c_int, _:c_int, _:chtype_p) -> c_int; pub fn mvinnstr(_:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvinsch(_:c_int, _:c_int, _:chtype) -> c_int; pub fn mvinsnstr(_:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvinsstr(_:c_int, _:c_int, _:char_p) -> c_int; pub fn mvinstr(_:c_int, _:c_int, _:char_p) -> c_int; pub fn mvprintw(_:c_int, _:c_int, _:char_p) -> c_int; // fn mvscanw(_:c_int,_:c_int, _:char_p) -> c_int; pub fn mvvline(_:c_int, _:c_int, _:chtype, _:c_int) -> c_int; pub fn mvwaddch(_:WINDOW, _:c_int, _:c_int, _:chtype) -> c_int; pub fn mvwaddchnstr(_:WINDOW, _:c_int, _:c_int, _:chtype_p, _:c_int) -> c_int; pub fn mvwaddchstr(_:WINDOW, _:c_int, _:c_int, _:chtype_p) -> c_int; pub fn mvwaddnstr(_:WINDOW, _:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvwaddstr(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; pub fn mvwchgat(_:WINDOW, _:c_int, _:c_int, _:c_int, _:attr_t, _:c_short, _:void_p) -> c_int; pub fn mvwdelch(_:WINDOW, _:c_int, _:c_int) -> c_int; pub fn mvwgetch(_:WINDOW, _:c_int, _:c_int) -> c_int; pub fn mvwgetnstr(_:WINDOW, _:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvwgetstr(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; pub fn mvwhline(_:WINDOW, _:c_int, _:c_int, _:chtype, _:c_int) -> c_int; pub fn mvwin(_:WINDOW,_:c_int,_:c_int) -> c_int; pub fn mvwinch(_:WINDOW, _:c_int, _:c_int) -> chtype; pub fn mvwinchnstr(_:WINDOW, _:c_int, _:c_int, _:chtype_p, _:c_int) -> c_int; pub fn mvwinchstr(_:WINDOW, _:c_int, _:c_int, _:chtype_p) -> c_int; pub fn mvwinnstr(_:WINDOW, _:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvwinsch(_:WINDOW, _:c_int, _:c_int, _:chtype) -> c_int; pub fn mvwinsnstr(_:WINDOW, _:c_int, _:c_int, _:char_p, _:c_int) -> c_int; pub fn mvwinsstr(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; pub fn mvwinstr(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; pub fn mvwprintw(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; // fn mvwscanw(_:WINDOW, _:c_int, _:c_int, _:char_p) -> c_int; pub fn mvwvline(_:WINDOW, _:c_int, _:c_int, _:chtype, _:c_int) -> c_int; pub fn napms(_:c_int) -> c_int; pub fn newpad(_:c_int,_:c_int) -> WINDOW; pub fn newterm(_:char_p,_:FILE_p,_:FILE_p) -> SCREEN; pub fn newwin(_:c_int,_:c_int,_:c_int,_:c_int) -> WINDOW; pub fn nl() -> c_int; pub fn nocbreak() -> c_int; pub fn nodelay(_:WINDOW,_:c_bool) -> c_int; pub fn noecho() -> c_int; pub fn nonl() -> c_int; pub fn noqiflush(); pub fn noraw() -> c_int; pub fn notimeout(_:WINDOW,_:c_bool) -> c_int; pub fn overlay(_:WINDOW,_:WINDOW) -> c_int; pub fn overwrite(_:WINDOW,_:WINDOW) -> c_int; pub fn pair_content(_:c_short,_:short_p,_:short_p) -> c_int; pub fn PAIR_NUMBER(_:c_int) -> c_int; pub fn pechochar(_:WINDOW, _:chtype) -> c_int; pub fn pnoutrefresh(_:WINDOW,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int) -> c_int; pub fn prefresh(_:WINDOW,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int,_:c_int) -> c_int; pub fn printw(_:char_p) -> c_int; pub fn putwin(_:WINDOW, _:FILE_p) -> c_int; pub fn qiflush(); pub fn raw() -> c_int; pub fn redrawwin(_:WINDOW) -> c_int; pub fn refresh() -> c_int; pub fn resizeterm(_:c_int, _:c_int) -> c_int; pub fn resize_term(_:c_int, _:c_int) -> c_int; pub fn resetty() -> c_int; pub fn reset_prog_mode() -> c_int; pub fn reset_shell_mode() -> c_int; // fn ripoffline(_:c_int, extern fn f(WINDOW, c_int) -> c_int) -> c_int; pub fn savetty() -> c_int; // fn scanw(_:NCURSES_CONST char_p,...) -> c_int; pub fn scr_dump(_:char_p) -> c_int; pub fn scr_init(_:char_p) -> c_int; pub fn scrl(_:c_int) -> c_int; pub fn scroll(_:WINDOW) -> c_int; pub fn scrollok(_:WINDOW,_:c_bool) -> c_int; pub fn scr_restore(_:char_p) -> c_int; pub fn scr_set(_:char_p) -> c_int; pub fn setlocale(_:c_int, _:char_p) -> char_p; pub fn setscrreg(_:c_int,_:c_int) -> c_int; pub fn set_term(_:SCREEN) -> SCREEN; pub fn set_escdelay(_:c_int) -> c_int; pub fn set_tabsize(_:c_int) -> c_int; pub fn slk_attroff(_:chtype) -> c_int; pub fn slk_attr_off(_:attr_t, _:void_p) -> c_int; pub fn slk_attron(_:chtype) -> c_int; pub fn slk_attr_on(_:attr_t,_:void_p) -> c_int; pub fn slk_attrset(_:chtype) -> c_int; pub fn slk_attr() -> attr_t; pub fn slk_attr_set(_:attr_t,_:c_short,_:void_p) -> c_int; pub fn slk_clear() -> c_int; pub fn slk_color(_:c_short) -> c_int; pub fn slk_init(_:c_int) -> c_int; pub fn slk_label(_:c_int) -> char_p; pub fn slk_noutrefresh() -> c_int; pub fn slk_refresh() -> c_int; pub fn slk_restore() -> c_int; pub fn slk_set(_:c_int,_:char_p,_:c_int) -> c_int; pub fn slk_touch() -> c_int; pub fn standout() -> c_int; pub fn standend() -> c_int; pub fn start_color() -> c_int; pub fn subpad(_:WINDOW, _:c_int, _:c_int, _:c_int, _:c_int) -> WINDOW; pub fn subwin(_:WINDOW, _:c_int, _:c_int, _:c_int, _:c_int) -> WINDOW; pub fn syncok(_:WINDOW, _:c_bool) -> c_int; pub fn termattrs() -> chtype; pub fn termname() -> char_p; pub fn timeout(_:c_int); pub fn touchline(_:WINDOW, _:c_int, _:c_int) -> c_int; pub fn touchwin(_:WINDOW) -> c_int; pub fn typeahead(_:c_int) -> c_int; pub fn ungetch(_:c_int) -> c_int; pub fn untouchwin(_:WINDOW) -> c_int; pub fn use_env(_:c_bool); pub fn use_default_colors() -> c_int; pub fn vidattr(_:chtype) -> c_int; // fn vidputs(_:chtype, extern fn f(c_int) -> c_int) -> c_int; //pub fn vidputs(_:chtype, f:*mut c_char) -> c_int; pub fn vline(_:chtype, _:c_int) -> c_int; pub fn vwprintw(_:WINDOW, _:char_p, _:va_list) -> c_int; pub fn vw_printw(_:WINDOW, _:char_p,_:va_list) -> c_int; // fn vwscanw(_:WINDOW, _:char_p, _:va_list) -> c_int; // fn vw_scanw(_:WINDOW, _:char_p, _:va_list) -> c_int; pub fn waddch(_:WINDOW, _:chtype) -> c_int; pub fn waddchnstr(_:WINDOW,_:chtype_p,_:c_int) -> c_int; pub fn waddchstr(_:WINDOW,_:chtype_p) -> c_int; pub fn waddnstr(_:WINDOW,_:char_p,_:c_int) -> c_int; pub fn waddstr(_:WINDOW,_:char_p) -> c_int; pub fn wattron(_:WINDOW, _:NCURSES_ATTR_T) -> c_int; pub fn wattroff(_:WINDOW, _:NCURSES_ATTR_T) -> c_int; pub fn wattrset(_:WINDOW, _:NCURSES_ATTR_T) -> c_int; pub fn wattr_get(_:WINDOW, _:attr_t_p, _:short_p, _:void_p) -> c_int; pub fn wattr_on(_:WINDOW, _:attr_t, _:void_p) -> c_int; pub fn wattr_off(_:WINDOW, _:attr_t, _:void_p) -> c_int; pub fn wattr_set(_:WINDOW, _:attr_t, _:c_short, _:void_p) -> c_int; pub fn wbkgd(_:WINDOW, _:chtype) -> c_int; pub fn wbkgdset(_:WINDOW,_:chtype); pub fn wborder(_:WINDOW,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype,_:chtype) -> c_int; pub fn wchgat(_:WINDOW, _:c_int, _:attr_t, _:c_short, _:void_p) -> c_int; pub fn wclear(_:WINDOW) -> c_int; pub fn wclrtobot(_:WINDOW) -> c_int; pub fn wclrtoeol(_:WINDOW) -> c_int; pub fn wcolor_set(_:WINDOW,_:c_short,_:void_p) -> c_int; pub fn wcursyncup(_:WINDOW); pub fn wdelch(_:WINDOW) -> c_int; pub fn wdeleteln(_:WINDOW) -> c_int; pub fn wechochar(_:WINDOW, _:chtype) -> c_int; pub fn werase(_:WINDOW) -> c_int; pub fn wgetch(_:WINDOW) -> c_int; pub fn wget_wch(_:WINDOW, _:*mut winttype) -> c_int; pub fn mvwget_wch(_:WINDOW, _:c_int, _:c_int, _:*mut winttype) -> c_int; pub fn mvget_wch(_:c_int, _: c_int, _:*mut winttype) -> c_int; pub fn get_wch(_:*mut winttype) -> c_int; pub fn unget_wch(_:winttype) -> c_int; pub fn wgetnstr(_:WINDOW,_:*const u8,_:c_int) -> c_int; pub fn wgetstr(_:WINDOW, _:char_p) -> c_int; pub fn whline(_:WINDOW, _:chtype, _:c_int) -> c_int; pub fn winch(_:WINDOW) -> chtype; pub fn winchnstr(_:WINDOW, _:chtype_p, _:c_int) -> c_int; pub fn winchstr(_:WINDOW, _:chtype_p) -> c_int; pub fn winnstr(_:WINDOW, _:char_p, _:c_int) -> c_int; pub fn winsch(_:WINDOW, _:chtype) -> c_int; pub fn winsdelln(_:WINDOW,_:c_int) -> c_int; pub fn winsertln(_:WINDOW) -> c_int; pub fn winsnstr(_:WINDOW, _:char_p,_:c_int) -> c_int; pub fn winsstr(_:WINDOW, _:char_p) -> c_int; pub fn winstr(_:WINDOW, _:char_p) -> c_int; pub fn wmove(_:WINDOW,_:c_int,_:c_int) -> c_int; pub fn wnoutrefresh(_:WINDOW) -> c_int; pub fn wprintw(_:WINDOW, _:char_p) -> c_int; pub fn wredrawln(_:WINDOW,_:c_int,_:c_int) -> c_int; pub fn wrefresh(_:WINDOW) -> c_int; pub fn wresize(_:WINDOW, _:c_int, _:c_int) -> c_int; // fn wscanw(_:WINDOW, _:NCURSES_CONST char_p) -> c_int; pub fn wscrl(_:WINDOW,_:c_int) -> c_int; pub fn wsetscrreg(_:WINDOW,_:c_int,_:c_int) -> c_int; pub fn wstandout(_:WINDOW) -> c_int; pub fn wstandend(_:WINDOW) -> c_int; pub fn wsyncdown(_:WINDOW); pub fn wsyncup(_:WINDOW); pub fn wtimeout(_:WINDOW,_:c_int); pub fn wtouchln(_:WINDOW,_:c_int,_:c_int,_:c_int) -> c_int; pub fn wvline(_:WINDOW,_:chtype,_:c_int) -> c_int; /* * These are also declared in : */ pub fn tigetflag(_:char_p) -> c_int; pub fn tigetnum(_:char_p) -> c_int; pub fn tigetstr(_:char_p) -> *mut c_char; pub fn putp(_:char_p) -> c_int; pub fn tparm(_:char_p) -> *mut c_char; /* * These functions are not in X/Open, but we use them in macro definitions: */ pub fn getattrs(_:WINDOW) -> c_int; pub fn getcurx(_:WINDOW) -> c_int; pub fn getcury(_:WINDOW) -> c_int; pub fn getbegx(_:WINDOW) -> c_int; pub fn getbegy(_:WINDOW) -> c_int; pub fn getmaxx(_:WINDOW) -> c_int; pub fn getmaxy(_:WINDOW) -> c_int; pub fn getparx(_:WINDOW) -> c_int; pub fn getpary(_:WINDOW) -> c_int; /* * These extensions provide access to information stored in the WINDOW even * when NCURSES_OPAQUE is set: */ pub fn wgetparent(_:WINDOW) -> WINDOW; pub fn is_cleared(_:WINDOW) -> c_bool; pub fn is_idcok(_:WINDOW) -> c_bool; pub fn is_idlok(_:WINDOW) -> c_bool; pub fn is_immedok(_:WINDOW) -> c_bool; pub fn is_keypad(_:WINDOW) -> c_bool; pub fn is_leaveok(_:WINDOW) -> c_bool; pub fn is_nodelay(_:WINDOW) -> c_bool; pub fn is_notimeout(_:WINDOW) -> c_bool; pub fn is_scrollok(_:WINDOW) -> c_bool; pub fn is_syncok(_:WINDOW) -> c_bool; pub fn wgetscrreg(_:WINDOW, _:*mut c_int, _:*mut c_int) -> c_int; /* * Added mouse support */ pub fn has_mouse() -> c_bool; pub fn getmouse(_:*mut MEVENT) -> c_int; pub fn ungetmouse(_:*mut MEVENT) -> c_int; pub fn mousemask(_:mmask_t,_:*mut mmask_t) -> mmask_t; pub fn wenclose(_:WINDOW,_:c_int,_:c_int) -> c_bool; pub fn mouseinterval(_:c_int) -> c_int; pub fn wmouse_trafo(_:WINDOW,_:*mut c_int,_:*mut c_int,_:c_bool) -> c_bool; pub fn mouse_trafo(_:*mut c_int,_:*mut c_int,_:c_bool) -> c_bool; } /// Extended color support. Requires ncurses6. #[cfg(feature = "extended_colors")] extern { pub fn init_extended_color(_: c_int, _: c_int, _: c_int, _: c_int) -> c_int; pub fn init_extended_pair(_: c_int, _: c_int, _: c_int) -> c_int; pub fn extended_color_content(_: c_int, _: int_p, _: int_p, _: int_p) -> c_int; pub fn extended_pair_content(_: c_int, _: int_p, _: int_p) -> c_int; } ncurses-5.99.0/src/menu/constants.rs010064400017500000144000000021551270033604400156340ustar0000000000000000use constants::KEY_MAX; pub const O_ONEVALUE: i32 = 0x01; pub const O_SHOWDESC: i32 = 0x02; pub const O_ROWMAJOR: i32 = 0x04; pub const O_IGNORECASE: i32 = 0x08; pub const O_SHOWMATCH: i32 = 0x10; pub const O_NONCYCLIC: i32 = 0x20; pub const O_SELECTABLE: i32 = 0x01; pub const REQ_LEFT_ITEM: i32 = KEY_MAX + 1; pub const REQ_RIGHT_ITEM: i32 = KEY_MAX + 2; pub const REQ_UP_ITEM: i32 = KEY_MAX + 3; pub const REQ_DOWN_ITEM: i32 = KEY_MAX + 4; pub const REQ_SCR_ULINE: i32 = KEY_MAX + 5; pub const REQ_SCR_DLINE: i32 = KEY_MAX + 6; pub const REQ_SCR_DPAGE: i32 = KEY_MAX + 7; pub const REQ_SCR_UPAGE: i32 = KEY_MAX + 8; pub const REQ_FIRST_ITEM: i32 = KEY_MAX + 9; pub const REQ_LAST_ITEM: i32 = KEY_MAX + 10; pub const REQ_NEXT_ITEM: i32 = KEY_MAX + 11; pub const REQ_PREV_ITEM: i32 = KEY_MAX + 12; pub const REQ_TOGGLE_ITEM: i32 = KEY_MAX + 13; pub const REQ_CLEAR_PATTERN: i32 = KEY_MAX + 14; pub const REQ_BACK_PATTERN: i32 = KEY_MAX + 15; pub const REQ_NEXT_MATCH: i32 = KEY_MAX + 16; pub const REQ_PREV_MATCH: i32 = KEY_MAX + 17; pub const MIN_MENU_COMMAND: i32 = KEY_MAX + 1; pub const MAX_MENU_COMMAND: i32 = KEY_MAX + 17; ncurses-5.99.0/src/menu/ll.rs010064400017500000144000000061561330701501000142230ustar0000000000000000#![allow(dead_code)] #![allow(unused_imports)] use libc::{c_int, c_char, c_void}; use ll::{WINDOW, chtype, c_bool}; pub type MENU = *mut i8; pub type ITEM = *mut i8; pub type HOOK = Option; #[cfg(feature="menu")] extern { pub fn menu_items(_:MENU) -> *mut ITEM; pub fn current_item(_:MENU) -> ITEM; pub fn new_item(_:*const c_char, _:*const c_char) -> ITEM; pub fn free_item(_:ITEM); pub fn new_menu(_:*mut ITEM) -> MENU; pub fn item_opts(_:ITEM) -> c_int; pub fn menu_opts(_:MENU) -> c_int; pub fn item_init(_:MENU) -> HOOK; pub fn item_term(_:MENU) -> HOOK; pub fn menu_init(_:MENU) -> HOOK; pub fn menu_term(_:MENU) -> HOOK; pub fn menu_sub(_:MENU) -> WINDOW; pub fn menu_win(_:MENU) -> WINDOW; pub fn item_description(_:ITEM) -> *const c_char; pub fn item_name(_:ITEM) -> *const c_char; pub fn menu_mark(_:MENU) -> *const c_char; pub fn menu_request_name(_:c_int) -> *const c_char; pub fn menu_pattern(_:MENU) -> *mut c_char; pub fn menu_back(_:MENU) -> chtype; pub fn menu_fore(_:MENU) -> chtype; pub fn menu_grey(_:MENU) -> chtype; pub fn free_menu(_:MENU) -> c_int; pub fn item_count(_:MENU) -> c_int; pub fn item_index(_:ITEM) -> c_int; pub fn item_opts_off(_:ITEM, _:c_int) -> c_int; pub fn item_opts_on(_:ITEM, _:c_int) -> c_int; pub fn menu_driver(_:MENU, _:c_int) -> c_int; pub fn menu_opts_off(_:MENU, _:c_int) -> c_int; pub fn menu_opts_on(_:MENU, _:c_int) -> c_int; pub fn menu_pad(_:MENU) -> c_int; pub fn pos_menu_cursor(_:MENU) -> c_int; pub fn post_menu(_:MENU) -> c_int; pub fn scale_menu(_:MENU, _:*mut c_int, _:*mut c_int) -> c_int; pub fn set_current_item(_:MENU, _:ITEM) -> c_int; pub fn set_item_init(_:MENU, _:HOOK) -> c_int; pub fn set_item_opts(_:ITEM, _:c_int) -> c_int; pub fn set_item_term(_:MENU, _:HOOK) -> c_int; pub fn set_item_value(_:ITEM, _:c_bool) -> c_int; pub fn set_menu_back(_:MENU, _:chtype) -> c_int; pub fn set_menu_fore(_:MENU, _:chtype) -> c_int; pub fn set_menu_format(_:MENU, _:c_int, _:c_int) -> c_int; pub fn set_menu_grey(_:MENU, _:chtype) -> c_int; pub fn set_menu_init(_:MENU, _:HOOK) -> c_int; pub fn set_menu_items(_:MENU, _:*mut ITEM) -> c_int; pub fn set_menu_mark(_:MENU, _:*const c_char) -> c_int; pub fn set_menu_opts(_:MENU, _:c_int) -> c_int; pub fn set_menu_pad(_:MENU, _:c_int) -> c_int; pub fn set_menu_pattern(_:MENU, _:*const c_char) -> c_int; pub fn set_menu_sub(_:MENU, _:WINDOW) -> c_int; pub fn set_menu_term(_:MENU, _:HOOK) -> c_int; pub fn set_menu_win(_:MENU, _:WINDOW) -> c_int; pub fn set_top_row(_:MENU, _:c_int) -> c_int; pub fn top_row(_:MENU) -> c_int; pub fn unpost_menu(_:MENU) -> c_int; pub fn menu_request_by_name(_:*const c_char) -> c_int; pub fn set_menu_spacing(_:MENU, _:c_int, _:c_int, _:c_int) -> c_int; pub fn menu_spacing(_:MENU, _:*mut c_int, _:*mut c_int, _:*mut c_int) -> c_int; pub fn item_value(_:ITEM) -> c_bool; pub fn item_visible(_:ITEM) -> c_bool; pub fn menu_format(_:MENU, _:*mut c_int, _:*mut c_int); } ncurses-5.99.0/src/menu/mod.rs010064400017500000144000000000541270033604400143730ustar0000000000000000mod ll; pub mod wrapper; pub mod constants; ncurses-5.99.0/src/menu/wrapper.rs010064400017500000144000000216301320445217700153050ustar0000000000000000#![allow(dead_code)] #![allow(unused_imports)] use std::str; use std::ptr; use std::slice; use std::ffi::{CStr, CString}; use libc::*; use menu::ll; use ll::{WINDOW, chtype, c_bool}; use constants::TRUE; pub type MENU = ll::MENU; pub type ITEM = ll::ITEM; pub type HOOK = ll::HOOK; #[cfg(feature="menu")] pub fn menu_items(menu: MENU) -> Vec { unsafe { slice::from_raw_parts(super::ll::menu_items(menu), item_count(menu) as usize).to_vec() } } #[cfg(feature="menu")] pub fn current_item(menu: MENU) -> ITEM { unsafe { super::ll::current_item(menu) } } #[cfg(feature="menu")] pub fn new_item>>(name: T, description: T) -> ITEM { unsafe { super::ll::new_item(CString::new(name).unwrap().into_raw(), CString::new(description).unwrap().into_raw()) } } #[cfg(feature="menu")] pub fn new_menu(items: &mut Vec) -> MENU { unsafe { items.push(ptr::null_mut()); let menu = super::ll::new_menu(items.as_mut_ptr()); items.pop(); menu } } #[cfg(feature="menu")] pub fn item_opts(item: ITEM) -> i32 { unsafe { super::ll::item_opts(item) } } #[cfg(feature="menu")] pub fn menu_opts(menu: MENU) -> i32 { unsafe { super::ll::menu_opts(menu) } } #[cfg(feature="menu")] pub fn menu_sub(menu: MENU) -> WINDOW { unsafe { super::ll::menu_sub(menu) } } #[cfg(feature="menu")] pub fn item_init(menu: MENU) -> HOOK { unsafe { super::ll::item_init(menu) } } #[cfg(feature="menu")] pub fn item_term(menu: MENU) -> HOOK { unsafe { super::ll::item_term(menu) } } #[cfg(feature="menu")] pub fn menu_init(menu: MENU) -> HOOK { unsafe { super::ll::menu_init(menu) } } #[cfg(feature="menu")] pub fn menu_term(menu: MENU) -> HOOK { unsafe { super::ll::menu_term(menu) } } #[cfg(feature="menu")] pub fn menu_win(menu: MENU) -> WINDOW { unsafe { super::ll::menu_win(menu) } } #[cfg(feature="menu")] pub fn item_description(item: ITEM) -> String { unsafe { ptr_to_string(super::ll::item_description(item)) } } #[cfg(feature="menu")] pub fn item_name(item: ITEM) -> String { unsafe { ptr_to_string(super::ll::item_name(item)) } } #[cfg(feature="menu")] pub fn menu_mark(menu: MENU) -> String { unsafe { ptr_to_string(super::ll::menu_mark(menu)) } } #[cfg(feature="menu")] pub fn menu_request_name(request: i32) -> String { unsafe { ptr_to_string(super::ll::menu_request_name(request)) } } #[cfg(feature="menu")] pub fn menu_pattern(menu: MENU) -> String { unsafe { ptr_to_string(super::ll::menu_pattern(menu)) } } #[cfg(feature="menu")] pub fn menu_back(menu: MENU) -> chtype { unsafe { super::ll::menu_back(menu) } } #[cfg(feature="menu")] pub fn menu_fore(menu: MENU) -> chtype { unsafe { super::ll::menu_fore(menu) } } #[cfg(feature="menu")] pub fn menu_grey(menu: MENU) -> chtype { unsafe { super::ll::menu_grey(menu) } } #[cfg(feature="menu")] pub fn free_item(item: ITEM) { unsafe { let name = super::ll::item_name(item) as *mut i8; if name.is_null() == false { let _ = CString::from_raw(name); } let desc = super::ll::item_description(item) as *mut i8; if desc.is_null() == false { let _ = CString::from_raw(desc); } super::ll::free_item(item); } } #[cfg(feature="menu")] pub fn free_menu(menu: MENU) -> i32 { unsafe { super::ll::free_menu(menu) } } #[cfg(feature="menu")] pub fn item_count(menu: MENU) -> i32 { unsafe { super::ll::item_count(menu) } } #[cfg(feature="menu")] pub fn item_index(item: ITEM) -> i32 { unsafe { super::ll::item_index(item) } } #[cfg(feature="menu")] pub fn item_opts_off(item: ITEM, opts: i32) -> i32 { unsafe { super::ll::item_opts_off(item, opts) } } #[cfg(feature="menu")] pub fn item_opts_on(item: ITEM, opts: i32) -> i32 { unsafe { super::ll::item_opts_on(item, opts) } } #[cfg(feature="menu")] pub fn menu_driver(menu: MENU, c: i32) -> i32 { unsafe { super::ll::menu_driver(menu, c) } } #[cfg(feature="menu")] pub fn menu_opts_off(menu: MENU, opts: i32) -> i32 { unsafe { super::ll::menu_opts_off(menu, opts) } } #[cfg(feature="menu")] pub fn menuopts_on(menu: MENU, opts: i32) -> i32 { unsafe { super::ll::menu_opts_on(menu, opts) } } #[cfg(feature="menu")] pub fn menu_pad(menu: MENU) -> i32 { unsafe { super::ll::menu_pad(menu) } } #[cfg(feature="menu")] pub fn pos_menu_cursor(menu: MENU) -> i32 { unsafe { super::ll::pos_menu_cursor(menu) } } #[cfg(feature="menu")] pub fn post_menu(menu: MENU) -> i32 { unsafe { super::ll::post_menu(menu) } } #[cfg(feature="menu")] pub fn scale_menu(menu: MENU, rows: &mut i32, cols: &mut i32) -> i32 { unsafe { super::ll::scale_menu(menu, rows as *mut c_int, cols as *mut c_int) } } #[cfg(feature="menu")] pub fn set_current_item(menu: MENU, item: ITEM) -> i32 { unsafe { super::ll::set_current_item(menu, item) } } #[cfg(feature="menu")] pub fn set_item_init(menu: MENU, hook: HOOK) -> i32 { unsafe { super::ll::set_item_init(menu, hook) } } #[cfg(feature="menu")] pub fn set_item_opts(item: ITEM, opts: i32) -> i32 { unsafe { super::ll::set_item_opts(item, opts) } } #[cfg(feature="menu")] pub fn set_item_term(menu: MENU, hook: HOOK) -> i32 { unsafe { super::ll::set_item_term(menu, hook) } } #[cfg(feature="menu")] pub fn set_item_value(item: ITEM, value: bool) -> i32 { unsafe { super::ll::set_item_value(item, value as c_bool) } } #[cfg(feature="menu")] pub fn set_menu_back(menu: MENU, attr: chtype) -> i32 { unsafe { super::ll::set_menu_back(menu, attr) } } #[cfg(feature="menu")] pub fn set_menu_fore(menu: MENU, attr: chtype) -> i32 { unsafe { super::ll::set_menu_fore(menu, attr) } } #[cfg(feature="menu")] pub fn set_menu_grey(menu: MENU, attr: chtype) -> i32 { unsafe { super::ll::set_menu_grey(menu, attr) } } #[cfg(feature="menu")] pub fn set_menu_format(menu: MENU, rows: i32, cols: i32) -> i32 { unsafe { super::ll::set_menu_format(menu, rows, cols) } } #[cfg(feature="menu")] pub fn set_menu_init(menu: MENU, hook: HOOK) -> i32 { unsafe { super::ll::set_menu_init(menu, hook) } } #[cfg(feature="menu")] pub fn set_menu_items(menu: MENU, items: &mut Vec) -> i32 { unsafe { items.push(ptr::null_mut()); let ret = super::ll::set_menu_items(menu, items.as_mut_ptr()); items.pop(); ret } } #[cfg(feature="menu")] pub fn set_menu_mark>>(menu: MENU, mark: T) -> i32 { unsafe { super::ll::set_menu_mark(menu, CString::new(mark).unwrap().into_raw()) } } #[cfg(feature="menu")] pub fn set_menu_opts(menu: MENU, opts: i32) -> i32 { unsafe { super::ll::set_menu_opts(menu, opts) } } #[cfg(feature="menu")] pub fn set_menu_pad(menu: MENU, opts: i32) -> i32 { unsafe { super::ll::set_menu_pad(menu, opts) } } #[cfg(feature="menu")] pub fn set_menu_pattern>>(menu: MENU, pattern: T) -> i32 { unsafe { super::ll::set_menu_pattern(menu, CString::new(pattern).unwrap().into_raw()) } } #[cfg(feature="menu")] pub fn set_menu_sub(menu: MENU, win: WINDOW) -> i32 { unsafe { super::ll::set_menu_sub(menu, win) } } #[cfg(feature="menu")] pub fn set_menu_term(menu: MENU, hook: HOOK) -> i32 { unsafe { super::ll::set_menu_term(menu, hook) } } #[cfg(feature="menu")] pub fn set_menu_win(menu: MENU, win: WINDOW) -> i32 { unsafe { super::ll::set_menu_win(menu, win) } } #[cfg(feature="menu")] pub fn set_top_row(menu: MENU, row: i32) -> i32 { unsafe { super::ll::set_top_row(menu, row) } } #[cfg(feature="menu")] pub fn top_row(menu: MENU) -> i32 { unsafe { super::ll::top_row(menu) } } #[cfg(feature="menu")] pub fn unpost_menu(menu: MENU) -> i32 { unsafe { super::ll::unpost_menu(menu) } } #[cfg(feature="menu")] pub fn menu_request_by_name>>(name: T) -> i32 { unsafe { super::ll::menu_request_by_name(CString::new(name).unwrap().as_ptr()) } } #[cfg(feature="menu")] pub fn set_menu_spacing(menu: MENU, spc_description: i32, spc_rows: i32, spc_columns: i32) -> i32 { unsafe { super::ll::set_menu_spacing(menu, spc_description, spc_rows, spc_columns) } } #[cfg(feature="menu")] pub fn menu_spacing(menu: MENU, spc_description: &mut i32, spc_rows: &mut i32, spc_columns: &mut i32) -> i32 { unsafe { super::ll::menu_spacing(menu, spc_description as *mut i32, spc_rows as *mut i32, spc_columns as *mut i32) } } #[cfg(feature="menu")] pub fn item_value(item: ITEM) -> bool { unsafe { super::ll::item_value(item) == TRUE } } #[cfg(feature="menu")] pub fn item_visible(item: ITEM) -> bool { unsafe { super::ll::item_visible(item) == TRUE } } #[cfg(feature="menu")] pub fn menu_format(menu: MENU, rows: &mut i32, cols: &mut i32) { unsafe { super::ll::menu_format(menu, rows as *mut i32, cols as *mut i32); } } pub fn ptr_to_string(ptr: *const c_char) -> String { unsafe { str::from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).to_owned() } } ncurses-5.99.0/src/panel/ll.rs010064400017500000144000000013531330701501000143500ustar0000000000000000#![allow(dead_code)] #![allow(unused_imports)] use libc::{ c_int, c_void }; use ll::WINDOW; pub type PANEL = *mut i8; #[cfg(feature="panel")] extern { pub fn panel_window(_:PANEL) -> WINDOW; pub fn update_panels() -> c_void; pub fn hide_panel(_:PANEL) -> c_int; pub fn show_panel(_:PANEL) -> c_int; pub fn del_panel(_:PANEL) -> c_int; pub fn top_panel(_:PANEL) -> c_int; pub fn bottom_panel(_:PANEL) -> c_int; pub fn new_panel(_:WINDOW) -> PANEL; pub fn panel_above(_:PANEL) -> PANEL; pub fn panel_below(_:PANEL) -> PANEL; pub fn move_panel(_:PANEL,_:c_int,_:c_int) -> c_int; pub fn replace_panel(_:PANEL,_:WINDOW) -> c_int; pub fn panel_hidden(_:PANEL) -> c_int; } ncurses-5.99.0/src/panel/mod.rs010064400017500000144000000000311270033604400145210ustar0000000000000000mod ll; pub mod wrapper; ncurses-5.99.0/src/panel/wrapper.rs010064400017500000144000000027411270033604400154340ustar0000000000000000#![allow(dead_code)] #![allow(unused_imports)] use panel::ll; use ll::WINDOW; use constants::TRUE; pub type PANEL = ll::PANEL; #[cfg(feature="panel")] pub fn panel_window(panel: PANEL) -> WINDOW { unsafe { ll::panel_window(panel) } } #[cfg(feature="panel")] pub fn update_panels() { unsafe { ll::update_panels(); } } #[cfg(feature="panel")] pub fn hide_panel(panel: PANEL) -> i32 { unsafe { ll::hide_panel(panel) } } #[cfg(feature="panel")] pub fn show_panel(panel: PANEL) -> i32 { unsafe { ll::show_panel(panel) } } #[cfg(feature="panel")] pub fn del_panel(panel: PANEL) -> i32 { unsafe { ll::del_panel(panel) } } #[cfg(feature="panel")] pub fn top_panel(panel: PANEL) -> i32 { unsafe { ll::top_panel(panel) } } #[cfg(feature="panel")] pub fn bottom_panel(panel: PANEL) -> i32 { unsafe { ll::bottom_panel(panel) } } #[cfg(feature="panel")] pub fn new_panel(window: WINDOW) -> PANEL { unsafe { ll::new_panel(window) } } #[cfg(feature="panel")] pub fn panel_above(panel: PANEL) -> PANEL { unsafe { ll::panel_above(panel) } } #[cfg(feature="panel")] pub fn panel_below(panel: PANEL) -> PANEL { unsafe { ll::panel_below(panel) } } #[cfg(feature="panel")] pub fn move_panel(panel: PANEL, y: i32, x: i32) -> i32 { unsafe { ll::move_panel(panel, y, x) } } #[cfg(feature="panel")] pub fn replace_panel(panel: PANEL, window: WINDOW) -> i32 { unsafe { ll::replace_panel(panel, window) } } #[cfg(feature="panel")] pub fn panel_hidden(panel: PANEL) -> bool { unsafe { ll::panel_hidden(panel) != 0 } } ncurses-5.99.0/.cargo_vcs_info.json0000644000000001120000000000000126530ustar00{ "git": { "sha1": "2a5dc99ef40c8f836b60b8a5ae9814410fc3bbcb" } }