Java Code Examples for org.fusesource.jansi.AnsiConsole#systemInstall()

The following examples show how to use org.fusesource.jansi.AnsiConsole#systemInstall() . 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: OrderBookStream.java    From limit-order-book with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: Main.java    From SaliensAuto with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: GroovyInterpreter.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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: MainLogger.java    From BukkitPE with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: Application.java    From ig-webapi-java-sample with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 6
Source File: GruntParser.java    From spork with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: AnsiLogger.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void initializeColor(boolean useColor) {
    this.useAnsi = useColor && !log.isDebugEnabled();
    if (useAnsi) {
        AnsiConsole.systemInstall();
        Ansi.setEnabled(true);
    }
    else {
        Ansi.setEnabled(false);
    }
}
 
Example 8
Source File: JythonInterpreter.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 9
Source File: AnsiWindowsTerminal.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: VertexiumShell.java    From vertexium with Apache License 2.0 5 votes vote down vote up
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 11
Source File: Logger.java    From rscplus with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: AnsiLoggerFacade.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
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 13
Source File: MavenColorRenderer.java    From maven-color with MIT License 5 votes vote down vote up
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 14
Source File: HelpAnsiTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: WindowsJansiDemo.java    From picocli with Apache License 2.0 5 votes vote down vote up
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 16
Source File: PGMServer.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
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 17
Source File: AnsiLogger.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void initializeColor(boolean useColor) {
    this.useAnsi = useColor && !log.isDebugEnabled();
    if (useAnsi) {
        AnsiConsole.systemInstall();
        Ansi.setEnabled(true);
    }
    else {
        Ansi.setEnabled(false);
    }
}
 
Example 18
Source File: CustomLogFormatter.java    From RepoSense with MIT License 4 votes vote down vote up
public CustomLogFormatter() {
    formatMap.put(Level.WARNING, WARNING_HIGHLIGHT);
    formatMap.put(Level.SEVERE, ERROR_HIGHLIGHT);
    AnsiConsole.systemInstall();
}
 
Example 19
Source File: AnsiLoggerTest.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeClass
public static void installAnsi() {
    AnsiConsole.systemInstall();
}
 
Example 20
Source File: AbstractConsole.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
protected AbstractConsole(PrintStream out) {
    this.out = out;
    AnsiConsole.systemInstall();
}