Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
---
## [0.0.6] - Unreleased

### Added
- Emojis: option to use custom mapping

### Changed
- Child limit: do not print skipped children count
- Max depth: do not print "max depth reached"
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ sorting/
```

## Emojis ❤️
If your terminal supports them, you can choose to use emojis.
You can choose to use default built-in emojis, or define your own emoji mapping.
Folders use the 📂 emoji, and files will have an emoji depending on their extension (when applicable).

```java
// Example: Emojis.java
var prettyPrinter = FileTreePrettyPrinter.builder()
.customizeOptions(options -> options.withEmojis(true))
.customizeOptions(options -> options.withDefaultEmojis()) // or withEmojis(EmojiMapping) for custom mapping
.build();
```

Expand All @@ -194,9 +194,6 @@ var prettyPrinter = FileTreePrettyPrinter.builder()
└─ 🎬 file.avi
```

> [!TIP]
> *Idea for a future version: option to allow custom emoji mapping*

## Child limit
You can set a fixed limit to the number of children displayed for each directory. Each directory and file that pass the filter (if set) counts for one.

Expand Down
3 changes: 1 addition & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [x] Option: filtering
- [x] Option: ordering
- [x] Option: emojis
- [x] Option: custom emojis mapping
- [x] Option: compact directories display
- [x] Option: line extension (=additional text after the file name)
- [x] Option: children limit (static & dynamic)
Expand All @@ -31,8 +32,6 @@
- [x] Publish on Maven Central!

## To do
- [ ] Option: hide number of skipped files and folders for child limit
- [ ] Option: custom emojis
- [ ] Option: custom tree format

## Backlog / To analyze / To implement if requested
Expand Down
Binary file modified assets/project-structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Emojis {

public static void main(String[] args) {
var prettyPrinter = FileTreePrettyPrinter.builder()
.customizeOptions(options -> options.withEmojis(true))
.customizeOptions(options -> options.withDefaultEmojis()) // or withEmojis(EmojiMapping) for custom mapping
.build();
var tree = prettyPrinter.prettyPrint("src/example/resources/emojis");
System.out.println(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void main(String[] args) {
var prettyPrinter = FileTreePrettyPrinter.builder()
.customizeOptions(
options -> options
.withEmojis(true) // Use emojis!
.withDefaultEmojis() // Use emojis!
.withCompactDirectories(true) // Inline directory chains: "src/main/java/..."
.filterDirectories(dirFilter)
.filterFiles(fileFilter)
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter;

import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.RenderingOptions;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.emoji.EmojiMapping;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.ScanningOptions;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
Expand Down Expand Up @@ -95,21 +96,28 @@ public PrettyPrintOptions withTreeFormat(TreeFormat treeFormat) {

// ---------- Emojis ----------

private boolean emojis = false;
private EmojiMapping emojiMapping = EmojiMapping.none();

@Override
public boolean areEmojisUsed() {
return emojis;
public EmojiMapping getEmojiMapping() {
return emojiMapping;
}

/**
* Whether or not use emojis in directory/filename rendering. Not all terminals supports emojis.
* Default is {@code false}.
* Use default emojis for directory/filename rendering.
*/
public PrettyPrintOptions withDefaultEmojis() {
this.emojiMapping = EmojiMapping.createDefault();
return this;
}

/**
* Use the given emojis mapping for directory/filename rendering.
*
* @param useEmojis {@code true} to use emojis, {@code false} otherwise.
* @see EmojiMapping
*/
public PrettyPrintOptions withEmojis(boolean useEmojis) {
this.emojis = useEmojis;
public PrettyPrintOptions withEmojis(EmojiMapping mapping) {
this.emojiMapping = Objects.requireNonNull(mapping, "mapping is null");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer;

import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.Depth;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.DepthFormatter;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file.FileFormatter;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer;

import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.emoji.EmojiMapping;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
Expand All @@ -22,7 +23,7 @@ public EmojiFileFormatter(FileFormatter decorated, EmojiMapping emojiMapping) {
}

private String getFileEmojiPrefix(Path p) {
var emoji = emojiMapping.getFileEmoji(p);
var emoji = emojiMapping.getPathEmoji(p);
return getEmojiPrefix(emoji);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer;

import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.emoji.EmojiMapping;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
Expand All @@ -9,7 +10,7 @@
import org.jspecify.annotations.NullMarked;

@NullMarked
public interface FileFormatter {
interface FileFormatter {

String formatDirectoryBegin(DirectoryEntry dirEntry, List<Path> dirs);

Expand All @@ -23,10 +24,6 @@ static FileFormatter createDefault() {
return new DefaultFileFormatter();
}

static FileFormatter wrapWithEmojis(FileFormatter decorated) {
return wrapWithEmojis(decorated, EmojiMapping.createDefault());
}

static FileFormatter wrapWithEmojis(FileFormatter decorated, EmojiMapping emojiMapping) {
return new EmojiFileFormatter(decorated, emojiMapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.Depth;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.DepthFormatter;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file.FileFormatter;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
Expand Down Expand Up @@ -31,9 +30,7 @@ static LineRenderer create(RenderingOptions options) {
var treeFormatter = DepthFormatter.getInstance(options.getTreeFormat());

var fileFormatter = FileFormatter.createDefault();
if (options.areEmojisUsed()) {
fileFormatter = FileFormatter.wrapWithEmojis(fileFormatter);
}
fileFormatter = FileFormatter.wrapWithEmojis(fileFormatter, options.getEmojiMapping());

return new DefaultLineRenderer(treeFormatter, fileFormatter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer;

import io.github.computerdaddyguy.jfiletreeprettyprinter.PrettyPrintOptions.TreeFormat;
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.emoji.EmojiMapping;
import java.nio.file.Path;
import java.util.function.Function;
import org.jspecify.annotations.NullMarked;
Expand All @@ -10,10 +11,10 @@
public interface RenderingOptions {

/**
* Are emojis used (filename, etc.)?
* The emoji mapping to use
* @return
*/
boolean areEmojisUsed();
EmojiMapping getEmojiMapping();

/**
* Are directories compacted into one entry?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.emoji;

import io.github.computerdaddyguy.jfiletreeprettyprinter.PathMatchers;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
class DefaultEmojiMapping implements EmojiMapping {

private final Function<Path, String> dirEmojis;
private final String defaultDirEmoji;

private final Function<Path, String> fileEmojis;
private final String defaultFileEmoji;

public DefaultEmojiMapping(String defaultDirEmoji, Function<Path, String> dirEmojis, String defaultFileEmoji, Function<Path, String> fileEmojis) {
super();
this.dirEmojis = Objects.requireNonNull(dirEmojis, "dirEmojis is null");
this.defaultDirEmoji = Objects.requireNonNull(defaultDirEmoji, "defaultDirEmoji is null");
this.fileEmojis = Objects.requireNonNull(fileEmojis, "fileEmojis is null");
this.defaultFileEmoji = Objects.requireNonNull(defaultFileEmoji, "defaultFileEmoji is null");
}

@Override
public @Nullable String getPathEmoji(Path path) {
return PathMatchers.isDirectory().matches(path)
? Optional.ofNullable(dirEmojis.apply(path)).orElse(defaultDirEmoji)
: Optional.ofNullable(fileEmojis.apply(path)).orElse(defaultFileEmoji);
}

}
Loading
Loading