Added rust to practice
This commit is contained in:
@@ -1,29 +1,75 @@
|
||||
extern crate pancurses;
|
||||
|
||||
use pancurses::{initscr, endwin, noecho, curs_set};
|
||||
use pancurses::{initscr, endwin, noecho, curs_set, cbreak, Input};
|
||||
const SCREENWIDTH: i32 = 15;
|
||||
const SCREENHEIGHT: i32 = 15;
|
||||
|
||||
|
||||
struct Character {
|
||||
row: i32,
|
||||
col: i32,
|
||||
symbol: char
|
||||
}
|
||||
|
||||
fn new_character(row: i32, col: i32, symbol: char) -> Character{
|
||||
let mut a = Character {
|
||||
row: row,
|
||||
col: col,
|
||||
symbol: symbol,
|
||||
};
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
/*Create the window*/
|
||||
let window = initscr();
|
||||
|
||||
window.keypad(true);
|
||||
|
||||
let mut max_x = 0;
|
||||
let mut max_y = 0;
|
||||
|
||||
|
||||
|
||||
getmaxyx(stdscr(), &mut max_y, &mut max_x);
|
||||
|
||||
/*Create our dude*/
|
||||
let draco = new_character(5,5,'@');
|
||||
|
||||
/*Set some ncurses config*/
|
||||
init();
|
||||
window.printw("Hello Rust");
|
||||
|
||||
// window.printw(&draco.row.to_string());
|
||||
|
||||
/*See function for explination */
|
||||
refresh_win(&window);
|
||||
window.getch();
|
||||
endwin();
|
||||
|
||||
loop {
|
||||
match window.getch() {
|
||||
Some(Input::Character(c)) => { window.addch(c); },
|
||||
Some(Input::KeyDC) => break,
|
||||
// Some(Input::KeyUp) => {
|
||||
// let mut y;
|
||||
// / let mut x;
|
||||
// getyx(window, y, x); },
|
||||
Some(Input) => { window.addstr(&format!("{:?}", Input)); },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
endwin();
|
||||
}
|
||||
|
||||
fn init() {
|
||||
noecho();
|
||||
curs_set(0);
|
||||
cbreak();
|
||||
}
|
||||
|
||||
|
||||
/* This is a test to see how I can find a way to manipulate main()
|
||||
* data in functions */
|
||||
* data (scope) in functions */
|
||||
fn refresh_win(window: &pancurses::Window) {
|
||||
window.refresh();
|
||||
}
|
||||
|
Reference in New Issue
Block a user