gdritter repos knurling / adb3b12
Add some logging for practice Getty Ritter 5 years ago
2 changed file(s) with 57 addition(s) and 51 deletion(s). Collapse all Expand all
131131 source = "registry+https://github.com/rust-lang/crates.io-index"
132132
133133 [[package]]
134 name = "redox_syscall"
135 version = "0.1.51"
136 source = "registry+https://github.com/rust-lang/crates.io-index"
137
138 [[package]]
139 name = "time"
140 version = "0.1.42"
141 source = "registry+https://github.com/rust-lang/crates.io-index"
142 dependencies = [
143 "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
144 "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
145 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
146 ]
147
148 [[package]]
149 name = "winapi"
150 version = "0.3.6"
151 source = "registry+https://github.com/rust-lang/crates.io-index"
152 dependencies = [
153 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
154 "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
155 ]
156
157 [[package]]
158 name = "winapi-i686-pc-windows-gnu"
159 version = "0.4.0"
160 source = "registry+https://github.com/rust-lang/crates.io-index"
161
162 [[package]]
163 name = "winapi-x86_64-pc-windows-gnu"
164 version = "0.4.0"
165 source = "registry+https://github.com/rust-lang/crates.io-index"
166
167 [[package]]
168 name = "x11"
169 version = "2.18.1"
170 source = "registry+https://github.com/rust-lang/crates.io-index"
171 dependencies = [
172 "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
173 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
174 ]
175
176 [[package]]
177 name = "xsamp"
134 name = "rbar"
178135 version = "0.1.0"
179136 dependencies = [
180137 "cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
184141 "pangocairo 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
185142 "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
186143 "x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
144 ]
145
146 [[package]]
147 name = "redox_syscall"
148 version = "0.1.51"
149 source = "registry+https://github.com/rust-lang/crates.io-index"
150
151 [[package]]
152 name = "time"
153 version = "0.1.42"
154 source = "registry+https://github.com/rust-lang/crates.io-index"
155 dependencies = [
156 "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
157 "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
158 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
159 ]
160
161 [[package]]
162 name = "winapi"
163 version = "0.3.6"
164 source = "registry+https://github.com/rust-lang/crates.io-index"
165 dependencies = [
166 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
167 "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
168 ]
169
170 [[package]]
171 name = "winapi-i686-pc-windows-gnu"
172 version = "0.4.0"
173 source = "registry+https://github.com/rust-lang/crates.io-index"
174
175 [[package]]
176 name = "winapi-x86_64-pc-windows-gnu"
177 version = "0.4.0"
178 source = "registry+https://github.com/rust-lang/crates.io-index"
179
180 [[package]]
181 name = "x11"
182 version = "2.18.1"
183 source = "registry+https://github.com/rust-lang/crates.io-index"
184 dependencies = [
185 "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
186 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
187187 ]
188188
189189 [metadata]
66 use std::ffi::CString;
77 use std::os::raw::{c_int,c_uchar};
88 use std::ptr;
9 use std::io::Write;
10 use std::os::unix::io::AsRawFd;
911
1012 use pango::LayoutExt;
1113
7678 xinput2::XISetMask(&mut mask, event);
7779 }
7880
79
8081 match xinput2::XISelectEvents(w.display, w.window, &mut input_event_mask, 1) {
8182 status if status as u8 == xlib::Success => (),
8283 err => panic!("Failed to select events {:?}", err)
8384 }
8485 }
8586
86 w.set_protocols();
87 w.set_protocols();
8788 w.map();
8889
8990 let surf = w.get_cairo_surface();
9394
9495 let mut fds = std::mem::uninitialized();
9596 let mut input = format!("Loading...");
97 let stdin_fd = std::io::stdin().as_raw_fd();
9698 let mut stdin = std::io::BufReader::new(std::io::stdin());
9799 let mut timer = libc::timeval {
98100 tv_sec: 5,
99101 tv_usec: 0,
100102 };
103 let mut log = std::fs::File::create("/home/gdritter/log.txt").unwrap();
101104 draw(&ctx, "[1]");
102
105
103106 loop {
104107 use std::io::BufRead;
105108
106109 libc::FD_ZERO(&mut fds);
107110 libc::FD_SET(window_fd, &mut fds);
108 libc::FD_SET(1, &mut fds);
111 libc::FD_SET(stdin_fd, &mut fds);
109112
110113 libc::select(window_fd + 1, &mut fds, ptr::null_mut(), ptr::null_mut(), &mut timer);
111114
112 if libc::FD_ISSET(1, &mut fds) {
115 if libc::FD_ISSET(stdin_fd, &mut fds) {
113116 input = String::new();
114117 stdin.read_line(&mut input).unwrap();
118 log.write_fmt(format_args!("got {}", input)).unwrap();
115119 if input == "" {
116120 break;
117121 }
122126 draw(&ctx, &input);
123127 match w.handle() {
124128 Event::QuitEvent => break,
125 e => (),
129 Event::ShowEvent =>
130 draw(&ctx, &input),
131 _e => (),
126132 }
127133 }
128134
133139
134140 fn draw(ctx: &cairo::Context, left: &str) {
135141 let now = time::now();
136
142
137143 ctx.set_source_rgb(0.1, 0.1, 0.1);
138144 ctx.paint();
139145 ctx.set_source_rgb(1.0, 1.0, 1.0);