-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
239 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
shell/impl/src/main/java/org/jboss/forge/addon/shell/aesh/completion/CompletionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jboss.forge.addon.shell.aesh.completion; | ||
|
||
import org.jboss.aesh.complete.CompleteOperation; | ||
import org.jboss.forge.addon.shell.ui.ShellContext; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
|
||
/** | ||
* Typed completion | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface CompletionStrategy | ||
{ | ||
/** | ||
* Invoked when an autocomplete for a specific component is required | ||
* | ||
* @param completeOperation | ||
* @param input | ||
* @param context | ||
* @param typedValue | ||
*/ | ||
public void complete(CompleteOperation completeOperation, InputComponent<?, Object> input, ShellContext context, | ||
String typedValue); | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/main/java/org/jboss/forge/addon/shell/aesh/completion/CompletionStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jboss.forge.addon.shell.aesh.completion; | ||
|
||
import org.jboss.forge.addon.ui.facets.HintsFacet; | ||
import org.jboss.forge.addon.ui.hints.InputType; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
|
||
/** | ||
* Returns the completion based on the input component | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class CompletionStrategyFactory | ||
{ | ||
public static CompletionStrategy getCompletionFor(InputComponent<?, Object> component) | ||
{ | ||
InputType inputType = component.getFacet(HintsFacet.class).getInputType(); | ||
switch (inputType) | ||
{ | ||
case FILE_PICKER: | ||
return new FileInputCompletionStrategy(false); | ||
case DIRECTORY_PICKER: | ||
return new FileInputCompletionStrategy(true); | ||
default: | ||
return new DefaultInputCompletionStrategy(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/org/jboss/forge/addon/shell/aesh/completion/DefaultInputCompletionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jboss.forge.addon.shell.aesh.completion; | ||
|
||
import org.jboss.aesh.complete.CompleteOperation; | ||
import org.jboss.forge.addon.shell.ui.ShellContext; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
import org.jboss.forge.addon.ui.input.UICompleter; | ||
import org.jboss.forge.addon.ui.util.InputComponents; | ||
|
||
public class DefaultInputCompletionStrategy implements CompletionStrategy | ||
{ | ||
@Override | ||
public void complete(CompleteOperation completeOperation, InputComponent<?, Object> input, ShellContext context, | ||
String typedValue) | ||
{ | ||
UICompleter<Object> completer = InputComponents.getCompleterFor(input); | ||
if (completer != null) | ||
{ | ||
for (String proposal : completer.getCompletionProposals(context, input, typedValue)) | ||
{ | ||
completeOperation.addCompletionCandidate(proposal); | ||
} | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/org/jboss/forge/addon/shell/aesh/completion/FileInputCompletionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jboss.forge.addon.shell.aesh.completion; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.aesh.complete.CompleteOperation; | ||
import org.jboss.aesh.util.FileLister; | ||
import org.jboss.forge.addon.resource.FileResource; | ||
import org.jboss.forge.addon.shell.ui.ShellContext; | ||
import org.jboss.forge.addon.ui.context.UISelection; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
import org.jboss.forge.addon.ui.util.InputComponents; | ||
import org.jboss.forge.furnace.util.OperatingSystemUtils; | ||
|
||
class FileInputCompletionStrategy implements CompletionStrategy | ||
{ | ||
|
||
private final boolean directory; | ||
|
||
public FileInputCompletionStrategy(boolean directory) | ||
{ | ||
this.directory = directory; | ||
} | ||
|
||
@Override | ||
public void complete(CompleteOperation completeOperation, InputComponent<?, Object> input, ShellContext context, | ||
String typedValue) | ||
{ | ||
completeOperation.setOffset(completeOperation.getCursor()); | ||
|
||
final File cwd; | ||
Object value = InputComponents.getValueFor(input); | ||
if (value == null) | ||
{ | ||
UISelection<FileResource<?>> selection = context.getInitialSelection(); | ||
cwd = selection.isEmpty() ? OperatingSystemUtils.getUserHomeDir() : selection.get() | ||
.getUnderlyingResourceObject(); | ||
} | ||
else | ||
{ | ||
// TODO: Use ConverterFactory ? | ||
cwd = new File(value.toString()); | ||
} | ||
FileLister fileLister = new FileLister(typedValue == null ? "" : typedValue, cwd, | ||
directory ? FileLister.Filter.DIRECTORY | ||
: FileLister.Filter.ALL); | ||
fileLister.findMatchingDirectories(completeOperation); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
...mpl/src/main/java/org/jboss/forge/addon/shell/aesh/completion/ForgeCommandCompletion.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.