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.