ui.rs 913 B

1234567891011121314151617181920212223242526272829303132333435
  1. #[cfg(feature = "tv")]
  2. use std::ffi::CString;
  3. use std::io::{stdin, stdout, Write};
  4. #[cfg(feature = "tv")]
  5. use std::os::raw::c_char;
  6. #[cfg(feature = "tv")]
  7. extern "C" {
  8. fn ui_main(line: *const c_char);
  9. }
  10. #[cfg(feature = "tv")]
  11. #[cfg_attr(tarpaulin, ignore)]
  12. pub fn run_tv() {
  13. let line = CString::new("I'm calling TV!").expect("Failed to create string");
  14. unsafe {
  15. ui_main(line.as_ptr());
  16. }
  17. println!("Hello, world!");
  18. }
  19. pub fn input_category(item: &str, cat: &str, cats: &[&String]) -> String {
  20. let mut x = String::with_capacity(64);
  21. if !cat.is_empty() {
  22. print!("'{}'? (default: {}) > ", item, cat);
  23. } else {
  24. print!(
  25. "'{}'? (no default, possible categories: {:?}) > ",
  26. item, cats
  27. );
  28. }
  29. let _ = stdout().flush();
  30. stdin().read_line(&mut x).expect("Error reading input");
  31. String::from(x.trim_end_matches('\n'))
  32. }