Make text text bold when reading from the console

How to make bold text in eclipse? To be more clear, I will give an example: we write in the syntax

System.out.print("Name: "); String name = in.nextLine(); 

When we run the program, the user must enter the name: NAME: David I want to make David bold and resize

+4
source share
2 answers

@Thomas is completely right. However, if you want to install bold on "most" terminals, you can write

  private final String setPlainText = "\033[0;0m"; private final String setBoldText = "\033[0;1m"; 

eg.

  System.out.println (setPlainText + "Prompt>" + setBoldText); 

This is not entirely universal, but it works for most popular terminals. To get some kind of amateur, you'll want to look at something like What is good Java, curses-like, library for terminal applications? or switch to creating a GUI, for example. possibly using Swing.

+5
source

In fact, you cannot change the font size in a text terminal. There is no such information sent to the terminal upon your request. (Only streaming text is sent through the stream). This is possible and easy in graphical applications created in Java and managed by the Java API. Before you start with them, I suggest you start with simple books or Java tutorials.

Java programming language basics, part 1

By the way, this is the code that can do your task (excluding changing the font size or font style)

  import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); String name = br.readLine(); System.out.print("Name: "+name); } } 

The only thing that can be changed using the eclipse console is the font color of the output stream and the error stream. (Right click on the console screen and settings)

+1
source

Source: https://habr.com/ru/post/1386383/


All Articles