Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a4951de
made notes for App.java file
BradyLeg May 13, 2025
774080b
made notes for ConsoleColor.java file
BradyLeg May 13, 2025
7cb7e03
made notes for ConsoleColor.java file
BradyLeg May 13, 2025
9ee1144
made notes for ColorPrinter.java and ConlorPrinterTest.java files
BradyLeg May 13, 2025
15c6881
Small changes
BradyLeg May 14, 2025
c21e44f
added notes for truffulla options and test files
JSaiyan May 14, 2025
d58ee3b
Small changes
BradyLeg May 14, 2025
2f3e7ca
added notes to AlphabeticalFileSorter.java
JSaiyan May 14, 2025
8e7c30f
Added notes for TruffulaPrint and test files
BradyLeg May 14, 2025
53d34f7
Small changes
BradyLeg May 14, 2025
1177390
changes
JSaiyan May 14, 2025
742bc64
Created print method
BradyLeg May 19, 2025
5ae34ac
colorprinter
JSaiyan May 19, 2025
6286c2d
colortests
JSaiyan May 19, 2025
9d6556f
Created testPrintWithCyanSingleParameterRestTrue
BradyLeg May 19, 2025
20c7319
Merged tests
BradyLeg May 19, 2025
dbff46f
Changed print method to print using printStream
BradyLeg May 20, 2025
f3ae869
changes
JSaiyan May 23, 2025
b9f4cc7
wave 2 progress
JSaiyan May 23, 2025
50be950
Added tests for TruffulaOptionsTest.java
BradyLeg May 23, 2025
2270fa1
fixed errors in TrufflaOptions
BradyLeg May 23, 2025
b0288a7
Added more tests for TruffulaOptionsTest.java
BradyLeg May 23, 2025
c790ef4
updates
JSaiyan May 23, 2025
cc3fe2b
Final edits to TrufflaOptions and test file
BradyLeg May 23, 2025
c51f409
Fixed merge issues
BradyLeg May 23, 2025
3083c1b
updates
JSaiyan May 23, 2025
2b92065
Completed steps 2 and 3 for wave 3
BradyLeg May 24, 2025
1173665
wave3 updates
JSaiyan May 24, 2025
5774657
wave 3 updates2
JSaiyan May 24, 2025
21d05fe
wave 4 updates
JSaiyan May 24, 2025
53bfc89
printTree method implemented wave 1
BradyLeg May 24, 2025
00cbf77
wave 4 updates
JSaiyan May 24, 2025
08d79d3
updated wave44
JSaiyan May 24, 2025
d9439f8
Merged TrufflaPrinterTest
BradyLeg May 24, 2025
feb7dfc
Merged TrufflaPrinterTest
BradyLeg May 24, 2025
5c12b54
wave444 updates
JSaiyan May 24, 2025
b478e1e
Completed wave 4
BradyLeg May 24, 2025
5ac4656
Removed depth limit
BradyLeg May 27, 2025
4d4d65a
Added conditions to check for hidden files and if they should be printed
BradyLeg May 27, 2025
f910d13
tests for hiddendiles
JSaiyan May 27, 2025
77e0106
updated
JSaiyan May 27, 2025
d3b28c2
merge
BradyLeg May 27, 2025
59763f1
Changed tests names and fixed testPrintTree_ExactOutput_WithCustomPri…
BradyLeg May 27, 2025
7f972ca
created testPrintTree_ExactOutput_WithCustomPrintStream_showHiddenFal…
BradyLeg May 27, 2025
32bab69
colors added
JSaiyan May 27, 2025
821d025
merged updates
JSaiyan May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ As part of Wave 0, please fill out notes for each of the below files. They are i
PLEASE MAKE FREQUENT COMMITS AS YOU FILL OUT THIS FILE.

## App.java

- Actual file that gets executed.
- Includes options to show hidden files, use colored output, and the root directory that the program should start reading from.
- Flags should be used to show hidden files (-h) and not using colored output (-nc).
## ConsoleColor.java
- Applies color to console text using Enums representing ANSI escape codes.
- To apply a color, prepend the desired color ANSI code to the text and append the RESET code after the text to reset the color to default.

