config.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #[derive(Clone, Copy)]
  2. #[non_exhaustive]
  3. pub struct Config {
  4. pub(crate) rendering_mode: RenderingMode,
  5. /// Controls if the terminal quit when the user presses `ctrl+c`?
  6. /// To handle quiting on your own, use the [crate::TuiContext] root context.
  7. pub(crate) ctrl_c_quit: bool,
  8. /// Controls if the terminal should dislay anything, usefull for testing.
  9. pub(crate) headless: bool,
  10. }
  11. impl Config {
  12. pub fn new() -> Self {
  13. Self::default()
  14. }
  15. pub fn with_rendering_mode(self, rendering_mode: RenderingMode) -> Self {
  16. Self {
  17. rendering_mode,
  18. ..self
  19. }
  20. }
  21. pub fn without_ctrl_c_quit(self) -> Self {
  22. Self {
  23. ctrl_c_quit: false,
  24. ..self
  25. }
  26. }
  27. pub fn with_headless(self) -> Self {
  28. Self {
  29. headless: true,
  30. ..self
  31. }
  32. }
  33. }
  34. impl Default for Config {
  35. fn default() -> Self {
  36. Self {
  37. rendering_mode: Default::default(),
  38. ctrl_c_quit: true,
  39. headless: false,
  40. }
  41. }
  42. }
  43. #[derive(Clone, Copy, Default)]
  44. pub enum RenderingMode {
  45. /// only 16 colors by accessed by name, no alpha support
  46. BaseColors,
  47. /// 8 bit colors, will be downsampled from rgb colors
  48. Ansi,
  49. /// 24 bit colors, most terminals support this
  50. #[default]
  51. Rgb,
  52. }