use datex_macros_internal::Datex;
#[derive(Datex, Debug, Clone, Default)]
#[datex(structural)]
pub struct DecompileOptions {
pub formatting_options: FormattingOptions,
pub resolve_slots: bool,
}
impl DecompileOptions {
pub fn json_compat() -> Self {
DecompileOptions {
formatting_options: FormattingOptions::json_compat(),
..DecompileOptions::default()
}
}
pub fn colorized() -> Self {
DecompileOptions {
formatting_options: FormattingOptions::colorized(),
..DecompileOptions::default()
}
}
pub fn pretty() -> Self {
DecompileOptions {
formatting_options: FormattingOptions::pretty(),
..DecompileOptions::default()
}
}
pub fn colorized_pretty() -> Self {
DecompileOptions {
formatting_options: FormattingOptions {
colorized: true,
mode: FormattingMode::pretty(),
..FormattingOptions::default()
},
..DecompileOptions::default()
}
}
pub fn compact() -> Self {
DecompileOptions {
formatting_options: FormattingOptions::compact(),
..DecompileOptions::default()
}
}
}
#[derive(Datex, Clone, Debug, Copy, Default)]
#[datex(structural)]
pub enum IndentType {
#[default]
Spaces,
Tabs,
}
#[derive(Datex, Debug, Clone, Default)]
#[datex(structural)]
pub enum FormattingMode {
#[default]
Compact,
Pretty {
indent: usize,
indent_type: IndentType,
},
}
impl FormattingMode {
pub fn pretty() -> Self {
FormattingMode::Pretty {
indent: 4,
indent_type: IndentType::Spaces,
}
}
pub fn compact() -> Self {
FormattingMode::Compact
}
pub fn pretty_with_indent(indent: usize, indent_type: IndentType) -> Self {
FormattingMode::Pretty {
indent,
indent_type,
}
}
}
#[derive(Datex, Debug, Clone, Default)]
#[datex(structural)]
pub struct FormattingOptions {
pub mode: FormattingMode,
pub json_compat: bool,
pub colorized: bool,
}
impl FormattingOptions {
pub fn colorized() -> Self {
FormattingOptions {
colorized: true,
..FormattingOptions::default()
}
}
pub fn json_compat() -> Self {
FormattingOptions {
json_compat: true,
..FormattingOptions::default()
}
}
pub fn compact() -> Self {
FormattingOptions {
mode: FormattingMode::Compact,
..FormattingOptions::default()
}
}
pub fn pretty() -> Self {
FormattingOptions {
mode: FormattingMode::pretty(),
..FormattingOptions::default()
}
}
pub fn pretty_with_indent(indent: usize, indent_type: IndentType) -> Self {
FormattingOptions {
mode: FormattingMode::pretty_with_indent(indent, indent_type),
..FormattingOptions::default()
}
}
}