ex_input/
ex_input.rs

1extern crate darkside;
2
3use darkside::input::*;
4use darkside::text::*;
5use darkside::*;
6use std::char;
7
8fn main() {
9  new_app();
10  let mut active_input = 0;
11  let mut input_username = new_input(2, 2, 30, "Username", false);
12  let mut input_password = new_input(2, 3, 30, "Password", true);
13  let mut result_text = new_text("", 2, 4);
14  loop {
15    render_input(&input_username);
16    render_input(&input_password);
17    render_text(&result_text);
18    let ch = wait_for_key();
19    if ch == KEY_DOWN {
20      active_input = 1;
21    } else if ch == KEY_UP {
22      active_input = 0;
23    } else if ch == KEY_BACKSPACE {
24      if active_input == 0 {
25        input_username = remove_input_last_char(input_username);
26      } else {
27        input_password = remove_input_last_char(input_password);
28      }
29    } else if ch == KEY_RETURN {
30      let username = get_input_value(&input_username);
31      let password = get_input_value(&input_password);
32      result_text = set_text_content(result_text, &format!("result: {}|{}", username, password));
33    } else {
34      let input_char = char::from_u32(ch as u32).unwrap();
35      if active_input == 0 {
36        input_username = add_input_char(input_username, input_char);
37      } else {
38        input_password = add_input_char(input_password, input_char);
39      }
40    }
41  }
42}