Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8b3db8f
Wave 0 - App.java Description
xavierb117 May 13, 2025
6defd81
Added bullet point for alpabeticalFileSorter in nodes
SketchRudy May 13, 2025
cb0cd75
Merge branch 'main' of https://github.com/xavierb117/truffula
SketchRudy May 13, 2025
9216902
Wave 0 - ConsoleColor
xavierb117 May 13, 2025
e412fde
Update notes.md to add descriptions for TruffulaPrinter
SketchRudy May 13, 2025
cde3035
Merge branch 'main' of https://github.com/xavierb117/truffula
SketchRudy May 13, 2025
472088a
Wave 0 - ColorPrinter and Tests
xavierb117 May 13, 2025
a3a7cc7
Added notes for TrufullaPrinterTest
SketchRudy May 13, 2025
b9cbb0d
Merge branch 'main' of https://github.com/xavierb117/truffula
SketchRudy May 13, 2025
27723cc
Formatting
xavierb117 May 13, 2025
4e55286
Added notes for TruffulaOptionsTest
SketchRudy May 13, 2025
9dd8fab
Wave 0 - TruffulaOptions
xavierb117 May 13, 2025
26080a0
Merge branch 'main' of https://github.com/xavierb117/truffula
SketchRudy May 13, 2025
c3db3ce
Implement print method in ColorPrinter and add test for printing with…
SketchRudy May 16, 2025
b6c4746
Add test for printing with black color without reset
SketchRudy May 16, 2025
7996cde
Added a couple more tests
xavierb117 May 16, 2025
fb18afc
Add main method to ColorPrinter and new tests for cyan and green prin…
SketchRudy May 16, 2025
e4d7188
Initial solution for TruffulaOptions
xavierb117 May 17, 2025
4b1b969
Added secondTest
SketchRudy May 17, 2025
4f8859f
Add tests for TruffulaOptions handling of hidden files and argument v…
SketchRudy May 17, 2025
ec533be
Added ordered test
xavierb117 May 17, 2025
1196c8e
Test for no arguments
xavierb117 May 17, 2025
83dfea7
Add error handling for invalid flags in TruffulaOptions and correspon…
xavierb117 May 17, 2025
c4fae8e
Merge branch 'main' of https://github.com/xavierb117/truffula
SketchRudy May 17, 2025
186923c
Made some improvements to the options method and created new tests
xavierb117 May 19, 2025
c642e5c
Initial solution for wave 3 passing all messsages
xavierb117 May 19, 2025
df511d1
Implement directory tree printing in TruffulaPrinter with color suppo…
SketchRudy May 24, 2025
eacf1ba
Initial solution for wave 4, 5, 6, and 7
xavierb117 May 27, 2025
cd2c74b
Initial tests for wave 4
xavierb117 May 27, 2025
b113328
Tests for Wave 5
xavierb117 May 27, 2025
f46b4d4
Add test for case-insensitive sorting in printTree method
SketchRudy May 27, 2025
8a6cee4
Add tests for printing directory trees with and without hidden files
SketchRudy May 27, 2025
78d2cb3
Add test for case-insensitive sorting with special filenames in print…
SketchRudy May 27, 2025
0797bad
Tests for wave 6
xavierb117 May 27, 2025
478a86e
Merge branch 'main' of https://github.com/xavierb117/truffula
xavierb117 May 27, 2025
5d2f511
Add null check for givenFiles in TruffulaPrinter to prevent NullPoint…
SketchRudy 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
2 changes: 1 addition & 1 deletion instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The provided tests are VERY MINIMAL. You are expected to be adding thorough test
You must NOT use the `java.nio` package for any wave! You can only use `java.io`.

## Wave 0: Understand
In this wave you will be working to undertsand the files that are provided for you. Open `notes.md` to see a list of the files in the order I recommend you look at them. For each file, write notes in `notes.md` summarizing your understanding and putting down any questions you want to better understand later. This will take a long time, but it is worth it! Do not skimp on this part, you will regret it! A very large part of this project is understanding the OOP structure.
In this wave you will be working to understand the files that are provided for you. Open `notes.md` to see a list of the files in the order I recommend you look at them. For each file, write notes in `notes.md` summarizing your understanding and putting down any questions you want to better understand later. This will take a long time, but it is worth it! Do not skimp on this part, you will regret it! A very large part of this project is understanding the OOP structure.

Make frequent commits to your `notes.md` as you learn.

Expand Down
27 changes: 26 additions & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@ 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
- This is the application for printing a directory tree, must be done manually
- There are options to show hidden files that start with a dot, and handle colored output
- OOP Heavy, create TruffulaOptions using args and pass it to TruffulaPrinter

## ConsoleColor.java
- This is an Enum representing ANSI escape codes for colored output
- Used to format console output by applying colors to texts
- Makes use of Enum, which will be researched in order to solve

## ColorPrinter.java / ColorPrinterTest.java
- Printer helps print colored text to a PrintStream. Tests help test for the color of the text
- Printer should apply specified colors in terminal. Tests must be written manually
- Colors will be managed by ConsoleColor

