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
7 changes: 4 additions & 3 deletions cli/src/main/java/io/github/dfa1/vortex/cli/CliHandles.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

/// Shared handle plumbing for the interactive subcommands (`view`, `tui`).
Expand All @@ -27,10 +28,10 @@ private CliHandles() {
///
/// @param worker the I/O worker that owns the handle's arena
/// @param target a local path or an `http(s)://` URL
/// @return the opened handle, or `null` if the target is missing or malformed
/// @return the opened handle, or empty if the target is missing or malformed
/// @throws InterruptedException if interrupted while waiting on the worker
/// @throws IOException if opening the file or URL fails
static VortexHandle openOnWorker(IoWorker worker, String target)
static Optional<VortexHandle> openOnWorker(IoWorker worker, String target)
throws InterruptedException, IOException {
AtomicReference<VortexHandle> handle = new AtomicReference<>();
AtomicReference<IOException> failure = new AtomicReference<>();
Expand All @@ -44,7 +45,7 @@ static VortexHandle openOnWorker(IoWorker worker, String target)
if (failure.get() != null) {
throw failure.get();
}
return handle.get();
return Optional.ofNullable(handle.get());
}

/// Closes `handle` on the worker thread that opened it.
Expand Down
6 changes: 4 additions & 2 deletions cli/src/main/java/io/github/dfa1/vortex/cli/TuiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.IOException;
import java.io.PrintStream;
import java.util.Optional;

final class TuiCommand {

Expand All @@ -19,10 +20,11 @@ static int run(String[] args) {
return ExitStatus.USAGE_ERROR;
}
try (IoWorker worker = new IoWorker("vortex-tui-io")) {
VortexHandle handle = CliHandles.openOnWorker(worker, args[1]);
if (handle == null) {
Optional<VortexHandle> opened = CliHandles.openOnWorker(worker, args[1]);
if (opened.isEmpty()) {
return ExitStatus.FILE_NOT_FOUND;
}
VortexHandle handle = opened.get();
try {
VortexInspectorTui.show(handle, worker, progressBar(System.err));
} finally {
Expand Down
28 changes: 16 additions & 12 deletions cli/src/main/java/io/github/dfa1/vortex/cli/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.dfa1.vortex.reader.VortexHandle;

import java.io.IOException;
import java.util.Optional;

@SuppressWarnings("java:S106")
final class ViewCommand {
Expand All @@ -22,24 +23,27 @@ static int run(String[] args) {
System.err.print("Opening file... ");
System.err.flush();
long tOpen = System.nanoTime();
VortexHandle handle = CliHandles.openOnWorker(worker, args[1]);
if (handle == null) {
Optional<VortexHandle> opened = CliHandles.openOnWorker(worker, args[1]);
if (opened.isEmpty()) {
return ExitStatus.FILE_NOT_FOUND;
}
System.err.println("done (" + (System.nanoTime() - tOpen) / 1_000_000L + " ms)");
VortexHandle handle = opened.get();
try {
System.err.println("done (" + (System.nanoTime() - tOpen) / 1_000_000L + " ms)");

System.err.print("Indexing chunks... ");
System.err.flush();
long tIdx = System.nanoTime();
try (LazyGridSource source = LazyGridSource.open(handle, worker)) {
long ms = (System.nanoTime() - tIdx) / 1_000_000L;
System.err.println("done — " + source.totalRows() + " rows × "
+ source.columns().size() + " cols (" + ms + " ms)");
VortexGridTui.show(args[1], source);
System.err.print("Indexing chunks... ");
System.err.flush();
long tIdx = System.nanoTime();
try (LazyGridSource source = LazyGridSource.open(handle, worker)) {
long ms = (System.nanoTime() - tIdx) / 1_000_000L;
System.err.println("done — " + source.totalRows() + " rows × "
+ source.columns().size() + " cols (" + ms + " ms)");
VortexGridTui.show(args[1], source);
}
return ExitStatus.OK;
} finally {
CliHandles.closeOnWorker(worker, handle);
}
return ExitStatus.OK;
} catch (IOException | RuntimeException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
Expand Down