class
Phase::MultiIndexable::Formatter::Settings
- Phase::MultiIndexable::Formatter::Settings
- Reference
- Object
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.
Settings.project_settings(nilby default, but can be altered via.project_settings=)Settings.user_settings(attempts to cache and return settings from aformatter.yamlfile. See.user_settingsfor details)Settings.default(the default configuration that we, the developers of Phase, think is nice)
Included Modules
- YAML::Serializable
Defined in:
multi_indexable/formatter/settings.crConstant Summary
-
USER_CONFIG_FILENAME =
"formatter.yaml"
Constructors
- .default : 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)
- .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
- .new
Class Method Summary
- .project_settings : self | Nil
- .project_settings=(project_settings : self | Nil)
-
.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.
Instance Method Summary
-
#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.
-
#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.
- #collapse_height : Int32
- #collapse_height=(collapse_height : Int32)
-
#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 withcolors[1], and so on. -
#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 withcolors[1], and so on. - #decimal_format : String
- #decimal_format=(decimal_format : String)
-
#display_limit : Array(Int32)
The maximum number of elements to display in a single row before truncating output.
-
#display_limit=(display_limit : Array(Int32))
The maximum number of elements to display in a single row before truncating output.
-
#indent_width : Int32
Controls the number of spaces that will be used to produce each indentation.
-
#indent_width=(indent_width : Int32)
Controls the number of spaces that will be used to produce each indentation.
- #integer_format : String
- #integer_format=(integer_format : String)
-
#max_element_width : Int32
Controls the maximum number of characters to display for each element.
-
#max_element_width=(max_element_width : Int32)
Controls the maximum number of characters to display for each element.
Constructor Detail
Class Method Detail
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
Instance Method Detail
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
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
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.
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.
The maximum number of elements to display in a single row before truncating output.
The maximum number of elements to display in a single row before truncating output.
Controls the number of spaces that will be used to produce each indentation.
Controls the number of spaces that will be used to produce each indentation.
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.
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.