mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Use compile-time include for examples
Instead of trying to read the file at runtime.
This commit is contained in:
parent
2380763b65
commit
267eddc263
@ -4,14 +4,9 @@ use cursive::Cursive;
|
|||||||
use cursive::align::HAlign;
|
use cursive::align::HAlign;
|
||||||
use cursive::view::{TextView, Dialog};
|
use cursive::view::{TextView, Dialog};
|
||||||
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Read some long text from a file.
|
// Read some long text from a file.
|
||||||
let mut file = File::open("assets/lorem.txt").unwrap();
|
let content = include_str!("../assets/lorem.txt");
|
||||||
let mut content = String::new();
|
|
||||||
file.read_to_string(&mut content).unwrap();
|
|
||||||
|
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
|
||||||
|
@ -1,24 +1,20 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{BufReader, BufRead};
|
|
||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::align::HAlign;
|
use cursive::align::HAlign;
|
||||||
use cursive::view::{Dialog, SelectView, TextView, BoxView};
|
use cursive::view::{Dialog, SelectView, TextView, BoxView};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// To keep things simple, little error management is done here.
|
|
||||||
// If you have an error, be sure to run this from the crate root, not from a sub directory.
|
|
||||||
|
|
||||||
let mut select = SelectView::new().h_align(HAlign::Center);
|
let mut select = SelectView::new().h_align(HAlign::Center);
|
||||||
|
|
||||||
// Read the list of cities from separate file, and fill the view with it.
|
// Read the list of cities from separate file, and fill the view with it.
|
||||||
let file = File::open("assets/cities.txt").unwrap();
|
// (We include the file at compile-time to avoid runtime read errors.)
|
||||||
let reader = BufReader::new(file);
|
let content = include_str!("../assets/cities.txt");
|
||||||
for line in reader.lines() {
|
for line in content.split('\n') {
|
||||||
select.add_item_str(&line.unwrap());
|
select.add_item_str(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the callback for when "Enter" is pressed.
|
||||||
select.set_on_select(show_next_window);
|
select.set_on_select(show_next_window);
|
||||||
|
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user