org.fusesource.jansi.AnsiConsole Java Examples
The following examples show how to use
org.fusesource.jansi.AnsiConsole.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java From java-repl with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { console = new ResultPrinter(printColors(args)); ConsoleReader consoleReader = new ConsoleReader(System.in, AnsiConsole.out); JavaREPLClient client = clientFor(hostname(args), port(args)); Sequence<String> initialExpressions = initialExpressionsFromFile().join(initialExpressionsFromArgs(args)); ExpressionReader expressionReader = expressionReaderFor(consoleReader, client, initialExpressions); Option<String> expression = none(); Option<EvaluationResult> result = none(); while (expression.isEmpty() || !result.isEmpty()) { expression = expressionReader.readExpression(); if (!expression.isEmpty()) { result = client.execute(expression.get()); if (!result.isEmpty()) { for (EvaluationLog log : result.get().logs()) { if (!handleTerminalCommand(log)) { handleTerminalMessage(log); } } } } } }
Example #2
Source File: MainLogger.java From BukkitPE with GNU General Public License v3.0 | 6 votes |
public MainLogger(String logFile, Boolean logDebug) { AnsiConsole.systemInstall(); if (logger != null) { throw new RuntimeException("MainLogger has been already created"); } logger = this; this.logFile = new File(logFile); if (!this.logFile.exists()) { try { this.logFile.createNewFile(); } catch (IOException e) { this.logException(e); } } this.logDebug = logDebug; this.start(); }
Example #3
Source File: GroovyInterpreter.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 6 votes |
public GroovyInterpreter(Binding binding) throws IOException { this.binding = binding; if (this.binding == null) this.binding = new Binding(); is = new PipedInputStream(); os = new PipedOutputStream(); pis = new PipedInputStream(os); pos = new PipedOutputStream(is); System.setProperty(TerminalFactory.JLINE_TERMINAL, "none"); AnsiConsole.systemInstall(); Ansi.setDetector(new AnsiDetector()); binding.setProperty("out", new ImmediateFlushingPrintWriter(pos)); shell = new Groovysh(binding, new IO(pis, pos, pos)); // { // @Override // public void displayWelcomeBanner(InteractiveShellRunner runner) { // // do nothing // } // }; shell.getIo().setVerbosity(Verbosity.QUIET); }
Example #4
Source File: HelpAnsiTest.java From picocli with Apache License 2.0 | 6 votes |
@Test public void testAnsiAutoJansiConsoleInstalledOverridesHintDisabled() { environmentVariables.clear(ANSI_ENVIRONMENT_VARIABLES); environmentVariables.set("CLICOLOR", "0"); // hint disabled System.setProperty("os.name", "Windows"); assertTrue(Ansi.isWindows()); assertFalse(Ansi.isPseudoTTY()); assertFalse(Ansi.forceDisabled()); assertFalse(Ansi.forceEnabled()); assertTrue(Ansi.hintDisabled()); assertFalse(Ansi.hintEnabled()); assertFalse(Ansi.isJansiConsoleInstalled()); AnsiConsole.systemInstall(); try { assertTrue(Ansi.isJansiConsoleInstalled()); assertTrue(Ansi.AUTO.enabled()); } finally { AnsiConsole.systemUninstall(); } }
Example #5
Source File: OrderBookStream.java From limit-order-book with GNU General Public License v3.0 | 6 votes |
public static void main(final String[] args) throws Exception { BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.ERROR); AnsiConsole.systemInstall(); int console_height = Integer.parseInt(args[0]); boolean real_time = Boolean.parseBoolean((args[1])); String symbol = args[2]; OrderBookStream orderBookStream = new OrderBookStream("bitstamp", symbol, real_time); orderBookStream.getOb().setConsoleHeight(console_height); Client client = new BitstampClient(); String subscriptionId = client.subscribeOrders(symbol, orderBookStream); try { OrderBook ob = orderBookStream.getOb(); while (true) { Thread.sleep(1000); if (!real_time) { AnsiConsole.system_out.println(ansi().eraseScreen(Erase.ALL).a(ob).reset()); } } } catch (InterruptedException e) { } }
Example #6
Source File: Main.java From SaliensAuto with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args){ AnsiConsole.systemInstall(); checkVersion(); debug(highlight("SaliensAuto "+ VersionUtils.getLocalVersion(),Color.LIGHT_PURPLE)); debug("&cPlease keep checking &ahttps://github.com/KickVN/SaliensAuto &cregularly in case there is a new update"); debug("&cAnd please close all runninng instances of Saliens on the same account in this program. For exampe, close your Saliens on web browser."); commandManager.showHelps(); if(args.length>=1) setToken(args[0]); if(args.length>=2) setPlanetSearchMode(Integer.valueOf(args[1])); if(args.length>=3 && !args[2].equals("0")) start(); if(args.length>=4) setAccountId(Long.valueOf(args[3])); Scanner scanner = new Scanner(System.in); while(true){ String s = scanner.nextLine(); if(s.length()==0) continue; try { commandManager.handleCommand(s); }catch (Exception e){if(!(e instanceof NullPointerException)) e.printStackTrace();} } }
Example #7
Source File: AnsiLoggerTest.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
@Before public void forceAnsiPassthrough() { // Because the AnsiConsole keeps a per-VM counter of calls to systemInstall, it is // difficult to force it to pass through escapes to stdout during test. // Additionally, running the test in a suite (e.g. with mvn test) means other // code may have already initialized or manipulated the AnsiConsole. // Hence we just reset the stdout/stderr references to those captured by AnsiConsole // during its static initialization and restore them after tests. System.setOut(AnsiConsole.system_out); System.setErr(AnsiConsole.system_err); }
Example #8
Source File: AnsiLogger.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private void initializeColor(boolean useColor) { this.useAnsi = useColor && !log.isDebugEnabled(); if (useAnsi) { AnsiConsole.systemInstall(); Ansi.setEnabled(true); } else { Ansi.setEnabled(false); } }
Example #9
Source File: GruntParser.java From spork with Apache License 2.0 | 5 votes |
@Override protected void printClear() { AnsiConsole.systemInstall(); Ansi ansi = Ansi.ansi(); System.out.println( ansi.eraseScreen() ); System.out.println( ansi.cursor(0, 0) ); AnsiConsole.systemUninstall(); }
Example #10
Source File: MavenColorRenderer.java From maven-color with MIT License | 5 votes |
public MavenColorRenderer(String pattern, boolean isActivated) { super(pattern); if (LOGGER.isDebugEnabled()) { System.out.println("Using maven-color v" + Version.current().get() + "."); } this.isActivated = isActivated; if (isActivated) { AnsiConsole.systemInstall(); colorizer = ColorConfiguration.read(); } else { colorizer = new KeepMavenDefaultColor(); } Ansi.setEnabled(isActivated); }
Example #11
Source File: OrderBookStream.java From limit-order-book with GNU General Public License v3.0 | 5 votes |
@Override public void onMessage(OrderEvent orderEvent) { OrderEvent.Order order = orderEvent.order; Direction direction = order.type == 0 ? Direction.BUY : Direction.SELL; long localTs = System.currentTimeMillis(); String exchangeOrderId = Long.toString(order.id); int limitPrice = getLimitPrice(order.price, symbol); long volume = getVolume(order.amount, symbol); long exchangeTimestamp = order.microTimestamp / 1000; OrderInfo orderInfo = new OrderInfo(exchangeOrderId, limitPrice, volume, exchangeTimestamp); net.parasec.trading.ticker.core.wire.OrderEvent.State state; switch (orderEvent.event) { case ORDER_CREATED: state = net.parasec.trading.ticker.core.wire.OrderEvent.State.CREATED; ob.addOrder(new net.parasec.trading.ticker.core.wire.OrderEvent(state, direction, symbol, venue, localTs, orderInfo)); break; case ORDER_UPDATED: state = net.parasec.trading.ticker.core.wire.OrderEvent.State.UPDATED; ob.modOrder(new net.parasec.trading.ticker.core.wire.OrderEvent(state, direction, symbol, venue, localTs, orderInfo)); break; case ORDER_DELETED: state = net.parasec.trading.ticker.core.wire.OrderEvent.State.DELETED; ob.delOrder(new net.parasec.trading.ticker.core.wire.OrderEvent(state, direction, symbol, venue, localTs, orderInfo)); } if (real_time) { AnsiConsole.system_out.println(ansi().a(ob).reset()); } System.err.println(ob.getState().toCsv()); }
Example #12
Source File: JythonInterpreter.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public JythonInterpreter() throws IOException { is = new PipedInputStream(); os = new PipedOutputStream(); pis = new PipedInputStream(os); pos = new PipedOutputStream(is); System.setProperty(TerminalFactory.JLINE_TERMINAL, "none"); AnsiConsole.systemInstall(); Ansi.setDetector(new AnsiDetector()); shell = new InteractiveConsole(); shell.setIn(pis); shell.setOut(pos); shell.setErr(pos); }
Example #13
Source File: ConsoleColorHandler.java From tomee with Apache License 2.0 | 5 votes |
public ConsoleColorHandler() { setFormatter(new ColorFormatter()); setLevel(level()); if (wrapped) { setOutputStream(AnsiConsole.out); } else { setOutputStream(System.out); } }
Example #14
Source File: AnsiWindowsTerminal.java From Thermos with GNU General Public License v3.0 | 5 votes |
private static boolean detectAnsiSupport() { AnsiConsole.systemInstall(); // CraftBukkit - install Windows JNI library OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream()); try { out.close(); } catch (Exception e) { // ignore; } return out instanceof WindowsAnsiOutputStream; }
Example #15
Source File: AnsiLogger.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void initializeColor(boolean useColor) { this.useAnsi = useColor && !log.isDebugEnabled(); if (useAnsi) { AnsiConsole.systemInstall(); Ansi.setEnabled(true); } else { Ansi.setEnabled(false); } }
Example #16
Source File: VertexiumShell.java From vertexium with Apache License 2.0 | 5 votes |
static void installAnsi() { // Install the system adapters, replaces System.out and System.err // Must be called before using IO(), because IO stores refs to System.out and System.err AnsiConsole.systemInstall(); // Register jline ansi detector Ansi.setDetector(new AnsiDetector()); }
Example #17
Source File: Logger.java From rscplus with GNU General Public License v3.0 | 5 votes |
public static void stop() { try { m_logWriter.close(); } catch (Exception e) { } AnsiConsole.systemUninstall(); }
Example #18
Source File: Application.java From ig-webapi-java-sample with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean run(final String user, final String password, final String apiKey, final String epic) { InputStreamReader reader = new InputStreamReader(System.in); try(BufferedReader in = new BufferedReader(reader)) { AnsiConsole.systemInstall(); System.out.println(ansi().eraseScreen()); connect(user, password, apiKey); if(StringUtils.isNotBlank(epic)) { tradeableEpic = getTradeableEpic(epic); } else { tradeableEpic = getTradableEpicFromWatchlist(); } subscribeToLighstreamerAccountUpdates(); subscribeToLighstreamerHeartbeat(); subscribeToLighstreamerPriceUpdates(); subscribeToLighstreamerTradeUpdates(); logStatusMessage("Press ENTER to BUY"); ConversationContextV3 contextV3 = (ConversationContextV3) authenticationContext.getConversationContext(); while(true) { if(new Date().getTime() + 5000 > contextV3.getAccessTokenExpiry()) { // Refresh the access token 5 seconds before expiry logStatusMessage("Refreshing access token"); contextV3 = refreshAccessToken(contextV3); } Thread.sleep(20); if (in.ready()) { in.readLine(); createPosition(); } } } catch (Exception e) { logStatusMessage("Failure: " + e.getMessage()); return false; } finally { disconnect(); AnsiConsole.systemUninstall(); } }
Example #19
Source File: AnsiWindowsTerminal.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
private static boolean detectAnsiSupport() { OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream()); try { out.close(); } catch (Exception e) { // ignore; } return out instanceof WindowsAnsiOutputStream; }
Example #20
Source File: API.java From cdep with Apache License 2.0 | 5 votes |
@NotNull private static List<String> callCDep(@NotNull GeneratorEnvironment environment) throws MalformedURLException { List<String> result = new ArrayList<>(); if (PlatformUtils.isWindows()) { result.add("\"" + getJvmLocation() + "\""); } else { result.add(platformQuote(getJvmLocation())); } result.add("-classpath"); File cdepLocation = ReflectionUtils.getLocation(API.class); String classPath = cdepLocation.getAbsolutePath().replace("\\", "/"); if (!classPath.endsWith(".jar")) { String separator = PlatformUtils.isWindows() ? ";" : ":"; // In a test environment need to include SnakeYAML since it isn't part of the unit test File yamlLocation = ReflectionUtils.getLocation(YAMLException.class); classPath = yamlLocation.getAbsolutePath().replace("\\", "/") + separator + classPath; File jansiLocation = ReflectionUtils.getLocation(AnsiConsole.class); classPath = jansiLocation.getAbsolutePath().replace("\\", "/") + separator + classPath; } result.add(platformQuote(classPath)); result.add("io.cdep.CDep"); result.add("--working-folder"); result.add(platformQuote(environment.workingFolder.getAbsolutePath().replace("\\", "/"))); return result; }
Example #21
Source File: Logger.java From rscplus with GNU General Public License v3.0 | 5 votes |
public static void start() { AnsiConsole.systemInstall(); File file = new File(Settings.Dir.JAR + "/log.txt"); try { m_logWriter = new PrintWriter(new FileOutputStream(file)); } catch (Exception e) { } }
Example #22
Source File: CDep.java From cdep with Apache License 2.0 | 5 votes |
public static void main(@NotNull String[] args) { int result; try { result = new CDep(AnsiConsole.out, AnsiConsole.err, true).go(args, false); resetAnsiColors(); } catch (Throwable e) { resetAnsiColors(); e.printStackTrace(System.err); result = 1; } System.exit(result); }
Example #23
Source File: HelpAnsiTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testAnsiEnabled() { assertTrue(Ansi.ON.enabled()); assertFalse(Ansi.OFF.enabled()); System.setProperty("picocli.ansi", "tty"); boolean hasConsole = Ansi.calcTTY() || Ansi.isPseudoTTY(); assertEquals(hasConsole, Ansi.AUTO.enabled()); System.setProperty("picocli.ansi", "true"); assertEquals(true, Ansi.AUTO.enabled()); System.setProperty("picocli.ansi", "false"); assertEquals(false, Ansi.AUTO.enabled()); System.clearProperty("picocli.ansi"); boolean isWindows = System.getProperty("os.name").startsWith("Windows"); boolean isXterm = System.getenv("TERM") != null && System.getenv("TERM").startsWith("xterm"); boolean hasOsType = System.getenv("OSTYPE") != null; // null on Windows unless on Cygwin or MSYS boolean isAtty = (isWindows && (isXterm || hasOsType)) // cygwin pseudo-tty || hasConsole(); assertEquals((isAtty && (!isWindows || isXterm || hasOsType)) || isJansiConsoleInstalled(), Ansi.AUTO.enabled()); if (isWindows && !Ansi.AUTO.enabled()) { AnsiConsole.systemInstall(); try { assertTrue(Ansi.AUTO.enabled()); } finally { AnsiConsole.systemUninstall(); } } }
Example #24
Source File: WindowsJansiDemo.java From picocli with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // Since https://github.com/remkop/picocli/issues/491 was fixed in picocli 3.6.0, // Ansi.AUTO is automatically enabled if the AnsiConsole is installed. AnsiConsole.systemInstall(); // Jansi magic new CommandLine(new WindowsJansiDemo()).execute(args); AnsiConsole.systemUninstall(); }
Example #25
Source File: PGMServer.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
protected Logger setupLogger() { AnsiConsole.systemInstall(); final java.util.logging.Logger global = java.util.logging.Logger.getLogger(""); global.setUseParentHandlers(false); final Handler[] handlers = global.getHandlers(); for (int i = 0; i < handlers.length; ++i) { global.removeHandler(handlers[i]); } global.addHandler(new ForwardLogHandler()); org.apache.logging.log4j.Logger logger = LogManager.getRootLogger(); if (logger instanceof org.apache.logging.log4j.core.Logger) { final Iterator<org.apache.logging.log4j.core.Appender> appenders = ((org.apache.logging.log4j.core.Logger) logger).getAppenders().values().iterator(); while (appenders.hasNext()) { final org.apache.logging.log4j.core.Appender appender = appenders.next(); if (appender instanceof ConsoleAppender) { ((org.apache.logging.log4j.core.Logger) logger).removeAppender(appender); } } } new Thread(new TerminalConsoleWriterThread(System.out, reader)).start(); System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true)); System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true)); BasicConfigurator.resetConfiguration(); try { return (Logger) PGMServer.class.getField("LOGGER").get(PGMServer.class); } catch (IllegalAccessException | NoSuchFieldException e) { // No-op } return logger; }
Example #26
Source File: AnsiLoggerFacade.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void initializeColor(boolean useColor) { // sl4j simple logger used by Maven seems to escape ANSI escapes on Windows this.useAnsi = useColor && System.console() != null && !log.isDebugEnabled() && !isWindows(); if (useAnsi) { AnsiConsole.systemInstall(); Ansi.setEnabled(true); } else { Ansi.setEnabled(false); } }
Example #27
Source File: AnsiLoggerTest.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Before public void forceAnsiPassthrough() { // Because the AnsiConsole keeps a per-VM counter of calls to systemInstall, it is // difficult to force it to pass through escapes to stdout during test. // Additionally, running the test in a suite (e.g. with mvn test) means other // code may have already initialized or manipulated the AnsiConsole. // Hence we just reset the stdout/stderr references to those captured by AnsiConsole // during its static initialization and restore them after tests. System.setOut(AnsiConsole.system_out); System.setErr(AnsiConsole.system_err); }
Example #28
Source File: AbstractConsole.java From elasticshell with Apache License 2.0 | 4 votes |
@Override public void shutdown() { AnsiConsole.systemUninstall(); }
Example #29
Source File: AbstractConsole.java From elasticshell with Apache License 2.0 | 4 votes |
protected AbstractConsole(PrintStream out) { this.out = out; AnsiConsole.systemInstall(); }
Example #30
Source File: Context.java From dsl-compiler-client with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Context() { this(AnsiConsole.out()); }