Skip to content

Commit

Permalink
Output com biblioteca jansi
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo authored and Ricardo committed Feb 9, 2021
1 parent 78af3b0 commit c798fc6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<graalvm.version>20.2.0</graalvm.version>
<jansi.version>2.2.0</jansi.version>
</properties>

<dependencies>
Expand All @@ -29,6 +30,11 @@
<artifactId>picocli</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>${jansi.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ric/dividaspgfn/BasePGFN.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Integer call() throws Exception {

Files.deleteIfExists(baseConsolidada);

System.out.println("Criando base em " + baseConsolidada.toAbsolutePath());
Common.mensagemProgresso("Criando base em " + baseConsolidada.toAbsolutePath());

try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + baseConsolidada.toAbsolutePath());) {
Common.executeUpdateStatement(conn, "CREATE TABLE pgfn_devedores " +
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/ric/dividaspgfn/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.sql.SQLException;
import java.sql.Statement;

import org.fusesource.jansi.Ansi;

final class Common {
static final Charset CHARSET = StandardCharsets.ISO_8859_1;

Expand All @@ -16,4 +18,12 @@ public static int executeUpdateStatement(Connection connection, String statement
return stmt.executeUpdate(statement);
}
}

public static void mensagemErro(String mensagem) {
System.out.println(Ansi.ansi().fgBright(Ansi.Color.RED).a(mensagem).reset());
}

public static void mensagemProgresso(String mensagem) {
System.out.println(Ansi.ansi().fgBright(Ansi.Color.GREEN).a(mensagem).reset());
}
}
21 changes: 20 additions & 1 deletion src/main/java/com/ric/dividaspgfn/DividaPGFN.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package com.ric.dividaspgfn;

import org.fusesource.jansi.AnsiConsole;

import picocli.CommandLine;
import picocli.CommandLine.Command;

@Command(name = "dividapgfn", subcommands = { BasePGFN.class, FiltraDivida.class })
final class DividaPGFN {
public static void main(String... args) {
System.exit(new CommandLine(new DividaPGFN()).execute(args));
CommandLine cli = new CommandLine(new DividaPGFN());

boolean jansiInstalled = false;
try {
AnsiConsole.systemInstall();
jansiInstalled = true;
} catch (Exception e) {
//ignorar
}
int exitCode = cli.execute(args);
if (jansiInstalled) {
try {
AnsiConsole.systemUninstall();
} catch (Exception e) {
//ignorar
}
}
System.exit(exitCode);
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/ric/dividaspgfn/FiltraDivida.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public Integer call() throws Exception {
Files.createDirectory(dirSaida);
}

System.out.println("Criando arquivos de análise em " + dirSaida.toAbsolutePath());
Common.mensagemProgresso("Criando arquivos de análise em " + dirSaida.toAbsolutePath());

if (Files.notExists(basePGFN)) {
System.out.println("Erro: arquivo " + basePGFN.toAbsolutePath() + " não encontrado.");
Common.mensagemErro("Erro: arquivo " + basePGFN.toAbsolutePath() + " não encontrado.");
return 1;
}

if (Files.notExists(this.baseCNPJ)) {
System.out.println("Erro: arquivo " + this.baseCNPJ.toAbsolutePath() + " não encontrado.");
Common.mensagemErro("Erro: arquivo " + this.baseCNPJ.toAbsolutePath() + " não encontrado.");
return 1;
}

if (Files.notExists(this.arqConsulta)) {
System.out.println("Erro: arquivo " + this.arqConsulta.toAbsolutePath() + " não encontrado.");
Common.mensagemErro("Erro: arquivo " + this.arqConsulta.toAbsolutePath() + " não encontrado.");
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module com.ric.dividaspgfn {
requires java.sql;
requires info.picocli;
requires org.fusesource.jansi;

opens com.ric.dividaspgfn to info.picocli;
}

0 comments on commit c798fc6

Please sign in to comment.