2017-09-27 8 views
0

일부 언어에서는 텍스트 주위에 Esc codes을 입력하여 Linux 콘솔/터미널에서 색상을 지정할 수 있습니다. 그러나,이 REBOL에서 작동하지 않는 것 :Rebol의 컬러 텍스트 콘솔 출력

\e[0;31mred text\e[0m 

리눅스 터미널에서 REBOL와 컬러 텍스트 출력 인쇄 할 수 있습니다 : 코드 위

NORMAL: "\e[0m" 
RED: "\e[0;31m" 

print rejoin["\e[0;31m" "red text" "\e[0m"] 

은 검은 색 (보통 색깔) 텍스트 출력을 생성?

+0

이것은 Linux/unix의 non-gui 콘솔이라고 가정합니다. –

답변

1

마찬가지로 Rebol/Red에서 색상 코드를 사용할 수 있습니다.

print "This text is ^[[0;31mred^[[0m text." 

#"^["은 Rebol/Red의 이스케이프 문자입니다.

예를 들어, 다음의 코드 레드의 프롬프트를 변경할 수 있습니다

system/console/prompt: "^[[31m^[[5D>>^[(B^[[m " 
system/console/result: "^[[32m^[[5D==^[(B^[[m" 

을 REBOL 3의 르네-C 지점에서 다음 (유사한) 코드로 프롬프트를 변경할 수 있습니다

system/console/prompt: "^[[31m^[[5D>>^[(B^[[m " 
system/console/result: "^[[32m^[[5D==^[(B^[[m " 
+0

텍스트는 어디에 색칠합니까? 말하자면, "빨간 색"이 빨간색으로 만 인쇄 된 "this is red text"를 인쇄하고 싶습니다. – rnso

0
REBOL [ 
     Title: "colorebol" 
     Date: 14-Jul-2013 
     File: %colorebol.reb 
     Version: 1.0.0 
     Purpose: "Enable switching of terminal font colors and backgrounds etc" 
     Note: "Includes the clr func for clearing the screen" 
    ] 

    clr: does [prin "^(page)"] 

    coloreb: func [ 
    {Use Fore/Red /Green /Yellow /Blue /Magenta /Cyan /White /Reset and even /Black. Viola! Font-color 
    Similarly Background/Blue etc..., then Style/bright /dim /normal /reset_all and finally Cyclor, which 
    randomly picks a font color. It needs some polishing} 
    ][cyclor print ["this is all i do. that, and provide a help doc-string"] cyclor] 

    Fore: make object! [ 

     Colors: ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" "reset"] 
     BLACK: does [prin "^[[30m"] 
     RED:  does [prin "^[[31m"] 
     GREEN: does [prin "^[[32m"] 
     YELLOW: does [prin "^[[33m"] 
     BLUE:  does [prin "^[[34m"] 
     MAGENTA: does [prin "^[[35m"] 
     CYAN:  does [prin "^[[36m"] 
     WHITE: does [prin "^[[37m"] 
     RESET: does [prin "^[[39m"] 
    ] 

    Background: make object! [ 
     Colors: ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" "reset"] 
     BLACK: does [prin "^[[40m"] 
     RED:  does [prin "^[[41m"] 
     GREEN: does [prin "^[[42m"] 
     YELLOW: does [prin "^[[43m"] 
     BLUE:  does [prin "^[[44m"] 
     MAGENTA: does [prin "^[[45m"] 
     CYAN:  does [prin "^[[46m"] 
     WHITE: does [prin "^[[47m"] 
     RESET: does [prin "^[[49m"] 
    ] 

    Style: make object! [ 
     Styles: ["bright" "dim" "normal" "reset_all"] 
     BRIGHT: does [prin "^[[1m"] 
     DIM:  does [prin "^[[2m"] 
     NORMAL: does [prin "^[[22m"] 
     RESET_ALL: does [prin "^[[0m"] 
    ] 

    cyclor: func [] [fore/(to-word fore/colors/(random/only [2 3 4 5 6 7 8]))] 

는 다른 스크립트 파일이 넣어 :

do %colorebol.reb 
,363,210

다음과 같이 사용 :

 col: has [ 
     "Wrap the colorebol.reb wrappers to reduce visual clutter" 
     color /red /green /blue /yellow /cyan /magenta /black /white][ 
     if red [color: 'red] 
     if green [color: 'green] 
     if blue [color: 'blue] 
     if yellow [color: 'yellow] 
     if cyan [color: 'cyan] 
     if magenta [color: 'magenta] 
     if black [color: 'black] 
     if white [color: 'white] 

     if unixy-os? [fore/(color)] 
    ] 

    ;test it: 
    col/magenta print "magenta" ;(it works). Maybe just mod /%colorebol.reb? 

내가 REBOL에 그 유창 아니에요 - 내가 더 간결한 방법이 확신 해요. 그러나 이것은 GNU/Linux에서 나에게 잘 돌아갔다. 스크립트를 이식성있게 유지하려면 OS 감지 기능이 있으며 코드화 코드는 이에 의존합니다.

+0

귀하의 질문에 대한 대답은 위의 코드의 마지막 줄입니다. – klausnrooster

+0

위대한 스크립트. 너는 내 질문을 분명히 좋아했다. – rnso