An warware: java terminal launuka

m launuka A cikin duniyar shirye-shirye da haษ“akawa, launuka masu ฦ™are suna taka muhimmiyar rawa wajen haษ“aka ฦ™warewar mai amfani da iya karantawa na fitowar rubutu. Launuka na ฦ™arshe suna ba da hanya mai sauฦ™i don keษ“ance yanayin gani na rubutu kuma ba da damar masu haษ“akawa don bambanta nau'ikan fitarwa daban-daban da sauri. A cikin wannan labarin, za mu yi la'akari da amfani da launuka masu ฦ™arewa a cikin Java kuma mu tattauna wasu ษ—akunan karatu da ayyuka waษ—anda zasu iya taimakawa wajen magance wannan matsala.

Matsalolin matsalar ta ta'allaka ne a cikin gaskiyar cewa ta tsohuwa, fitarwar tasha sau da yawa a bayyane take kuma ba ta da kowane irin bambancin launi. Wannan na iya sa ya zama da wahala ga masu haษ“akawa su yi saurin fassara abubuwan da aka fitar yayin gyara ko gwaji. Alhamdu lillahi, akwai mafita ga wannan matsalar ta amfani da lambobin tserewa na ANSI, waษ—anda ke ba da damar gyare-gyaren launuka masu ฦ™arewa.

Da farko, bari mu bincika lambobin tserewa na ANSI da kuma yadda za a iya amfani da su don musanya launuka masu iyaka a Java. Waษ—annan lambobin tserewa ainihin jerin haruffa ne waษ—anda ke ba da umarni ga tashar don aiwatar da takamaiman ayyuka, kamar canza launin rubutu. Don amfani da waษ—annan lambobin, suna buฦ™atar saka su a cikin rubutun da za a nuna a cikin tasha.

public class TerminalColors {

    public static final String ANSI_RESET = "33[0m";
    public static final String ANSI_RED = "33[31m";
    public static final String ANSI_GREEN = "33[32m";

    public static void main(String[] args) {
        System.out.println(ANSI_RED + "This is red text" + ANSI_RESET);
        System.out.println(ANSI_GREEN + "This is green text" + ANSI_RESET);
    }
}

A cikin lambar da ke sama, mun ayyana uku ANSI lambobin tserewa: daya don sake saita launin tasha, ษ—aya don canza launi zuwa ja, wani kuma don kore. Muna amfani da waษ—annan lambobin a cikin rubutun da aka buga zuwa na'ura mai kwakwalwa don canza launuka daidai.

Madadin Laburaren don Launukan Tasha

Kodayake yin amfani da lambobin tserewa na ANSI yana aiki da kyau don gyare-gyaren launi na asali, wasu ษ—akunan karatu na iya sa wannan tsari ya fi dacewa da dacewa.

  • JansiJansi sanannen ษ—akin karatu ne na Java wanda ke ba da API mai sauฦ™in amfani don aiki tare da lambobin tserewa na ANSI. Wannan ษ—akin karatu ta atomatik yana ganowa kuma yana hana tallafin ANSI akan dandamali waษ—anda basa goyan bayansa, yana tabbatar da daidaiton gogewa a cikin tsarin daban-daban.
  • RichTextFX: RichTextFX ษ—akin karatu ne na JavaFX wanda ke ba da hanya mai ฦ™arfi da sassauฦ™a don salon rubutu a cikin aikace-aikacen JavaFX, gami da mahalli kamar tasha. Wannan ษ—akin karatu yana ba da damar yin salo mai ban sha'awa da haษ“aka, gami da haruffa na al'ada, launuka, da ฦ™ari.

Aiwatar da Launuka Tasha a cikin Aikace-aikacen JavaFX

Ga masu haษ“akawa da ke aiki tare da JavaFX, yin amfani da launuka masu ฦ™arewa na iya zama ษ—an ฦ™alubale, kamar yadda tsarin tsarin System.out.println ba ya aiki. Koyaya, har yanzu yana yiwuwa a cimma gyare-gyaren launuka masu kama da ฦ™arshen.

Don yin haka, zaku iya amfani da ษ—akin karatu na RichTextFX kuma ฦ™irฦ™irar sarrafa al'ada, kamar a StyledTextArewa, don nuna abubuwan da kuke fitarwa. Wannan kulawar na iya rarraba lambobin tserewa ta ANSI kuma ya yi amfani da salon da suka dace.

A taฦ™aice, launuka masu ฦ™arewa suna taka muhimmiyar rawa wajen haษ“aka iya karantawa da ฦ™warewar mai amfani a duniyar shirye-shirye. Ta amfani da lambobin tserewa na ANSI ko ษ—aya daga cikin ษ—akunan karatu daban-daban da ake da su, zaku iya aiwatar da gyare-gyaren launuka masu sauฦ™i a cikin aikace-aikacen Java ษ—inku don haษ“aka kuskuren lamba da gwaji. Ka tuna, ฦ™irar mai amfani da aka ฦ™era da kyau na iya yin kowane bambanci a cikin nasarar aikin ku, don haka kada ku yi jinkirin amfani da launuka masu ฦ™arewa don fa'idar ku.

Shafi posts:

Leave a Comment