1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-21 12:21:32 +03:00
wezterm/window/examples/basic.rs

36 lines
669 B
Rust
Raw Normal View History

2019-08-09 03:44:57 +03:00
use ::window::*;
2019-08-08 05:19:04 +03:00
use failure::Fallible;
2019-08-08 07:18:30 +03:00
struct MyWindow {
allow_close: bool,
}
impl WindowCallbacks for MyWindow {
fn can_close(&mut self) -> bool {
eprintln!("can I close?");
if self.allow_close {
2019-08-09 03:44:57 +03:00
Connection::get().unwrap().terminate_message_loop();
2019-08-08 07:18:30 +03:00
true
} else {
self.allow_close = true;
false
}
}
}
2019-08-08 05:19:04 +03:00
fn main() -> Fallible<()> {
2019-08-09 03:44:57 +03:00
let conn = Connection::init()?;
2019-08-08 07:18:30 +03:00
let win = Window::new_window(
"myclass",
"the title",
800,
600,
Box::new(MyWindow { allow_close: false }),
)?;
2019-08-08 05:19:04 +03:00
win.show();
2019-08-09 03:44:57 +03:00
conn.run_message_loop()
2019-08-08 05:19:04 +03:00
}