Skip to content

Commit

Permalink
Merge pull request #2 from Minecraftian14/Update-LambdasAndFile
Browse files Browse the repository at this point in the history
Update lambdas and file
  • Loading branch information
Minecraftian14 authored Jan 29, 2021
2 parents e444a58 + f50df76 commit fba0474
Show file tree
Hide file tree
Showing 47 changed files with 1,461 additions and 654 deletions.
15 changes: 0 additions & 15 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions OTHER_IMPORTANT_THINGS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Umm, complete documentation?

### Initialisation

```
// Default initialisation, prints to System.out
FLog logger = FLog.getNew();
// Prepares and provides the formatted log text to the given object.
// The object can be an OutputStream, a ByteConsumer or a StringsConsumer.
FLog logger = FLog.getNew(object);
// The same initialisation methods are followed by ALog
FLog logger = ALog.getNew();
FLog logger = ALog.getNew(object);
// To write logs to to a file "Hello.txt".
FLog logger = FileLog.getNew("Hello.txt");
// or
FLog logger = FileLog.getNew(new File("logs/Hello.txt"));
// To write logs to a file with a default name.
FLog logger = FileLog.getNew();
// To use a custom Decoration
log.setDecorationType(Decorations.TAG); // enable tag decos.
log.setDecorationType(Decorations.RAW); // enable raw decos, ie, no strange characters.
// creating a logger to both, print to console and write to file.
FLog log = ULog.forNew()
.add(FLog.getNew())
.add(FileLog.getNew("new.txt"))
.create();
// When using ConsoleDecoration, to set the color mode.
ConsoleDecoration.setColorMode(mode);
// mode can be one of [NONE, BLACK, WHITE, BIT_3, BIT_4, BIT_8, TRUE_COLOR_BIT_24]
```

#### Usage

```
// Print formatted text
// the arguments can be strings or objects.
logger.prt(arg1, arg2, arg3 ... argn);
// Print unformatted text
logger.raw(arg);
// Print with a custom format
logger.prtf(format1, format2...).consume(arg1, arg2, arg3...);
// To set a specific decoration type
logger.setDecorationType(name);
// name can be one of Decorations.[CONSOLE, RAW, TAG, EMPTY]
// To print a cluster of data at once, you may prepare a packet
Packet pack = logger.newPacket();
pack.prt(...);
pack.raw(...);
pack.consume();
// To use log levels
logger.general().prt(() -> new String[]{"General", "Hello", "World"});
// or
LogLevel.DEBUG.act(() -> log.prt("General", "Hello", "World"));
// To set a log level
LogLevel.setLevel(LogLevel.WARN);
// or
LogLevel.NOTICE.activate();
```
22 changes: 10 additions & 12 deletions PLOTTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ FLog log = FLog.getNew();
int[] age = new int[]{6,47,74,70,42,22,11,30,18,32,94,4,90,44,86,86,46,20,91,89,86,47,8,45,56};
log.raw(Plot.BarGraph.simple()
Plot.BarGraph.simple()
.values(age)
.create()
);
.create(log);
```
![SuperSimpleTest](images/SuperSimpleTest.png)<br /><br />

Expand All @@ -37,14 +36,13 @@ FLog log = FLog.getNew();
int[] age = new int[]{6, 47, 74, 70, 42, 22, 11, 30, 18, 32, 94, 4, 90, 44, 86, 86, 46, 20, 91, 89, 86, 47, 8, 45, 56};
log.raw(Plot.BarGraph.simple()
Plot.BarGraph.simple()
.title("Visitor's Age Survey")
.XLabel(0, age.length, i -> (age[i] > 18 ? "Adult " : "Minor ") + age[i])
.YLabel(0, 10,i -> i*15)
.scale(0.08)
.values(age)
.create()
);
.create(log);
```
![SimpleTest1](images/SimpleTest1.png)<br /><br />

