config.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 with_ctrl_c_quit(self, ctrl_c_quit: bool) -> Self {
  22. Self {
  23. ctrl_c_quit,
  24. ..self
  25. }
  26. }
  27. pub fn with_headless(self, headless: bool) -> Self {
  28. Self { headless, ..self }
  29. }
  30. }
  31. impl Default for Config {
  32. fn default() -> Self {
  33. Self {
  34. rendering_mode: Default::default(),
  35. ctrl_c_quit: true,
  36. headless: false,
  37. }
  38. }
  39. }
  40. #[derive(Clone, Copy)]
  41. pub enum RenderingMode {
  42. /// only 16 colors by accessed by name, no alpha support
  43. BaseColors,
  44. /// 8 bit colors, will be downsampled from rgb colors
  45. Ansi,
  46. /// 24 bit colors, most terminals support this
  47. Rgb,
  48. }
  49. impl Default for RenderingMode {
  50. fn default() -> Self {
  51. RenderingMode::Rgb
  52. }
  53. }