Skip to content

Commit 0a979c3

Browse files
committed
Fixed bug iwth no month row 4 or 5.
Also bumped dependencies Cleaned up the code a small bit for both cal and libray
1 parent 37eb5c0 commit 0a979c3

File tree

12 files changed

+83
-39
lines changed

12 files changed

+83
-39
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ plugins {
3030
java
3131
application
3232
id("com.github.ben-manes.versions") version "0.53.0"
33-
id("com.gradleup.shadow") version "9.3.1"
33+
id("com.gradleup.shadow") version "9.3.2"
3434
}
3535

3636
group = "org.fross"
@@ -70,8 +70,8 @@ dependencies {
7070
implementation("com.google.code.gson:gson:2.13.2")
7171

7272
// --- JLine Terminal Access for Colorized Output---
73-
implementation("org.jline:jline-terminal:3.30.6")
74-
implementation("org.jline:jline-terminal-ffm:3.30.6")
73+
implementation("org.jline:jline-terminal:4.0.0")
74+
implementation("org.jline:jline-terminal-ffm:4.0.0")
7575

7676
// --- JUnit Testing ---
7777
testImplementation("org.junit.jupiter:junit-jupiter-api:6.1.0-M1")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ org.gradle.caching=false
1111
org.gradle.console=colored
1212

1313
# Cal Program Version
14-
version=3.0.2
14+
version=3.0.3
1515

1616
# Cal Inception Date
1717
inceptionYear=2018

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fcal
22
title: fCal
3-
version: '3.0.2'
3+
version: '3.0.3'
44
summary: Command line calendar display
55
description: |
66
fCal is a command line calendar utility. It will display a

src/main/java/org/fross/cal/Calendar.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public class Calendar {
3434
static protected final int DEFAULT_CALS_PER_ROW = 3;
3535
static protected final int CALENDARWIDTH = 20;
3636
static protected final int SPACESBETWEENCALS = 2;
37-
static protected final String[] MONTHLIST = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
38-
"November", "December"};
37+
static protected final String[] MONTHLIST = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
3938
static protected final int TODAYHIGHLIGHT_FG = Output.WHITE;
4039
static protected final int TODAYHIGHLIGHT_BG = Output.BLUE;
4140

@@ -96,10 +95,12 @@ public static int getDayOfWeek(int month, int day, int year) {
9695
* @return
9796
*/
9897
public static boolean isLeapYear(int year) {
99-
if ((year % 4 == 0) && (year % 100 != 0))
98+
if ((year % 4 == 0) && (year % 100 != 0)) {
10099
return true;
101-
if (year % 400 == 0)
100+
} else if (year % 400 == 0) {
102101
return true;
102+
}
103+
103104
return false;
104105
}
105106

@@ -244,9 +245,9 @@ public static String[] getCalDays(int month, int year) {
244245
// Insert spaces until we get to first day of the month in the calendar
245246
returnString[row] += " ".repeat(firstDayOfMon);
246247

247-
// Initialize the length of the each row
248+
// Initialize the length of each row
248249
// I can't just use the length of returnString[row] because the ANSI colored characters take up more room and that won't be
249-
// printed. Therefore I'll keep the length of the returnString in a separate variable
250+
// printed. Therefore, I'll keep the length of the returnString in a separate variable
250251
returnStringLen[row] = returnString[row].length();
251252

252253
// Create the day strings. After 7 days start a new line.
@@ -277,6 +278,7 @@ public static String[] getCalDays(int month, int year) {
277278
if (((day + firstDayOfMon) % 7 == 0) || (day == daysInMonth[month])) {
278279
// Ensure that the array element is padded with space characters
279280
if (returnStringLen[row] < CALENDARWIDTH) {
281+
// Pad the return string for this row with spaces
280282
returnString[row] += " ".repeat(CALENDARWIDTH - returnStringLen[row] + 1);
281283
}
282284

@@ -285,6 +287,12 @@ public static String[] getCalDays(int month, int year) {
285287
}
286288
}
287289

290+
// Ensure the 5th row (row=4) is padded.
291+
// Fixed bug where 2/28 ended on Sunday, and we didn't have anything in row=4
292+
if (returnStringLen[4] == 0) {
293+
returnString[4] = " ".repeat(CALENDARWIDTH + 1);
294+
}
295+
288296
// Ensure last row / array element is CALENDARWIDTH characters. Pad with spaces.
289297
int lastElement = returnString.length - 1;
290298
if (returnString[lastElement].length() < CALENDARWIDTH) {

src/main/java/org/fross/cal/CommandLineArgs.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ public static void ProcessCommandLine(String[] argv) {
144144
Output.debugPrintln("No Month or Year provided on command line. Showing current year: " + yearToUse);
145145
break;
146146

147-
// Just a date or month provided
147+
// Just a Year or Month provided
148148
case 1:
149-
int d = Integer.parseInt(cli.clMonthAndOrYear.get(0));
149+
int d = Integer.parseInt(cli.clMonthAndOrYear.getFirst());
150150

151-
// Number must be a year if it's greater than 12
151+
// If the entered number is greater than 12 then it must be a year
152152
if (d > 12) {
153153
yearToUse = d;
154154
Output.debugPrintln("Commandline Year provided. Showing Year: " + yearToUse);
@@ -180,7 +180,7 @@ public static void ProcessCommandLine(String[] argv) {
180180
/**
181181
* Return the month to use after processing the command line
182182
*
183-
* @return
183+
* @return Selected Month
184184
*/
185185
public static int queryMonthToUse() {
186186
return monthToUse;
@@ -189,7 +189,7 @@ public static int queryMonthToUse() {
189189
/**
190190
* Return the year to use after processing the command line
191191
*
192-
* @return
192+
* @return Selected Year
193193
*/
194194
public static int queryYearToUse() {
195195
return yearToUse;

src/main/java/org/fross/cal/Holidays.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.fross.library.Output;
3030
import org.fross.library.URLOperations;
3131

32+
import java.io.IOException;
3233
import java.util.Locale;
3334
import java.util.TreeMap;
3435
import java.util.prefs.BackingStoreException;

src/main/java/org/fross/cal/Main.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Main {
4848
/**
4949
* Main(): Start of program and holds main command loop
5050
*
51-
* @param args
51+
* @param args Command Line Arguments
5252
*/
5353
public static void main(String[] args) {
5454
// Force JLine to assume the terminal supports ANSI color and movement
@@ -63,23 +63,23 @@ public static void main(String[] args) {
6363

6464
// Create a terminal used for output with JLine
6565
try {
66-
// This will print the actual reason (like "Missing library" or "Access Denied") to the console
67-
// For Debugging: System.setProperty("org.jline.terminal.debug", "true");
66+
// Print any jline issues to the console for debugging
67+
// System.setProperty("org.jline.terminal.debug", "true");
6868

6969
// Create the terminal
7070
terminal = TerminalBuilder.builder()
7171
.system(true)
7272
.build();
7373

74-
// Let Output and Input classes know which terminal to use
74+
// Let the Output classes know which terminal to use
7575
Output.setTerminal(terminal);
7676

7777
} catch (IOException ex) {
78-
// Note: Since terminal failed, we use System.out as a fallback
78+
// Note: Since terminal failed, Output will use System.out as a fallback
7979
Output.println("Unable to create a terminal. Visuals may be impacted");
8080
}
8181

82-
// Process application level properties file
82+
// Process application level properties file. The values are updated via the Gradle processResources task
8383
try {
8484
InputStream iStream = Main.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE);
8585
Properties prop = new Properties();
@@ -108,7 +108,7 @@ public static void main(String[] args) {
108108
Output.fatalError("There can not be more than 2 dates given on the commandline.\nPlease see Help (-h)", 6);
109109
}
110110

111-
// Ensure the month / year is a valid integer
111+
// Ensure the Month / Year is a valid integer
112112
for (int i = 0; i < CommandLineArgs.cli.clMonthAndOrYear.size(); i++) {
113113
int monthAndOrYear = 0;
114114
try {

src/main/java/org/fross/library/Output.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public static void Ansi256Test() {
236236
Output.printColor(index, String.format("%d", index));
237237
}
238238

239-
System.out.println("\n");
239+
Output.println("\n");
240240

241241
// Test Backgrounds
242242
for (int index = 0; index < 256; index++) {

src/main/java/org/fross/library/URLOperations.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static String ReadURL(String urlString) throws Exception {
5454
}
5555

5656
} catch (Exception ex) {
57-
Output.printColorln(Output.RED, "ERROR: An IO Error Occurred\n" + ex.getMessage());
57+
throw new IOException(ex.getMessage());
5858
} finally {
5959
if (reader != null) {
6060
reader.close();
@@ -83,7 +83,8 @@ public static void DownloadURLToFile(String urlStr, String file) throws IOExcept
8383
fos = new FileOutputStream(file);
8484

8585
} catch (Exception ex) {
86-
Output.printColorln(Output.RED, "ERROR: An error occurred opening the URL\n" + ex.getMessage());
86+
//Output.printColorln(Output.RED, "ERROR: An error occurred opening the URL\n" + ex.getMessage());
87+
throw new IOException(ex.getMessage());
8788
}
8889

8990
// Download chunks of the file and write them out
@@ -98,9 +99,13 @@ public static void DownloadURLToFile(String urlStr, String file) throws IOExcept
9899
Output.printColorln(Output.RED, "ERROR: An error occurred reading from the URL\n" + ex.getMessage());
99100
}
100101

101-
// Cleanup by closing the streams
102-
fos.close();
103-
bis.close();
102+
// Cleanup by closing the streams.
103+
if (fos != null) {
104+
fos.close();
105+
}
106+
if (bis != null) {
107+
bis.close();
108+
}
104109
}
105110

106111
/**

0 commit comments

Comments
 (0)