config.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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) -> Self {
  22. Self {
  23. ctrl_c_quit: true,
  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)]
  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. Rgb,
  51. }
  52. impl Default for RenderingMode {
  53. fn default() -> Self {
  54. RenderingMode::Rgb
  55. }
  56. }