Added rust to practice
This commit is contained in:
parent
f6a827b078
commit
2a38448585
1
rust/calculator/.gitignore
vendored
Normal file
1
rust/calculator/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target
|
4
rust/calculator/Cargo.lock
generated
Normal file
4
rust/calculator/Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[root]
|
||||||
|
name = "calculator"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
6
rust/calculator/Cargo.toml
Normal file
6
rust/calculator/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "calculator"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Logen Kain <logen@sudotask.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
35
rust/calculator/src/main.rs
Normal file
35
rust/calculator/src/main.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Create a simple calculator
|
||||||
|
* I should be able to do basic add/sub/mult/divd and be able to use "()"
|
||||||
|
*
|
||||||
|
* 1. Take user input
|
||||||
|
* a. Check to see if there is a previous answer that we are going to act on
|
||||||
|
* 1. initialize answer to 0
|
||||||
|
* 2. if the user starts with an operand, the first number is "answer"
|
||||||
|
* else, start a new problem with whatever the user puts in
|
||||||
|
* b. Parse user input for ( ) / * - + in order to formulate a proper math problem
|
||||||
|
* 1. Strip trailing and leading white space
|
||||||
|
* 2. Check to see if there is a library that converts a string to a math problem
|
||||||
|
* c. check for the clear command
|
||||||
|
* 2. Calculate the answer
|
||||||
|
* a. Take
|
||||||
|
* 3. return the answer above a new prompt in a clered screen
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let strNumber1;
|
||||||
|
let strNumber2;
|
||||||
|
let number: i32;
|
||||||
|
|
||||||
|
strNumber1 = "5";
|
||||||
|
strNumber2 = "6";
|
||||||
|
number = strNumber1.parse::<i32>().unwrap() + strNumber2.parse::<i32>().unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
//let my_int = number.parse::<i32>().unwrap();
|
||||||
|
|
||||||
|
println!("Hello, world! Here's your number! {}", number);
|
||||||
|
}
|
@ -1,29 +1,75 @@
|
|||||||
extern crate pancurses;
|
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() {
|
fn main() {
|
||||||
|
|
||||||
/*Create the window*/
|
/*Create the window*/
|
||||||
let window = initscr();
|
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*/
|
/*Set some ncurses config*/
|
||||||
init();
|
init();
|
||||||
window.printw("Hello Rust");
|
window.printw("Hello Rust");
|
||||||
|
|
||||||
|
// window.printw(&draco.row.to_string());
|
||||||
|
|
||||||
/*See function for explination */
|
/*See function for explination */
|
||||||
refresh_win(&window);
|
refresh_win(&window);
|
||||||
window.getch();
|
|
||||||
|
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();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
cbreak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is a test to see how I can find a way to manipulate main()
|
/* 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) {
|
fn refresh_win(window: &pancurses::Window) {
|
||||||
window.refresh();
|
window.refresh();
|
||||||
}
|
}
|
||||||
|
1
rust/curses_test2/.gitignore
vendored
Normal file
1
rust/curses_test2/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target
|
30
rust/curses_test2/Cargo.lock
generated
Normal file
30
rust/curses_test2/Cargo.lock
generated
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[root]
|
||||||
|
name = "curses_test2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"ncurses 5.85.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gcc"
|
||||||
|
version = "0.3.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ncurses"
|
||||||
|
version = "5.85.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"gcc 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum gcc 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)" = "40899336fb50db0c78710f53e87afc54d8c7266fb76262fecc78ca1a7f09deae"
|
||||||
|
"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135"
|
||||||
|
"checksum ncurses 5.85.0 (registry+https://github.com/rust-lang/crates.io-index)" = "21f71f0e1ae96558612b1e9d188ec4f23149a11ee4fb4b96e130523bea52d605"
|
7
rust/curses_test2/Cargo.toml
Normal file
7
rust/curses_test2/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "curses_test2"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Logen Kain <logen@sudotask.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ncurses = "5.85.0"
|
27
rust/curses_test2/src/main.rs
Normal file
27
rust/curses_test2/src/main.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user