## ColorPrinter.java / ColorPrinterTest.java
- ColorPrinter is a class that supports printing colored text using PrintStream.
- Allows setting a current color, print messages in that color, and deciding if the color should be reset or not.
- Colors and the reset code can be accessed from the ConsoleColor class
- ColorPrintTest contains a test for checking if the color red is applied to the text properly

## TruffulaOptions.java / TruffulaOptionsTest.java
- checks flags for if color should not be used (-nc)
- or if hidden files should be shown (-h)
- if unkown flags are provided or path argument is missing, throws illegalArgumentException/
- FileNotFoundException will be thrown if specified directory does not exist or if path points to a file instead of a directory
- checks to see if flags are being created properly
- checks if file directory path is being read correctly

## TruffulaPrinter.java / TruffulaPrinterTest.java
- Prints the directory tree structure.
- Supports sorting files and directories in a case-insensitive alphabetical order.
- Cycles through texts colors for visually clarifying which level files and directories are at.
- Test file checks if os used is Windows or not.
- Test file contains a test to see if the directories and files are being printed out correctly and in the right order.


## AlphabeticalFileSorter.java
## AlphabeticalFileSorter.java
- Sorts an array of files alphabetically by name, ignoring case.
- uses lambdas, a shortcut way of writing small code without giving it a name
6 changes: 4 additions & 2 deletions src/AlphabeticalFileSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
* Utility class for sorting an array of files alphabetically by name,
* ignoring case differences.
*/
public class AlphabeticalFileSorter {
public class AlphabeticalFileSorter
{

/**
* Sorts an array of files alphabetically by name, ignoring case.
*
* @param files the array of files to be sorted
* @return the sorted array of files
*/
public static File[] sort(File[] files) {
public static File[] sort(File[] files)
{
// This uses lambdas, which we haven't yet covered
// Look at it with curiosity, but you don't need to edit anything here
Arrays.sort(files, (f1, f2) -> f1.getName().compareToIgnoreCase(f2.getName()));
Expand Down
25 changes: 17 additions & 8 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

public class App {

/**
* Application for printing a directory tree
*
Expand All @@ -8,19 +9,21 @@ public class App {
* - Whether to use colored output.
* - The root directory from which to begin printing the tree.
*
* Hidden files are identified by names that start with a dot (e.g., ".hidden.txt").
* Hidden files are identified by names that start with a dot (e.g.,
* ".hidden.txt").
* Color output is enabled by default, but can be disabled using flags.
*
* Usage Example:
*
* Arguments Format: [-h] [-nc] path
*
* Flags:
* - -h : Show hidden files (defaults to false).
* - -nc : Do not use color (color is enabled by default).
* - -h : Show hidden files (defaults to false).
* - -nc : Do not use color (color is enabled by default).
*
* Path:
* - The absolute or relative path to the directory whose contents will be printed.
* - The absolute or relative path to the directory whose contents will be
* printed.
*
* Behavior:
* - If color is disabled, all text will be printed in white.
Expand All @@ -30,20 +33,26 @@ public class App {
* Examples:
*
* 1. ['-nc', '-h', '/path/to/directory']
* → Don't use color, do show hidden files.
* → Don't use color, do show hidden files.
*
* 2. ['-h', '-nc', '/path/to/directory']
* → Don't use color, do show hidden files (order of flags is ignored).
* → Don't use color, do show hidden files (order of flags is ignored).
*
* 3. ['/path/to/directory']
* → Use color, don't show hidden files.
* → Use color, don't show hidden files.
*
* Error messages will be shown for illegal arguments or a not found file
*/
public static void main(String[] args) throws Exception {
// TODO: Implement this
// You should create a TruffulaOptions object using the args and
TruffulaOptions options = new TruffulaOptions(args);

// pass it to a new TruffulaPrinter that uses System.out
TruffulaPrinter printer = new TruffulaPrinter(options);

// Then, call printTree on the TruffulaPrinter
printer.printTree();

}
}
33 changes: 24 additions & 9 deletions src/ColorPrinter.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import java.io.PrintStream;

/**
* A utility class for printing colored text to a PrintStream using ANSI escape codes.
* A utility class for printing colored text to a PrintStream using ANSI escape
* codes.
*
* The ColorPrinter allows setting a current color and printing messages in that color
* to the specified output stream. The color can be reset after each print or kept active
* The ColorPrinter allows setting a current color and printing messages in that
* color
* to the specified output stream. The color can be reset after each print or
* kept active
* based on the provided parameters.
*
* Colors are managed using the ConsoleColor enum, which defines standard ANSI color codes.
* Colors are managed using the ConsoleColor enum, which defines standard ANSI
* color codes.
*
* Example Usage:
*
* ColorPrinter printer = new ColorPrinter(System.out);
* printer.setCurrentColor(ConsoleColor.RED);
* printer.println("This is red text");
*
* The printed text will appear in the terminal with the specified colors if the terminal supports ANSI codes.
* The printed text will appear in the terminal with the specified colors if the
* terminal supports ANSI codes.
*/
public class ColorPrinter {
/**
Expand All @@ -38,7 +43,8 @@ public ConsoleColor getCurrentColor() {
}

/**
* Sets the current color for the printer. All subsequent print operations will use this color
* Sets the current color for the printer. All subsequent print operations will
* use this color
* until it is changed or reset.
*
* @param color the ConsoleColor to set as the current color
Expand All @@ -62,7 +68,8 @@ public void println(String message) {
* Optionally resets the color after printing based on the reset parameter.
*
* @param message the message to print
* @param reset if true, resets the color after printing; if false, keeps the current color
* @param reset if true, resets the color after printing; if false, keeps the
* current color
*/
public void println(String message, boolean reset) {
print(message + System.lineSeparator(), reset);
Expand All @@ -83,10 +90,18 @@ public void print(String message) {
* Optionally resets the color after printing based on the reset parameter.
*
* @param message the message to print
* @param reset if true, resets the color after printing; if false, keeps the current color
* @param reset if true, resets the color after printing; if false, keeps the
* current color
*/

public void print(String message, boolean reset) {
// TODO: Implement this!
String out = getCurrentColor() + message;

if (reset) {
out += ConsoleColor.RESET;
}

printStream.print(out);
}

/**
Expand Down
39 changes: 38 additions & 1 deletion src/ColorPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,47 @@ void testPrintlnWithRedColorAndReset() {
String message = "I speak for the trees";
printer.println(message);


String expectedOutput = ConsoleColor.RED + "I speak for the trees" + System.lineSeparator() + ConsoleColor.RESET;

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintWithCyanSingleParameterRestTrue() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);
printer.setCurrentColor(ConsoleColor.CYAN);

printer.print("Miku Miku Beeeeaaaaam");

String expected = ConsoleColor.CYAN + "Miku Miku Beeeeaaaaam" + ConsoleColor.RESET;

assertEquals(expected, outputStream.toString());
}

@Test
void testPrintWithColorAndResetFalse() {
// arrange
// this is to capture printed output
ByteArrayOutputStream output = new ByteArrayOutputStream();
PrintStream testStream = new PrintStream(output);

// this will write to the output
ColorPrinter printer = new ColorPrinter(testStream);
printer.setCurrentColor(ConsoleColor.RED);

String message = "test";

// act perform the action we are testing
// call the print method with resete to false
// the printed message will stay red and will not reset after print
printer.print(message, false);

// assert
String expected = ConsoleColor.RED.toString() + message;
assertEquals(expected, output.toString());
}
}
3 changes: 2 additions & 1 deletion src/ConsoleColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* - WHITE : White text
* - RESET : Resets the text color to default
*/
public enum ConsoleColor {
public enum ConsoleColor
{
/**
* Black text color (ANSI code: \033[0;30m).
*/
Expand Down
Loading