## TruffulaOptions.java / TruffulaOptionsTest.java
TruffulaOptions:
- Represents the configuration options for controlling how a directory tree is displayed, including hidden files and colored output
- Includes the root directory from which to begin printing the tree
- -h and -nc are the flags to determine display, path is mandatory
TruffulaOptionsTest:
- We test to see if the directory we're calling Truffula in is a working directory or if there is an error such as
corruption, no network detected, etc.


## TruffulaPrinter.java / TruffulaPrinterTest.java
TrufullaPrinter:
- Prints out the directory and optional colors if selected/inputted
- Same methods with different signature/parameters; Whichever argument is selected is the method that will be used
TrufullaPrinterTest:
- Checks the os system and creates a hidden file in a specified folder (file name must start with . which indicates it is a hidden folder)
- This test will let us know if the program works correctly

## AlphabeticalFileSorter.java
## AlphabeticalFileSorter.java
- Looks over the files, grabs two at a time and compares sorts them alphabetically, then repeats for the entire file directory you're in.
- What happens to the method if there's only one file in the directory?
3 changes: 3 additions & 0 deletions src/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ public static void main(String[] args) throws Exception {
// You should create a TruffulaOptions object using the args and
// pass it to a new TruffulaPrinter that uses System.out
// Then, call printTree on the TruffulaPrinter
TruffulaOptions chosenOptions = new TruffulaOptions(args);
TruffulaPrinter printFiles = new TruffulaPrinter(chosenOptions);
printFiles.printTree();
}
}
15 changes: 15 additions & 0 deletions src/ColorPrinter.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.awt.Color;
import java.io.PrintStream;

/**
Expand All @@ -18,6 +19,12 @@
* The printed text will appear in the terminal with the specified colors if the terminal supports ANSI codes.
*/
public class ColorPrinter {
public static void main (String[] args) {
ColorPrinter printer = new ColorPrinter(System.out, ConsoleColor.RED);
// printer.setCurrentColor(ConsoleColor.RED);
printer.println("This is red text");
printer.println("Now the message is white");
}
/**
* The current color used for printing.
*/
Expand Down Expand Up @@ -87,6 +94,14 @@ public void print(String message) {
*/
public void print(String message, boolean reset) {
// TODO: Implement this!

if (reset == true) {
// setCurrentColor(ConsoleColor.RESET);
printStream.print(getCurrentColor() + message + ConsoleColor.RESET);
}
if (reset == false) {
printStream.print(getCurrentColor() + message);
}
}

/**
Expand Down
113 changes: 113 additions & 0 deletions src/ColorPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,117 @@ void testPrintlnWithRedColorAndReset() {
// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintWithBlueColorAndReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

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

// Act: print the emssage
String message = "I am the lorax";
printer.print(message);

String expectedOutput = ConsoleColor.BLUE + "I am the lorax" + ConsoleColor.RESET;

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

@Test
void testPrintWithBlackColorWithNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

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

// Act: print the emssage
String message = "The Oncelor";
printer.print(message, false);

String expectedOutput = ConsoleColor.BLACK + "The Oncelor";

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

@Test
void testPrintlnWithPurpleColorWithNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

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

// Act: print the emssage
String message = "";
printer.println(message, false);

String expectedOutput = ConsoleColor.PURPLE + "" + System.lineSeparator();

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

@Test
void testPrintlnWithDefaultColorWithReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);

// Act: print the emssage
String message = "Mr. O'Hare";
printer.println(message, true);

String expectedOutput = ConsoleColor.WHITE + "Mr. O'Hare" + System.lineSeparator() + ConsoleColor.RESET;

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

@Test
void testPrintlnWithCyanAnsiAsCyanTextColorWithReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

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

// Act: print the emssage
String message = "\033[0;36m";
printer.println(message, true);

String expectedOutput = ConsoleColor.CYAN + "\033[0;36m" + System.lineSeparator() + ConsoleColor.RESET;

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

@Test
void testprintWithOnlySpacesCharactersAsGreen() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

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

// Act: print the emssage
String message = " ";
printer.print(message, false);

String expectedOutput = ConsoleColor.GREEN + " ";

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}
}
44 changes: 41 additions & 3 deletions src/TruffulaOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,47 @@ public boolean isUseColor() {
*/
public TruffulaOptions(String[] args) throws IllegalArgumentException, FileNotFoundException {
// TODO: Replace the below lines with your implementation
root = null;
showHidden = false;
useColor = false;
if (args.length == 0) {
throw new IllegalArgumentException("No arguments provided.");
}

boolean hiddenFile = false;
boolean colors = true;
for (int i = 0; i < args.length - 1; i++) {
if (args[i].equals("-h")) {
hiddenFile = true;
}
else if (args[i].equals("-nc")) {
colors = false;
}
else {
throw new IllegalArgumentException("Unknown flag: " + args[i]);
}
}

File file = null;
if (!args[args.length - 1].equals("-nc") && !args[args.length - 1].equals("-h")) {
file = new File(args[args.length - 1]);
}
else {
file = null;
}

showHidden = hiddenFile;
useColor = colors;
root = file;

if (root == null) {
throw new IllegalArgumentException("Path is missing");
}

if (!root.exists()) {
throw new FileNotFoundException("Could not find directory");
}

if (!root.isDirectory()) {
throw new FileNotFoundException("Path is not directory");
}
}

/**
Expand Down
Loading