Expand All @@ -53,12 +51,11 @@ FLog log = FLog.getNew();
int[] age = new int[]{6, 47, 74, 70, 42, 22, 11, 30, 18, 32, 94, 4, 90, 44, 86, 86, 46, 20, 91, 89, 86, 47, 8, 45, 56};
log.raw(Plot.BarGraph.simple()
Plot.BarGraph.simple()
.values(age)
.charHeight(15)
.setBarType(Box.B_T)
.create()
);
.create(log);
```
![SimpleTest3](images/SimpleTest3.png)<br /><br />

Expand All @@ -67,11 +64,10 @@ FLog log = FLog.getNew();
int[] age = new int[]{6, 47, 74, 70, 42, 22, 11, 30, 18, 32, 94};
log.raw(Plot.BarGraph.simple()
Plot.BarGraph.simple()
.values(age)
.setBarType("Hello")
.create()
);
.create(log);
```
![SimpleTest2](images/SimpleTest2.png)<br /><br />

Expand All @@ -96,5 +92,7 @@ log.raw(Plot.image(i.getWidth(), i.getHeight(), i.getWidth()/2, i.getHeight()/2,
(x, y) -> (i.getRGB(x, y) >> 8) & 0xFF, // for green
(x, y) -> i.getRGB(x, y) & 0xFF)); // for blue
```
original <br />
![SimpleTest2](images/ImageTestB.png)<br /><br />
the output <br />
![SimpleTest2](images/ImageTestA.png)<br /><br />
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

A simple _logging_ tool to make **console outputs** look prettier...

For instructions on writing a "Formatting Code",
Get an intro to "writing formatting codes" at,
[![](https://img.shields.io/badge/Logger-Instructions-yellow)](WRITING_A_FORMAT_FOR_DECORATION.md)

For examples of `@Format` annotation,
Other important stuff regarding the usage of this tool,
[![](https://img.shields.io/badge/Logger-Stuff-cyan)](WRITING_A_FORMAT_FOR_DECORATION.md)

Get simple and complicated examples for better insight,
[![](https://img.shields.io/badge/Logger-Examples-orange)](LOGGER_EXAMPLES.md)

For instructions on using Tables and examples,
You know, you can also create Tables with this tool!
[![](https://img.shields.io/badge/Tables-Examples-green)](TABLE_EXAMPLES.md)

For examples of plotint data,
And well, we have simple plotting tools too,
[![](https://img.shields.io/badge/Plotting-Examples-red)](PLOTTING.md)

For console specific compatibility,
[![](https://img.shields.io/badge/Console-Compatibility-purple)](SUPPORT.md)

<br />

[![](https://jitpack.io/v/Minecraftian14/MyLOGGER.svg)](https://jitpack.io/#Minecraftian14/MyLOGGER)
[![](https://img.shields.io/discord/740954840259362826?color=7289da&label=Discord)](https://discord.gg/UgMH9c98mg)
Expand All @@ -31,12 +35,13 @@ For console specific compatibility,
```groovy
allprojects {
repositories {
...
// ... other sources
maven { url 'https://jitpack.io' }
}
}
dependencies {
// ... other dependencies
// Include the library as a dependency.
// Replace TAG_NAME with the number aside jitpack badge.
Expand All @@ -51,18 +56,24 @@ dependencies {
#### Initialise

```
// default initialisation.
// Default initialisation, to print to Console.
FLog logger = FLog.getNew();
// if using the annotation processor version.
// The annotation processor version.
FLog logger = ALog.getNew();
// to use a custom Decoration
Decoration.setDecoration(TagDecoration::new);
// To write logs to to a file "Hello.txt".
FLog logger = FileLog.getNew("new.txt");
// to change the output Decoration when using RawFileDecoration
RawFileDecoration.setPartnerDecorationDecoration(TagDecoration::new);
Decoration.setDecoration(RawFileDecoration::new);
// to use a custom Decoration
log.setDecorationType(Decorations.TAG); // enable tag decos.
log.setDecorationType(Decorations.RAW); // enable raw decos, ie, no strange characters.
// creating a logger to both, print to console and write to file.
FLog log = ULog.forNew()
.add(FLog.getNew())
.add(FileLog.getNew("new.txt"))
.create();
```

#### Usage
Expand Down
16 changes: 8 additions & 8 deletions TABLE_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ for (int i = 0; i < len; i++) {
Oce[i] = Ace[i] * Mice[i];
}
System.out.print(Table.stripped()
Table.stripped()
.head("S.No.", "Number 1", "Number 2", "Answer")
.row("", "A", "B", "A x B")
.iter(0, len, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.row("", "Only", "Even", "Values")
.iter(1, len, 2, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.create());
.create(log);
```

### Output
Expand All @@ -42,14 +42,14 @@ System.out.print(Table.stripped()
```
// Same Initialisation
System.out.print(Table.box()
Table.box()
.title("Hello")
.head("S.No.", "Number 1", "Number 2", "Answer")
.row("!", "A", "B", "A x B")
.iter(0, len, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.row("", "Only", "Even", "Values")
.iter(1, len, 2, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.create());
.create(log);
```
### Output
![Example Table Two](images/T2.png)
Expand All @@ -63,14 +63,14 @@ System.out.print(Table.box()
```
// Same initialisation.
System.out.print(Table.empty()
Table.empty()
.title("Hello")
.head("S.No.", "Number 1", "Number 2", "Answer")
.row("!", "A", "B", "A x B")
.iter(0, len, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.row("", "Only", "Even", "Values")
.iter(1, len, 2, i -> i + 1, i -> Ace[i], i -> Mice[i], i -> Oce[i])
.create());
.create(log);
```
### Output
![Example Table Three](images/T3.png)
Expand All @@ -90,7 +90,7 @@ int gs = len / 10; // group size
Double[] iterations = new Double[len];
for (int i = 0; i < len; i++) iterations[i] = Math.random();
System.out.print(Table.stripped()
Table.stripped()
.title("Average of Random Numbers")
.head("S.No.", "Range", "Average")
.bunch(iterations, len / 10,
Expand All @@ -101,7 +101,7 @@ System.out.print(Table.stripped()
.formatTitle(":@4085eeb:")
.formatHead(":@2565ae#fff:", ":@0f5298#fff:")
.format(":@66d3fa:", ":@55d3fe:")
.create());
.create(log);
```
```
private Double avg(Double[] g) {
Expand Down
3 changes: 3 additions & 0 deletions WRITING_A_FORMAT_FOR_DECORATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ input text.
|Tab Space |t |Yes |Yes |? | To prepend a tab space |
|Word Wrap |wnw |Yes |Yes |? | Word Wrap input to fit a width of 'n' and apply the same format to each line. |
|Splitter |xcx |Yes |Yes |? | Split the given input about each occurrance of 'c'. |
|Repeater |R |Yes |Yes |Yes | Reuse the decorators from start when input exceeds them. |
|Meta Data |P C or M |Yes |Yes |Yes | P -> package name, C -> class name, M -> method name. |


* Console -> a Formatting Style to decorate the console outputs.
* Raw -> Just like console but no color/bold/underline... formatting.
* Tags -> a Formatting Style consisting of appending bracketed
tags to the input to inform a parser about the text format.
An example of this formatting is used in HyperLap2D to apply
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}
22 changes: 19 additions & 3 deletions src/main/java/com/mcxiv/logger/decorations/ConsoleDecoration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static void setColorMode(int mode) {
STATE = mode;
}

public ConsoleDecoration(String... codes) {
public ConsoleDecoration(Decorations.Tag tag, String... codes) {
super(tag);

decorates = new Decorate[codes.length];

Expand All @@ -39,13 +40,26 @@ public ConsoleDecoration(String... codes) {
FormattingCodeSplitter sp = new FormattingCodeSplitter(code);

// And some basic initialisation.
StringBuilder format = new StringBuilder(sp.prepre);
StringBuilder format = new StringBuilder();
Matcher m;


//


if (tag != null) {
String brush = "";
if (sp.content.contains("P")) brush += "[" + tag.packageName + "]";
if (sp.content.contains("C")) brush += "[" + tag.className + "]";
if (sp.content.contains("M")) brush += "[" + tag.executableName + "]";
sp.prepre = brush + " " + sp.prepre;
}
format.append(sp.prepre);


//


// Parsing Color type to code
String colorcd = "";

Expand Down Expand Up @@ -128,7 +142,9 @@ public ConsoleDecoration(String... codes) {
if (sp.content.contains("-"))
if (!sp.content.contains("%") || sp.content.indexOf("-") < sp.content.indexOf("%"))
format.append(C.FS);
if (sp.content.contains("~")) {

if (sp.content.contains("R")) the_whole_repeats = true;
else if (sp.content.contains("~")) {
last_one_repeats = true;
repeater_index = i;
}
Expand Down
Loading

0 comments on commit fba0474

Please sign in to comment.