Skip to content

Commit

Permalink
Removed threepoint font, added (upper)case support, removed TinyLog()…
Browse files Browse the repository at this point in the history
… constructor
  • Loading branch information
sikorka committed Jun 14, 2023
1 parent 35423fc commit 879dc2b
Show file tree
Hide file tree
Showing 14 changed files with 4,058 additions and 391 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Next run one of these methods:

TinyLog.dressUp(bold);
bold.applyLook();
new TinyLog(bold);

Now you own your log's look!

Expand Down Expand Up @@ -147,7 +146,6 @@ TODO

- enable multiline printing: `say("response:", response, headers)` would print in separate lines with one call
- refactor code to add more & proper Unit tests
- use `Case` class
- add FG / BG color combinations
- add javadoc for basic usage
- create predefined, lazy outfits
Expand Down
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@

<!-- junit tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>

<!-- spock tests -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4</version>
<version>2.3-groovy-4.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -130,6 +130,7 @@
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
<check/>
</configuration>
</plugin>

Expand Down Expand Up @@ -173,7 +174,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.6</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -185,7 +186,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<version>1.6</version>
<executions>
<execution>
<id>SIGN-ARTIFACTS</id>
Expand Down
125 changes: 104 additions & 21 deletions src/main/java/com/github/sikorka/Outfit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.github.sikorka.tinylog.Font;
import com.github.sikorka.tinylog.SpaceOut;

import static com.github.sikorka.TinyLog.*;

/**
* Dresses up {@link TinyLog} in pretty colors / sizes and fonts.
*/
Expand All @@ -26,15 +28,15 @@ public class Outfit {
private Color shoutColor = highlightColor;

/**
* Recommended are {@link Font#MINI}, {@link Font#STRAIGHT} or {@link Font#THREEPOINT}.
* Recommended are {@link Font#THIN_MINI}, {@link Font#THIN_STRAIGHT} or {@link Font#THIN_STRAIGHT}.
*/
private Font highlightFont = Font.STRAIGHT;
private Font highlightFont = Font.THIN_STRAIGHT;

/**
* Recommended are {@link Font#STANDARD}, {@link Font#SLANT}.
* Recommended are {@link Font#BIG}, {@link Font#BIG_CURSIVE}.
*/
private Font shoutFont = Font.SLANT;
private Font shoutFont = Font.BIG_CURSIVE;

//TODO methods for cases
private Case sayCase = Case.LOWER;
private Case sayLouderCase = Case.LOWER;
private Case highlightCase = Case.LOWER;
Expand All @@ -52,7 +54,6 @@ public Outfit sayColor(Color color) {
}

this.sayColor = color;

return this;
}

Expand All @@ -63,7 +64,6 @@ public Outfit loudColor(Color color) {
}

this.loudColor = color;

return this;
}

Expand All @@ -74,7 +74,6 @@ public Outfit highlightColor(Color color) {
}

this.highlightColor = color;

return this;
}

Expand All @@ -85,7 +84,6 @@ public Outfit shoutColor(Color color) {
}

this.shoutColor = color;

return this;
}

