[LIB-13] Lazy scanners init, scan by URL and rename API functions
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / ChessHogScannerConsole.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.scanner;
18
19 import java.time.LocalDateTime;
20 import java.util.Calendar;
21
22 /**
23  * ChessHog Scanner utility class for working with console.
24  *
25  * @author Dmitry Samoshin aka gotty
26  */
27 public class ChessHogScannerConsole {
28
29     private static final String[] ASCII_LOGO = {
30             "             _______     _                   _                   ",
31             "            |   |  _|_ _| |___ ___ ___ ___ _| |___               ",
32             "            |     | -_| . | . | -_|  _| . | . | -_|              ",
33             "            |     |___|___|_  |___|___|___|___|___|              ",
34             "      _     |___|___| _   |___|                                  ",
35             "  ___| |_ ___ ___ ___| |_ ___ ___   ___ ___ ___ ___ ___ ___ ___  ",
36             " |  _|   | -_|_ -|_ -|   | . | . | |_ -|  _| .'|   |   | -_|  _| ",
37             " |___|_|_|___|___|___|_|_|___|_  | |___|___|__,|_|_|_|_|___|_|   ",
38             "                             |___|                               "
39     };
40
41     private static final String COPYRIGHT = "Copyright (c) Hedgecode";
42
43     private static boolean logMode = false;
44
45     private ChessHogScannerConsole() {
46     }
47
48     public static void setLogMode(boolean isLogMode) {
49         logMode = isLogMode;
50     }
51
52     public static void console(String message) {
53         System.out.println(
54                 String.format(
55                         logMode ? "[%1$tT] %2$s" : "%2$s",
56                         LocalDateTime.now(),
57                         message == null ? "" : message
58                 )
59         );
60     }
61
62     public static void empty() {
63         console(null);
64     }
65
66     public static void init() {
67         asciiLogo();
68         empty();
69         copyright();
70         version();
71         empty();
72     }
73
74     private static void asciiLogo() {
75         for (String line : ASCII_LOGO) {
76             console(line);
77         }
78     }
79
80     private static void copyright() {
81         int inceptionYear = ChessHogScannerProperties.getInt("scanner.inception.year");
82         int currentYear = Calendar.getInstance().get(Calendar.YEAR);
83         String copyright = currentYear > inceptionYear
84                 ? String.format("%s-%s %s", inceptionYear, currentYear, COPYRIGHT)
85                 : String.format("%s %s", currentYear, COPYRIGHT);
86         console(
87                 alignCenter(copyright)
88         );
89     }
90
91     private static void version() {
92         console(
93                 alignCenter(
94                         String.format(
95                                 "v. %s", ChessHogScannerProperties.get("scanner.version")
96                         )
97                 )
98         );
99     }
100
101     private static String alignCenter(String message) {
102         int indent = (ASCII_LOGO[0].length() + message.length()) / 2;
103         return String.format(
104                 "%" + indent + "s",
105                 message
106         );
107     }
108
109 }