Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Give commands access to input stream. #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.codeaffine.console.calculator.internal;

import java.io.InputStream;

import com.codeaffine.console.core.ConsoleCommandInterpreter;
import com.codeaffine.console.core.ConsoleComponentFactory;
import com.codeaffine.console.core.ConsoleOutput;
Expand All @@ -20,7 +22,7 @@ public ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput ) {
}

@Override
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) {
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) {
return new ConsoleCommandInterpreter[] { new CalculatorConsoleCommandInterpreter( stdOut ) };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.codeaffine.console.core.pdetest.console;

import java.io.InputStream;

import com.codeaffine.console.core.ConsoleCommandInterpreter;
import com.codeaffine.console.core.ConsoleComponentFactory;
import com.codeaffine.console.core.ConsoleOutput;
Expand All @@ -15,7 +17,7 @@ public ConsolePrompt createConsolePrompt( final ConsoleOutput consoleOutput ) {
}

@Override
public ConsoleCommandInterpreter[] createCommandInterpreters( final ConsoleOutput stdOut, ConsoleOutput errorOut ) {
public ConsoleCommandInterpreter[] createCommandInterpreters( final ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) {
return new ConsoleCommandInterpreter[] { new TestConsoleCommandInterpreter( stdOut ) };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.codeaffine.console.core;

import java.io.InputStream;

import com.codeaffine.console.core.history.HistoryTracker;


public interface ConsoleComponentFactory {
ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut );
ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn );
ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput );
ContentProposalProvider[] createProposalProviders();
HistoryTracker getHistoryTracker();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codeaffine.console.core.internal;

import java.io.InputStream;
import java.util.stream.Stream;

import com.codeaffine.console.core.ConsoleCommandInterpreter;
Expand Down Expand Up @@ -37,8 +38,8 @@ public ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput ) {
}

@Override
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) {
ConsoleCommandInterpreter[] result = consoleComponentFactory.createCommandInterpreters( stdOut, errorOut );
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) {
ConsoleCommandInterpreter[] result = consoleComponentFactory.createCommandInterpreters( stdOut, errorOut, stdIn );
if( getHistoryTracker() != null ) {
result = Stream.concat( Stream.of( getHistoryTracker() ), Stream.of( result ) ).toArray( ConsoleCommandInterpreter[]::new );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.codeaffine.console.core.ConsoleConstants.ENCODING;

import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;

Expand All @@ -17,7 +18,7 @@ public Input( ConsoleIoProvider consoleIoProvider ) {

@SuppressWarnings("resource")
public String readLine() {
Scanner scanner = new Scanner( consoleIOProvider.getInputStream(), ENCODING.name() );
Scanner scanner = new Scanner( getInputStream(), ENCODING.name() );
String result;
try {
result = scanner.nextLine();
Expand All @@ -26,4 +27,8 @@ public String readLine() {
}
return result;
}

public InputStream getInputStream() {
return consoleIOProvider.getInputStream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void run() {

private ConsoleCommandInterpreter[] createCommandInterpreters() {
return consoleComponentFactory.createCommandInterpreters( consoleStandardOutput,
consoleErrorOutput );
consoleErrorOutput,
consoleInput.getInputStream() );
}

private static void printStackTrace( ConsoleOutput consoleOutput, Exception exception ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static com.codeaffine.gonsole.internal.activator.IconRegistry.GIT_PROPOSAL;

import java.io.InputStream;

import org.eclipse.jface.resource.ImageDescriptor;

import com.codeaffine.console.core.ConsoleCommandInterpreter;
Expand Down Expand Up @@ -29,7 +31,7 @@ class GitConsoleComponentFactory implements ConsoleComponentFactory {
}

@Override
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) {
public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) {
return new ConsoleCommandInterpreter[]{
new ControlCommandInterpreter( this, stdOut, errorOut, repositoryProvider ),
new GitCommandInterpreter( stdOut, repositoryProvider )
Expand Down