@Override public void println() { try { screenBuffer.write(OSUtils.getLineSeparator().getBytes()); _flushBuffer(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setHistory(final List<String> lines) { if (isNoInitMode()) { _historyOverride = lines; return; } _setHistory(lines); }
@Override public void setAnsiSupported(final boolean value) { if (value != isAnsiSupported()) { try { if (value) { configureOSTerminal(); } else { TerminalFactory.configure(TerminalFactory.Type.NONE); TerminalFactory.reset(); } initReaderAndStreams(); } catch (IOException e) { throw new RuntimeException("Failed to reset Terminal instance for ANSI configuration", e); } } }
void doShell(@Observes final AcceptUserInput event) throws Exception { String line; reader.setPrompt(getPrompt()); while (!exitRequested) { try { line = readLine(); if (line != null) { if (!"".equals(line.trim())) { writeToHistory(line); execute(line); flush(); } reader.setPrompt(getPrompt()); } } catch (Exception e) { handleException(e); } } }
configureOSTerminal(); initReaderAndStreams(); initParameters(); shellConfig.loadConfig(this); initSignalHandlers(); if (!isNoInitMode()) this.registerKeyListener(ignoreEOF); environment.setProperty("CWD", getCurrentDirectory().getFullyQualifiedName()); environment.setProperty("SHELL", this);
public void loadConfig(final ShellImpl shell) { File configDir = environment.getConfigDirectory().getUnderlyingResourceObject(); if ((configDir != null) && configDir.exists() && !shell.isNoInitMode()) { boolean historyEnabled = shell.isHistoryEnabled(); shell.setHistoryEnabled(false); File configFile = new File(configDir.getPath(), ShellImpl.FORGE_CONFIG_FILE); if (!configFile.exists()) { createDefaultConfigFile(configFile); } try { shell.execute(configFile); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("error loading file: " + configFile.getAbsolutePath()); } shell.setHistoryEnabled(historyEnabled); } }
@Override public String promptSecret(String message) { if (!message.isEmpty() && message.matches("^.*\\S$")) { message = message + " "; } message = renderColor(ShellColor.CYAN, " ? ") + message; try { reader.removeCompleter(this.completer); reader.setHistoryEnabled(false); reader.setPrompt(message); flush(); String line = readLine('*'); flush(); return line; } catch (IOException e) { throw new IllegalStateException("Shell input stream failure", e); } finally { reader.addCompleter(this.completer); reader.setHistoryEnabled(true); reader.setPrompt(""); } }
private void handleException(final Exception original) throws Exception if (!isExceptionHandlingEnabled()) if (isVerbose()) ShellMessages.error(this, formatSourcedError(e.getCommand()) + e.getMessage()); if (isVerbose()) ShellMessages.error(this, formatSourcedError(e.getCommand()) + e.getMessage()); if (isVerbose()) ShellMessages.error(this, formatSourcedError(e.getPlugin()) + e.getMessage()); if (isVerbose()) if (isVerbose()) if (!isVerbose())
@Override public String readLine(final Character mask) throws IOException { String line; if (mask != null) { line = reader.readLine(mask); } else { line = reader.readLine(); } if ((line != null) && !OSUtils.getLineSeparator().equals(line)) { write(OSUtils.getLineSeparator().getBytes()); } flush(); return line; }
@Override @SuppressWarnings("unchecked") public Class<? extends Resource<?>> getCurrentResourceScope() { return (Class<? extends Resource<?>>) getCurrentResource().getClass(); }
message = renderColor(ShellColor.CYAN, " ? ") + message; flush(); flush(); if (thread.getException() instanceof EndOfStreamException)
@Override public void execute(final File file) throws Exception { StringBuilder buf = new StringBuilder(); InputStream instream = new BufferedInputStream(new FileInputStream(file)); try { byte[] b = new byte[25]; int read; while ((read = instream.read(b)) != -1) { for (int i = 0; i < read; i++) { buf.append((char) b[i]); } } instream.close(); execute(buf.toString()); } finally { ignoreEOF.reset(); instream.close(); } }
@Override public JavaResource[] convertFrom(final Object obj) { if (getCurrentProject().hasFacet(JavaSourceFacet.class)) { String[] strings = obj instanceof String[] ? (String[]) obj : new String[] { obj.toString() }; List<Resource<?>> resources = new ArrayList<Resource<?>>(); for (String string : strings) { resources.addAll(new JavaPathspecParser(getCurrentProject().getFacet(JavaSourceFacet.class), string).resolve()); } List<JavaResource> filtered = new ArrayList<JavaResource>(); for (Resource<?> resource : resources) { if (resource instanceof JavaResource) { filtered.add((JavaResource) resource); } } JavaResource[] result = new JavaResource[filtered.size()]; result = filtered.toArray(result); return result; } else return null; }
@Override @SuppressWarnings("rawtypes") public Resource[] convertFrom(final Object obl) { return GeneralUtils.parseSystemPathspec(resourceFactory, lastResource, getCurrentResource(), obl instanceof String[] ? (String[]) obl : new String[] { obl.toString() }); }
execute(buf.toString());
@Override public Object convertFrom(final Object obj) { JavaResource[] res = (JavaResource[]) javaResourceConversionHandler.convertFrom(obj); if (res.length > 1) { throw new RuntimeException("ambiguous paths"); } else if (res.length == 0) { if (getCurrentProject().hasFacet(JavaSourceFacet.class)) { JavaSourceFacet java = getCurrentProject().getFacet(JavaSourceFacet.class); try { JavaResource resource = java.getJavaResource(obj.toString()); return resource; } catch (FileNotFoundException e) { throw new RuntimeException(e); } } return null; } else { return res[0]; } }
private void initReaderAndStreams() throws IOException boolean noInitMode = isNoInitMode(); if ((_redirectedStream == null) && noInitMode) _setHistory(_historyOverride);
@Override public DirectoryResource getCurrentDirectory() { Resource<?> r = getCurrentResource(); return ResourceUtil.getContextDirectory(r); }
@Override public Object convertFrom(final Object o) { Resource<?>[] res = (Resource<?>[]) resourceConversionHandler.convertFrom(o); if (res.length > 1) { throw new RuntimeException("ambiguous paths"); } else if (res.length == 0) { return ResourceUtil.parsePathspec(resourceFactory, getCurrentResource(), o.toString()).get(0); } else { return res[0]; } }
@Override public void setCurrentResource(final Resource<?> resource) { lastResource = getCurrentResource(); projectContext.setCurrentResource(resource); environment.setProperty("CWD", resource.getFullyQualifiedName()); }