From bab17f5c9494c04295cf4a0403506ff283ed8158 Mon Sep 17 00:00:00 2001 From: mahala Date: Thu, 19 Mar 2026 21:39:51 -0400 Subject: [PATCH 1/6] Format --- README.md => READ GENERAL.md | 0 java/PhaseNote.java | 145 +++++++++++++++++++++++++++++ java/{README.md => README JAVA.md} | 0 3 files changed, 145 insertions(+) rename README.md => READ GENERAL.md (100%) create mode 100644 java/PhaseNote.java rename java/{README.md => README JAVA.md} (100%) diff --git a/README.md b/READ GENERAL.md similarity index 100% rename from README.md rename to READ GENERAL.md diff --git a/java/PhaseNote.java b/java/PhaseNote.java new file mode 100644 index 0000000..86465f6 --- /dev/null +++ b/java/PhaseNote.java @@ -0,0 +1,145 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; +import java.util.stream.Collectors; + +public class PhaseNote { + private static final Path NOTES_DIR = Path.of(System.getProperty("user.home"), ".notes"); + + public static void main(String[] args) { + if (args.length < 1) { + System.err.println("Error: No command provided."); + System.err.println("Usage: java PhaseNote [command]"); + System.err.println("Try 'java PhaseNote help' for more information."); + System.exit(1); + } + + String command = args[0].toLowerCase(); + switch (command) { + case "help" -> { + showHelp(); + System.exit(0); + } + case "list" -> { + boolean success = listNotes(NOTES_DIR); + System.exit(success ? 0 : 1); + } + default -> { + System.err.println("Error: Unknown command '" + command + "'"); + System.err.println("Try 'java PhaseNote help' for more information."); + System.exit(1); + } + } + } + + private static Map parseYamlHeader(Path path) { + Map metadata = new HashMap<>(); + metadata.put("file", path.getFileName().toString()); + + try { + List lines = Files.readAllLines(path); + if (lines.isEmpty() || !lines.get(0).trim().equals("---")) { + metadata.put("title", path.getFileName().toString()); + return metadata; + } + + // Find the closing --- + int closingIndex = -1; + for (int i = 1; i < lines.size(); i++) { + if (lines.get(i).trim().equals("---")) { + closingIndex = i; + break; + } + } + + if (closingIndex == -1) { + metadata.put("title", path.getFileName().toString()); + return metadata; + } + + // Parse key-value pairs between the markers + for (int i = 1; i < closingIndex; i++) { + String line = lines.get(i).trim(); + if (line.contains(":")) { + String[] parts = line.split(":", 2); + metadata.put(parts[0].trim(), parts[1].trim()); + } + } + } catch (IOException e) { + metadata.put("error", e.getMessage()); + } + + return metadata; + } + + private static boolean listNotes(Path baseDir) { + if (!Files.exists(baseDir)) { + System.err.println("Error: Notes directory does not exist: " + baseDir); + System.err.println("Create it with: mkdir -p ~/.notes/notes"); + return false; + } + + Path searchPath = Files.exists(baseDir.resolve("notes")) ? baseDir.resolve("notes") : baseDir; + List noteFiles; + + try (Stream walk = Files.walk(searchPath, 1)) { + noteFiles = walk + .filter(Files::isRegularFile) + .filter(p -> { + String name = p.getFileName().toString(); + return name.endsWith(".md") || name.endsWith(".note") || name.endsWith(".txt"); + }) + .sorted() + .collect(Collectors.toList()); + } catch (IOException e) { + System.err.println("Error reading notes directory: " + e.getMessage()); + return false; + } + + if (noteFiles.isEmpty()) { + System.out.println("No notes found in " + baseDir); + return true; + } + + System.out.println("Notes in " + baseDir + ":"); + System.out.println("=".repeat(60)); + + for (Path file : noteFiles) { + Map metadata = parseYamlHeader(file); + String title = metadata.getOrDefault("title", file.getFileName().toString()); + String created = metadata.getOrDefault("created", "N/A"); + String tags = metadata.getOrDefault("tags", ""); + + System.out.println("\n" + file.getFileName()); + System.out.println(" Title: " + title); + if (!"N/A".equals(created)) System.out.println(" Created: " + created); + if (!tags.isEmpty()) System.out.println(" Tags: " + tags); + } + + System.out.println("\n" + noteFiles.size() + " note(s) found."); + return true; + } + + private static void showHelp() { + String helpText = String.format(""" + Future Proof Notes Manager v0.1 + + Usage: java PhaseNote [command] + + Available commands: + help - Display this help information + list - List all notes in the notes directory + + Notes directory: %s + + Setup: + mkdir -p ~/.notes/notes + cp test-notes/*.md ~/.notes/notes/ + """, NOTES_DIR); + System.out.println(helpText.trim()); + } +} diff --git a/java/README.md b/java/README JAVA.md similarity index 100% rename from java/README.md rename to java/README JAVA.md From 2777ac6121d64b3d41198945701d437d530f05c6 Mon Sep 17 00:00:00 2001 From: mahala Date: Fri, 20 Mar 2026 10:57:04 -0400 Subject: [PATCH 2/6] Added a Comment --- java/PhaseNote.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/PhaseNote.java b/java/PhaseNote.java index 86465f6..6fc0ffd 100644 --- a/java/PhaseNote.java +++ b/java/PhaseNote.java @@ -7,6 +7,7 @@ import java.util.stream.Stream; import java.util.stream.Collectors; +// Start of Phase 1 Notes public class PhaseNote { private static final Path NOTES_DIR = Path.of(System.getProperty("user.home"), ".notes"); From 0a296875ecad9997de7f3daa29c7516bdfdaba33 Mon Sep 17 00:00:00 2001 From: mahala Date: Fri, 20 Mar 2026 11:19:31 -0400 Subject: [PATCH 3/6] Add createnote --- java/PhaseNote.java | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/java/PhaseNote.java b/java/PhaseNote.java index 6fc0ffd..bd32f62 100644 --- a/java/PhaseNote.java +++ b/java/PhaseNote.java @@ -29,6 +29,10 @@ public static void main(String[] args) { boolean success = listNotes(NOTES_DIR); System.exit(success ? 0 : 1); } + case "create" -> { + boolean success = createNote(NOTES_DIR); + System.exit(success ? 0 : 1); + } default -> { System.err.println("Error: Unknown command '" + command + "'"); System.err.println("Try 'java PhaseNote help' for more information."); @@ -125,6 +129,50 @@ private static boolean listNotes(Path baseDir) { return true; } + + // createNote + private static boolean createNote(Path baseDir) { + if (!Files.exists(baseDir)) { + System.err.println("Error: Notes directory does not exist: " + baseDir); + System.err.println("Create it with: mkdir -p ~/.notes/notes"); + return false; + } + + Path notesPath = baseDir.resolve("notes"); + if (!Files.exists(notesPath)) { + try { + Files.createDirectories(notesPath); + } catch (IOException e) { + System.err.println("Error creating notes directory: " + e.getMessage()); + return false; + } + } + + try { + // Create a new note with timestamp-based filename + String timestamp = java.time.LocalDateTime.now().format( + java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")); + String filename = "note_" + timestamp + ".md"; + Path newNotePath = notesPath.resolve(filename); + + // Create note content with YAML header + String noteContent = String.format(""" + --- + title: New Note + created: %s + tags: + --- + + """, java.time.LocalDate.now().toString()); + + Files.writeString(newNotePath, noteContent); + System.out.println("Note created successfully: " + newNotePath); + return true; + } catch (IOException e) { + System.err.println("Error creating note: " + e.getMessage()); + return false; + } + } private static void showHelp() { String helpText = String.format(""" Future Proof Notes Manager v0.1 From 5a0804014b1cae326a2e0a4c6f7199cbbe2bcc44 Mon Sep 17 00:00:00 2001 From: mahala Date: Fri, 20 Mar 2026 11:38:47 -0400 Subject: [PATCH 4/6] Added read by number --- java/PhaseNote.java | 68 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/java/PhaseNote.java b/java/PhaseNote.java index bd32f62..325f939 100644 --- a/java/PhaseNote.java +++ b/java/PhaseNote.java @@ -33,6 +33,21 @@ public static void main(String[] args) { boolean success = createNote(NOTES_DIR); System.exit(success ? 0 : 1); } + case "read" -> { + if (args.length < 2) { + System.err.println("Error: No note number provided."); + System.err.println("Usage: java PhaseNote read [note-number]"); + System.exit(1); + } + try { + int noteNumber = Integer.parseInt(args[1]); + boolean success = readNote(NOTES_DIR, noteNumber); + System.exit(success ? 0 : 1); + } catch (NumberFormatException e) { + System.err.println("Error: Invalid note number '" + args[1] + "'"); + System.exit(1); + } + } default -> { System.err.println("Error: Unknown command '" + command + "'"); System.err.println("Try 'java PhaseNote help' for more information."); @@ -113,13 +128,14 @@ private static boolean listNotes(Path baseDir) { System.out.println("Notes in " + baseDir + ":"); System.out.println("=".repeat(60)); - for (Path file : noteFiles) { + for (int i = 0; i < noteFiles.size(); i++) { + Path file = noteFiles.get(i); Map metadata = parseYamlHeader(file); String title = metadata.getOrDefault("title", file.getFileName().toString()); String created = metadata.getOrDefault("created", "N/A"); String tags = metadata.getOrDefault("tags", ""); - System.out.println("\n" + file.getFileName()); + System.out.println("\n[" + (i + 1) + "] " + file.getFileName()); System.out.println(" Title: " + title); if (!"N/A".equals(created)) System.out.println(" Created: " + created); if (!tags.isEmpty()) System.out.println(" Tags: " + tags); @@ -173,6 +189,48 @@ private static boolean createNote(Path baseDir) { return false; } } + + // readNote + private static boolean readNote(Path baseDir, int noteNumber) { + if (!Files.exists(baseDir)) { + System.err.println("Error: Notes directory does not exist: " + baseDir); + return false; + } + + Path searchPath = Files.exists(baseDir.resolve("notes")) ? baseDir.resolve("notes") : baseDir; + List noteFiles; + + try (Stream walk = Files.walk(searchPath, 1)) { + noteFiles = walk + .filter(Files::isRegularFile) + .filter(p -> { + String name = p.getFileName().toString(); + return name.endsWith(".md") || name.endsWith(".note") || name.endsWith(".txt"); + }) + .sorted() + .collect(Collectors.toList()); + } catch (IOException e) { + System.err.println("Error reading notes directory: " + e.getMessage()); + return false; + } + + // Check if note number is valid + if (noteNumber < 1 || noteNumber > noteFiles.size()) { + System.err.println("Error: Note number " + noteNumber + " not found. Valid range: 1-" + noteFiles.size()); + return false; + } + + try { + Path notePath = noteFiles.get(noteNumber - 1); + String content = Files.readString(notePath); + System.out.println(content); + return true; + } catch (IOException e) { + System.err.println("Error reading note: " + e.getMessage()); + return false; + } + } + private static void showHelp() { String helpText = String.format(""" Future Proof Notes Manager v0.1 @@ -182,6 +240,12 @@ private static void showHelp() { Available commands: help - Display this help information list - List all notes in the notes directory + create - Create a new note + read - Read a note by number (use list to see note numbers) + + Examples: + java PhaseNote list + java PhaseNote read 1 Notes directory: %s From 23152cd8555cd153b0d0f9b5e7f05c671904ac12 Mon Sep 17 00:00:00 2001 From: mahala Date: Fri, 20 Mar 2026 11:50:34 -0400 Subject: [PATCH 5/6] Added Delete Method --- java/PhaseNote.java | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/java/PhaseNote.java b/java/PhaseNote.java index 325f939..6ead5cf 100644 --- a/java/PhaseNote.java +++ b/java/PhaseNote.java @@ -48,6 +48,21 @@ public static void main(String[] args) { System.exit(1); } } + case "delete" -> { + if (args.length < 2) { + System.err.println("Error: No note number provided."); + System.err.println("Usage: java PhaseNote delete [note-number]"); + System.exit(1); + } + try { + int noteNumber = Integer.parseInt(args[1]); + boolean success = deleteNote(NOTES_DIR, noteNumber); + System.exit(success ? 0 : 1); + } catch (NumberFormatException e) { + System.err.println("Error: Invalid note number '" + args[1] + "'"); + System.exit(1); + } + } default -> { System.err.println("Error: Unknown command '" + command + "'"); System.err.println("Try 'java PhaseNote help' for more information."); @@ -231,6 +246,47 @@ private static boolean readNote(Path baseDir, int noteNumber) { } } + // deleteNote + private static boolean deleteNote(Path baseDir, int noteNumber) { + if (!Files.exists(baseDir)) { + System.err.println("Error: Notes directory does not exist: " + baseDir); + return false; + } + + Path searchPath = Files.exists(baseDir.resolve("notes")) ? baseDir.resolve("notes") : baseDir; + List noteFiles; + + try (Stream walk = Files.walk(searchPath, 1)) { + noteFiles = walk + .filter(Files::isRegularFile) + .filter(p -> { + String name = p.getFileName().toString(); + return name.endsWith(".md") || name.endsWith(".note") || name.endsWith(".txt"); + }) + .sorted() + .collect(Collectors.toList()); + } catch (IOException e) { + System.err.println("Error reading notes directory: " + e.getMessage()); + return false; + } + + // Check if note number is valid + if (noteNumber < 1 || noteNumber > noteFiles.size()) { + System.err.println("Error: Note number " + noteNumber + " not found. Valid range: 1-" + noteFiles.size()); + return false; + } + + try { + Path notePath = noteFiles.get(noteNumber - 1); + Files.delete(notePath); + System.out.println("Note deleted successfully: " + notePath.getFileName()); + return true; + } catch (IOException e) { + System.err.println("Error deleting note: " + e.getMessage()); + return false; + } + } + private static void showHelp() { String helpText = String.format(""" Future Proof Notes Manager v0.1 @@ -242,10 +298,12 @@ private static void showHelp() { list - List all notes in the notes directory create - Create a new note read - Read a note by number (use list to see note numbers) + delete - Delete a note by number (use list to see note numbers) Examples: java PhaseNote list java PhaseNote read 1 + java PhaseNote delete 1 Notes directory: %s From 5e1db13a45064b7aada5b81782370f24b1f52a84 Mon Sep 17 00:00:00 2001 From: mahala Date: Fri, 20 Mar 2026 15:56:59 -0400 Subject: [PATCH 6/6] Added edit method --- java/PhaseNote.java | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/java/PhaseNote.java b/java/PhaseNote.java index 6ead5cf..d2ef1c1 100644 --- a/java/PhaseNote.java +++ b/java/PhaseNote.java @@ -63,6 +63,21 @@ public static void main(String[] args) { System.exit(1); } } + case "edit" -> { + if (args.length < 2) { + System.err.println("Error: No note number provided."); + System.err.println("Usage: java PhaseNote edit [note-number]"); + System.exit(1); + } + try { + int noteNumber = Integer.parseInt(args[1]); + boolean success = editNote(NOTES_DIR, noteNumber); + System.exit(success ? 0 : 1); + } catch (NumberFormatException e) { + System.err.println("Error: Invalid note number '" + args[1] + "'"); + System.exit(1); + } + } default -> { System.err.println("Error: Unknown command '" + command + "'"); System.err.println("Try 'java PhaseNote help' for more information."); @@ -287,6 +302,71 @@ private static boolean deleteNote(Path baseDir, int noteNumber) { } } + // editNote + private static boolean editNote(Path baseDir, int noteNumber) { + if (!Files.exists(baseDir)) { + System.err.println("Error: Notes directory does not exist: " + baseDir); + return false; + } + + Path searchPath = Files.exists(baseDir.resolve("notes")) ? baseDir.resolve("notes") : baseDir; + List noteFiles; + + try (Stream walk = Files.walk(searchPath, 1)) { + noteFiles = walk + .filter(Files::isRegularFile) + .filter(p -> { + String name = p.getFileName().toString(); + return name.endsWith(".md") || name.endsWith(".note") || name.endsWith(".txt"); + }) + .sorted() + .collect(Collectors.toList()); + } catch (IOException e) { + System.err.println("Error reading notes directory: " + e.getMessage()); + return false; + } + + // Check if note number is valid + if (noteNumber < 1 || noteNumber > noteFiles.size()) { + System.err.println("Error: Note number " + noteNumber + " not found. Valid range: 1-" + noteFiles.size()); + return false; + } + + try { + Path notePath = noteFiles.get(noteNumber - 1); + + // Read current content + String currentContent = Files.readString(notePath); + System.out.println("Current note content:"); + System.out.println("=".repeat(60)); + System.out.println(currentContent); + System.out.println("=".repeat(60)); + + // Open editor for user input + System.out.print("Enter new content (or type 'quit' on a new line to cancel):\n"); + java.util.Scanner scanner = new java.util.Scanner(System.in); + StringBuilder newContent = new StringBuilder(); + String line; + + while (scanner.hasNextLine()) { + line = scanner.nextLine(); + if (line.equals("quit")) { + System.out.println("Edit cancelled."); + return false; + } + newContent.append(line).append("\n"); + } + + // Write updated content back to file + Files.writeString(notePath, newContent.toString()); + System.out.println("Note updated successfully: " + notePath.getFileName()); + return true; + } catch (IOException e) { + System.err.println("Error editing note: " + e.getMessage()); + return false; + } + } + private static void showHelp() { String helpText = String.format(""" Future Proof Notes Manager v0.1 @@ -298,11 +378,13 @@ private static void showHelp() { list - List all notes in the notes directory create - Create a new note read - Read a note by number (use list to see note numbers) + edit - Edit a note by number (use list to see note numbers) delete - Delete a note by number (use list to see note numbers) Examples: java PhaseNote list java PhaseNote read 1 + java PhaseNote edit 1 java PhaseNote delete 1 Notes directory: %s