Expand All @@ -95,14 +93,78 @@ public Outfit shoutColor(Color color) {


public Outfit highlightFont(Font font) {
this.highlightFont = font;
if (font == null) {
this.highlightFont = Font.NONE;
return this;
}

this.highlightFont = font;
return this;
}

public Outfit shoutFont(Font font) {
if (font == null) {
this.shoutFont = Font.NONE;
return this;
}

this.shoutFont = font;
return this;
}

public Outfit shoutCase(Case c) {
if (c == null) {
this.shoutCase = Case.LOWER;
return this;
}

this.shoutCase = c;
return this;
}

public Outfit sayCase(Case c) {
if (c == null) {
this.sayCase = Case.LOWER;
return this;
}

this.sayCase = c;
return this;
}

public Case getSayCase() {
return sayCase;
}

public Case getSayLouderCase() {
return sayLouderCase;
}

public Case getHighlightCase() {
return highlightCase;
}

public Case getShoutCase() {
return shoutCase;
}

public Outfit sayLouderCase(Case c) {
if (c == null) {
this.sayLouderCase = Case.LOWER;
return this;
}

this.sayLouderCase = c;
return this;
}

public Outfit highlightCase(Case c) {
if (c == null) {
this.highlightCase = Case.LOWER;
return this;
}

this.highlightCase = c;
return this;
}

Expand All @@ -118,12 +180,10 @@ public Outfit shoutFont(Font font) {
*
* @return the single instance of {@link TinyLog}
* */
public TinyLog applyLook() {
return new TinyLog(this);
public void applyLook() {
TinyLog.dressUp(this);
}



public Outfit setClearScreen(SpaceOut size) {
clearScreenSize = size;

Expand Down Expand Up @@ -175,12 +235,35 @@ public Font getShoutFont() {
public static void main(String args[]) {
Outfit b = new Outfit()
.shoutColor(Color.BOLD_PURPLE)
.shoutFont(Font.THREEPOINT);

TinyLog log = new TinyLog(b);

log.say("I I, sir.");
log.shout("Nothin.");
.shoutFont(Font.THIN_STRAIGHT)
.shoutCase(Case.UPPER);
dressUp(b);
say("------ colors");
say("say");
shout("shout");


Outfit a = new Outfit()
.shoutFont(null)
.highlightFont(null);
dressUp(a);
say("------ fonts");
shout("shout");
highlight("highlight");
say("say");
sayLoud("say loud");

Outfit c = new Outfit()
.sayCase(Case.UPPER)
.shoutCase(Case.UPPER)
.highlightCase(Case.UPPER)
.sayLouderCase(Case.UPPER);
TinyLog.dressUp(c);
say("------ upper lower case");
say("say");
shout("shout");
highlight("highlight");
sayLoud("say loud");
}


Expand All @@ -189,7 +272,7 @@ public static void main(String args[]) {

// //Usage
// new Outfit().
// upper(). //if upper then huge will set width differently
// upper(). //if upper then huge will set width differently
// huge().
// yellow().
// newLine();
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/com/github/sikorka/TinyLog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.sikorka;

import com.github.lalyos.jfiglet.FigletFont;
import com.github.sikorka.tinylog.Case;
import com.github.sikorka.tinylog.Color;
import com.github.sikorka.tinylog.Font;
import com.github.sikorka.tinylog.SpaceOut;
Expand All @@ -11,7 +12,7 @@
* Tiny logger.
* <p>
* Delivers tiny API for printing msgs to standard out.
* Prints them with string effects for each msg type.
* Prints them with effects - like color or big font - for each msg type.
* <p>
* Makes log messages more readable and thus reading logs easier.
*
Expand All @@ -27,7 +28,7 @@ public class TinyLog {
.loudColor(Color.YELLOW_BOLD)
.highlightColor(Color.RED_BOLD)
.shoutColor(Color.BOLD_PURPLE)
.shoutFont(Font.STANDARD);
.shoutFont(Font.BIG);

static Outfit myOutfit = DEFAULT_OUTFIT;

Expand All @@ -37,7 +38,7 @@ public class TinyLog {
*
* @param outfit the proud outfit of the Tiny Log looks
* */
public TinyLog(Outfit outfit) {
protected TinyLog(Outfit outfit) {
myOutfit = outfit;
}

Expand All @@ -47,22 +48,17 @@ public TinyLog(Outfit outfit) {
* @param toBePrinted any object
*/
public static void say(String toBePrinted) {
if (myOutfit.getSayCase() == Case.UPPER) {
toBePrinted = toBePrinted.toUpperCase();
}

writePlainNoLine(
myOutfit.getSayColor(),
toBePrinted);

newLine();
}

// /**
// * Logs array to standard out.
// *
// * @param arrayToPrint an array object
// */
// public static void say(Object[] arrayToPrint) {
// say(Arrays.toString(arrayToPrint));
// }

/**
* Highlights object at standard out.
* <p>
Expand All @@ -71,13 +67,16 @@ public static void say(String toBePrinted) {
* @param toBePrinted any object
*/
public static void sayLoud(String toBePrinted) {
if (myOutfit.getSayLouderCase() == Case.UPPER) {
toBePrinted = toBePrinted.toUpperCase();
}

sayLoudNoLine(toBePrinted);
newLine();
}

private static void sayLoudNoLine(String toBePrinted) {
writePlainNoLine(myOutfit.getLoudColor(), toBePrinted);

}

/**
Expand Down Expand Up @@ -136,6 +135,10 @@ private static void writePlain(Color color, String toBePrinted) {
* @param somethingToPrint anything to print
*/
public static void highlight(String somethingToPrint) {
if (myOutfit.getHighlightCase() == Case.UPPER) {
somethingToPrint = somethingToPrint.toUpperCase();
}

writeInBigFont(
myOutfit.getHighlightFont(),
myOutfit.getHighlightColor(),
Expand All @@ -151,6 +154,10 @@ public static void highlight(String somethingToPrint) {
* @param toBePrinted any object to be printed
*/
public static void shout(String toBePrinted) {
if (myOutfit.getShoutCase() == Case.UPPER) {
toBePrinted = toBePrinted.toUpperCase();
}

writeInBigFont(
myOutfit.getShoutFont(),
myOutfit.getShoutColor(),
Expand Down Expand Up @@ -222,7 +229,7 @@ public static void dressUp(Outfit newOutfit) {
}

/** Switches to the plain old default and original outfit. */
public static void bringBackOriginalOutfit() {
public static void setDefaultOutfit() {
myOutfit = DEFAULT_OUTFIT;
}

Expand Down
Loading

0 comments on commit 879dc2b

Please sign in to comment.