class Phase::MultiIndexable::Formatter::Settings

Overview

Every instance of Settings stores configuration options that can be provided to MultiIndexable::Formatter. Additionally, Settings can store a project-wide formatter configuration (via .project_settings and .project_settings=), and load system-wide configuration (via self.user_settings).

Where does Settings get it's data from?

All user-configurable printing methods in Formatter will accept an optional settings parameter. If you provide an instance of Settings to that formatter method, it will always be used, no matter what project or system-wide configuration is enabled. If you do not provide a Settings instance in the call to Formatter, Formatter will load its configuration from Settings.new.

Settings.new will check everything on this list (starting at the top) until it finds suitable settings, and then returns those.

Included Modules

Defined in:

multi_indexable/formatter/settings.cr

Constant Summary

USER_CONFIG_FILENAME = "formatter.yaml"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.default : self #

[View source]
def self.new(indent_width : Int32, max_element_width : Int32, omit_after display_limit : Array(Int32), brackets : Array(Tuple(String, String)), colors, collapse_brackets_after collapse_height : Int32, integer_format : String, decimal_format : String) #

[View source]
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new #

[View source]

Class Method Detail

def self.project_settings : self | Nil #

[View source]
def self.project_settings=(project_settings : self | Nil) #

[View source]
def self.user_settings : self | Nil #

TODO document properly once this is set in stone tries to read from PHASE_CONFIG_DIR - if the file isn't there, reads from XDG_CONFIG_DIR/phase. if still not there, tries ~/.config BETTER_ERROR: Better error message for failed read


[View source]

Instance Method Detail

def brackets : Array(Tuple(String, String)) #

The formatter is capable of using different brackets for different structures - this may help disambiguate rows, columns, and higher dimensional arrays.

narr = NArray.build([2, 2, 2, 2]) { |_, idx| idx }

settings = MultiIndexable::Formatter::Settings.default
settings.brackets = [{"<", ">"}, {"begin", "end"}]

MultiIndexable::Formatter.print(narr, settings: settings)

# Output (note how the 0th element in brackets was used for the innermost arrays)
# begin
#     <
#         begin< 0,  1>,
#              < 2,  3>end,
#         
#         begin< 4,  5>,
#              < 6,  7>end
#     >,
#     <
#         begin< 8,  9>,
#              <10, 11>end,
#         
#         begin<12, 13>,
#              <14, 15>end
#     >
# end

[View source]
def brackets=(brackets : Array(Tuple(String, String))) #

The formatter is capable of using different brackets for different structures - this may help disambiguate rows, columns, and higher dimensional arrays.

narr = NArray.build([2, 2, 2, 2]) { |_, idx| idx }

settings = MultiIndexable::Formatter::Settings.default
settings.brackets = [{"<", ">"}, {"begin", "end"}]

MultiIndexable::Formatter.print(narr, settings: settings)

# Output (note how the 0th element in brackets was used for the innermost arrays)
# begin
#     <
#         begin< 0,  1>,
#              < 2,  3>end,
#         
#         begin< 4,  5>,
#              < 6,  7>end
#     >,
#     <
#         begin< 8,  9>,
#              <10, 11>end,
#         
#         begin<12, 13>,
#              <14, 15>end
#     >
# end

[View source]
def collapse_height : Int32 #

[View source]
def collapse_height=(collapse_height : Int32) #

[View source]
def colors : Array(Colorize::ColorRGB | Symbol) #

The formatter output can be colorized according to its nesting level - the brackets around sets of elements are colored with colors[0], the brackets around sets of rows are colored with colors[1], and so on. Note that this array can be whatever length you want - the formatter will restart the color cycle after reaching the end of the color array.

For a list of valid colors, see the Colorize module in the standard library.


[View source]
def colors=(colors : Array(Colorize::ColorRGB | Symbol)) #

The formatter output can be colorized according to its nesting level - the brackets around sets of elements are colored with colors[0], the brackets around sets of rows are colored with colors[1], and so on. Note that this array can be whatever length you want - the formatter will restart the color cycle after reaching the end of the color array.

For a list of valid colors, see the Colorize module in the standard library.


[View source]
def decimal_format : String #

[View source]
def decimal_format=(decimal_format : String) #

[View source]
def display_limit : Array(Int32) #

The maximum number of elements to display in a single row before truncating output.


[View source]
def display_limit=(display_limit : Array(Int32)) #

The maximum number of elements to display in a single row before truncating output.


[View source]
def indent_width : Int32 #

Controls the number of spaces that will be used to produce each indentation.


[View source]
def indent_width=(indent_width : Int32) #

Controls the number of spaces that will be used to produce each indentation.


[View source]
def integer_format : String #

[View source]
def integer_format=(integer_format : String) #

[View source]
def max_element_width : Int32 #

Controls the maximum number of characters to display for each element. Elements that stringify to something longer than this will be truncated, and numbers that are too long will be put into scientific notation to attempt to fit them into this length.


[View source]
def max_element_width=(max_element_width : Int32) #

Controls the maximum number of characters to display for each element. Elements that stringify to something longer than this will be truncated, and numbers that are too long will be put into scientific notation to attempt to fit them into this length.


[View source]