Skip to content

Commit

Permalink
Revampt the config and got rid of things like bold, blink etc etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
agilesteel committed Nov 4, 2015
1 parent d4ea084 commit d80958d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 87 deletions.
36 changes: 21 additions & 15 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ spells {
WidthInCharacters = 160
}

XrayReport {
DisplayDateTime = yes
DisplayDuration = yes
DisplayLocation = yes
DisplayThread = yes
DisplayClass = yes
DisplayType = yes
xray {
report {
display {
DateTime = yes
Duration = yes
Location = yes
Thread = yes
Class = yes
Type = yes
}

DescriptionStyle = Green
DateTimeStyle = Untouched
DurationStyle = Untouched
LocationStyle = Untouched
ThreadStyle = Untouched
ClassStyle = Untouched
TypeStyle = Untouched
ValueStyle = Magenta
styles {
Description = Green
DateTime = Untouched
Duration = Untouched
Location = Untouched
Thread = Untouched
Class = Untouched
Type = Untouched
Value = Magenta
}
}
}
}
33 changes: 19 additions & 14 deletions src/main/scala/spells/Ansi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ trait Ansi {

implicit final class AnsiStyleBuilder(style: String) {
def toAnsiStyle: Ansi.Style = style match {
case "Random" => Random
case "Untouched" => Reset
case "Reset" => Reset
case "Black" => Black
Expand All @@ -15,10 +16,6 @@ trait Ansi {
case "Magenta" => Magenta
case "Cyan" => Cyan
case "White" => White
case "Bold" => Bold
case "Blink" => Blink
case "Reversed" => Reversed
case "Invisible" => Invisible
case _ => new Ansi.Style(style)
}
}
Expand All @@ -32,11 +29,12 @@ trait Ansi {
final val Magenta: Ansi.Style = Console.MAGENTA.toAnsiStyle
final val Cyan: Ansi.Style = Console.CYAN.toAnsiStyle
final val White: Ansi.Style = Console.WHITE.toAnsiStyle

final val Bold: Ansi.Style = Console.BOLD.toAnsiStyle
final val Blink: Ansi.Style = Console.BLINK.toAnsiStyle
final val Reversed: Ansi.Style = Console.REVERSED.toAnsiStyle
final val Invisible: Ansi.Style = Console.INVISIBLE.toAnsiStyle
final def Random: Ansi.Style =
Ansi.AllStylesOutOfTheBox {
util.Random.nextInt {
Ansi.AllStylesOutOfTheBox.size
}
}
}

object Ansi extends Ansi {
Expand All @@ -55,14 +53,21 @@ object Ansi extends Ansi {
final def magenta: String = this in Magenta
final def cyan: String = this in Cyan
final def white: String = this in White

final def bold: String = this in Bold
final def blink: String = this in Blink
final def reversed: String = this in Reversed
final def invisible: String = this in Invisible
}

final def removedStyles(input: String): String = input.replaceAll(StylePrint.StyleOrReset, "")

private final val Sample: String = "sample"

val AllStylesOutOfTheBox: Vector[Style] =
Vector(
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White
)
}
2 changes: 1 addition & 1 deletion src/main/scala/spells/CustomRendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object CustomRendering {
final val AvailableWidthInCharacters: CustomRendering.AvailableWidthInCharacters = new CustomRendering.AvailableWidthInCharacters(spells.terminal.WidthInCharacters)
}

implicit class AvailableWidthInCharacters(val value: Int) extends AnyVal {
implicit class AvailableWidthInCharacters(val value: Int) {
override final def toString: String = value.toString
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/spells/XRay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ object Xray
Report.customRenderedTableForXray(
lines,
styles = Map[String, Ansi.Style](
"DateTime" -> spells.XrayReport.DateTimeStyle,
"Duration" -> spells.XrayReport.DurationStyle,
"Location" -> spells.XrayReport.LocationStyle,
"Thread" -> spells.XrayReport.ThreadStyle,
"Class" -> spells.XrayReport.ClassStyle,
"Type" -> spells.XrayReport.TypeStyle,
"Value" -> spells.XrayReport.ValueStyle
"DateTime" -> spells.xray.report.styles.DateTime,
"Duration" -> spells.xray.report.styles.Duration,
"Location" -> spells.xray.report.styles.Location,
"Thread" -> spells.xray.report.styles.Thread,
"Class" -> spells.xray.report.styles.Class,
"Type" -> spells.xray.report.styles.Type,
"Value" -> spells.xray.report.styles.Value
) withDefaultValue Reset,
availableWidthInCharacters
)
Expand All @@ -115,7 +115,7 @@ object Xray
lazy val hyphens = "-" * (numberOfCharsInTheLongestLine min availableWidthInCharacters)

val centeredHeader = {
val headerStyleFromConfig: Ansi.Style = spells.XrayReport.DescriptionStyle
val headerStyleFromConfig: Ansi.Style = spells.xray.report.styles.Description
val header = if (Ansi.removedStyles(description).isEmpty) styled("X-Ray")(headerStyleFromConfig) else styled(description)(headerStyleFromConfig)
val emptySpace = hyphens.size - Ansi.removedStyles(header).size
val leftPadding = " " * (emptySpace / 2)
Expand Down
40 changes: 21 additions & 19 deletions src/main/scala/spells/package.scala
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package object spells extends LocationAwareConfig {
// private[spells] object coverage {
// object `should-be-happy` extends LocationAwareProperty[Boolean]
// }

object terminal {
object WidthInCharacters extends LocationAwareProperty[Int]
}

object XrayReport {
object DisplayDateTime extends LocationAwareProperty[Boolean]
object DisplayDuration extends LocationAwareProperty[Boolean]
object DisplayLocation extends LocationAwareProperty[Boolean]
object DisplayThread extends LocationAwareProperty[Boolean]
object DisplayClass extends LocationAwareProperty[Boolean]
object DisplayType extends LocationAwareProperty[Boolean]
object xray {
object report {
object display {
object DateTime extends LocationAwareProperty[Boolean]
object Duration extends LocationAwareProperty[Boolean]
object Location extends LocationAwareProperty[Boolean]
object Thread extends LocationAwareProperty[Boolean]
object Class extends LocationAwareProperty[Boolean]
object Type extends LocationAwareProperty[Boolean]
}

object DescriptionStyle extends LocationAwareProperty[Ansi.Style]
object DateTimeStyle extends LocationAwareProperty[Ansi.Style]
object DurationStyle extends LocationAwareProperty[Ansi.Style]
object LocationStyle extends LocationAwareProperty[Ansi.Style]
object ThreadStyle extends LocationAwareProperty[Ansi.Style]
object ClassStyle extends LocationAwareProperty[Ansi.Style]
object TypeStyle extends LocationAwareProperty[Ansi.Style]
object ValueStyle extends LocationAwareProperty[Ansi.Style]
object styles {
object Description extends LocationAwareProperty[Ansi.Style]
object DateTime extends LocationAwareProperty[Ansi.Style]
object Duration extends LocationAwareProperty[Ansi.Style]
object Location extends LocationAwareProperty[Ansi.Style]
object Thread extends LocationAwareProperty[Ansi.Style]
object Class extends LocationAwareProperty[Ansi.Style]
object Type extends LocationAwareProperty[Ansi.Style]
object Value extends LocationAwareProperty[Ansi.Style]
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/scala/compilation/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CompilationTests extends spells.user.UnitTestConfiguration {
new java.util.HashMap[Any, Any].rendered

object CR extends spells.CustomRendering {
def rendered(implicit availableWidthInCharacters: spells.CustomRendering.AvailableWidthInCharacters = spells.CustomRendering.Defaults.AvailableWidthInCharacters): String = ???
override def rendered(implicit availableWidthInCharacters: spells.CustomRendering.AvailableWidthInCharacters = spells.CustomRendering.Defaults.AvailableWidthInCharacters): String = "adf"
}
}
}
17 changes: 3 additions & 14 deletions src/test/scala/spells/user/AnsiTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class AnsiTests extends UnitTestConfiguration {
"Magenta".toAnsiStyle should be(Magenta)
"Cyan".toAnsiStyle should be(Cyan)
"White".toAnsiStyle should be(White)
"Bold".toAnsiStyle should be(Bold)
"Blink".toAnsiStyle should be(Blink)
"Reversed".toAnsiStyle should be(Reversed)
"Invisible".toAnsiStyle should be(Invisible)
spells.Ansi.AllStylesOutOfTheBox should contain("Random".toAnsiStyle)
}

test(""""green".green should be(Green.value + "green" + Reset.value)""") {
Expand All @@ -53,11 +50,7 @@ class AnsiTests extends UnitTestConfiguration {
Blue,
Magenta,
Cyan,
White,
Bold,
Blink,
Reversed,
Invisible
White
)

val factories =
Expand All @@ -69,11 +62,7 @@ class AnsiTests extends UnitTestConfiguration {
_.blue,
_.magenta,
_.cyan,
_.white,
_.bold,
_.blink,
_.reversed,
_.invisible
_.white
)

forEvery(styles zip factories) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/spells/user/CustomRenderingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CustomRenderingTests extends UnitTestConfiguration {
}

object CR extends spells.CustomRendering {
def rendered(implicit availableWidthInCharacters: spells.CustomRendering.AvailableWidthInCharacters = spells.CustomRendering.Defaults.AvailableWidthInCharacters): String =
def rendered(implicit availableWidthInCharacters: spells.CustomRendering.AvailableWidthInCharacters = spells.CustomRendering.Defaults.AvailableWidthInCharacters.value): String =
availableWidthInCharacters.toString
}
}
28 changes: 14 additions & 14 deletions src/test/scala/spells/user/DoubleEntryConfigKeeping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ class DoubleEntryConfigKeeping extends UnitTestConfiguration {
test("The reference.conf file should be valid") {
(spells.terminal.WidthInCharacters: Int) should be(160)

(spells.XrayReport.DisplayDateTime: Boolean) should be(true)
(spells.XrayReport.DisplayDuration: Boolean) should be(true)
(spells.XrayReport.DisplayLocation: Boolean) should be(true)
(spells.XrayReport.DisplayThread: Boolean) should be(true)
(spells.XrayReport.DisplayClass: Boolean) should be(true)
(spells.XrayReport.DisplayType: Boolean) should be(true)
(spells.xray.report.display.DateTime: Boolean) should be(true)
(spells.xray.report.display.Duration: Boolean) should be(true)
(spells.xray.report.display.Location: Boolean) should be(true)
(spells.xray.report.display.Thread: Boolean) should be(true)
(spells.xray.report.display.Class: Boolean) should be(true)
(spells.xray.report.display.Type: Boolean) should be(true)

(spells.XrayReport.DescriptionStyle: spells.Ansi.Style) should be(Green)
(spells.XrayReport.DateTimeStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.DurationStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.LocationStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.ThreadStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.ClassStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.TypeStyle: spells.Ansi.Style) should be(Reset)
(spells.XrayReport.ValueStyle: spells.Ansi.Style) should be(Magenta)
(spells.xray.report.styles.Description: spells.Ansi.Style) should be(Green)
(spells.xray.report.styles.DateTime: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Duration: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Location: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Thread: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Class: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Type: spells.Ansi.Style) should be(Reset)
(spells.xray.report.styles.Value: spells.Ansi.Style) should be(Magenta)
}
}

0 comments on commit d80958d

Please sign in to comment.