1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::rc::Rc;

use super::print_items::*;

thread_local! {
  static TRUE: ConditionResolver = Rc::new(|_| {
    Some(true)
  });

  static FALSE: ConditionResolver = Rc::new(|_| {
    Some(false)
  });

  static IS_START_OF_LINE_RESOLVER: ConditionResolver = Rc::new(|context| {
    Some(context.writer_info.is_start_of_line())
  });

  static IS_NOT_START_OF_LINE_RESOLVER: ConditionResolver = Rc::new(|context| {
    Some(!context.writer_info.is_start_of_line())
  });

  static IS_START_OF_LINE_INDENTED: ConditionResolver = Rc::new(|context| {
    Some(context.writer_info.is_start_of_line_indented())
  });

  static IS_START_OF_LINE_OR_IS_START_OF_LINE_INDENTED: ConditionResolver = Rc::new(|context| {
    Some(context.writer_info.is_start_of_line_indented() || context.writer_info.is_start_of_line())
  });

  static IS_FORCING_NO_NEWLINES: ConditionResolver = Rc::new(|context| {
    Some(context.is_forcing_no_newlines())
  });
}

pub fn true_resolver() -> ConditionResolver {
  TRUE.with(|r| r.clone())
}

pub fn false_resolver() -> ConditionResolver {
  FALSE.with(|r| r.clone())
}

pub fn is_start_of_line() -> ConditionResolver {
  IS_START_OF_LINE_RESOLVER.with(|r| r.clone())
}

pub fn is_not_start_of_line() -> ConditionResolver {
  IS_NOT_START_OF_LINE_RESOLVER.with(|r| r.clone())
}

pub fn is_start_of_line_indented() -> ConditionResolver {
  IS_START_OF_LINE_INDENTED.with(|r| r.clone())
}

pub fn is_start_of_line_or_is_start_of_line_indented() -> ConditionResolver {
  IS_START_OF_LINE_OR_IS_START_OF_LINE_INDENTED.with(|r| r.clone())
}

pub fn is_forcing_no_newlines() -> ConditionResolver {
  IS_FORCING_NO_NEWLINES.with(|r| r.clone())
}