1

I am new to Tcl. I am trying to call one proc in other proc for rich text formatting. The proc for changing color of font looks like this :

 proc color {foreground text} {
       # for colored font
       return [exec tput setaf $foreground]$text[exec tput sgr0]
   }

This works with puts "[color 3 SomeText]". However I have another proc which contains text and looks like this,

proc Text {} {
    puts stdout "SOMETEXT"
}

Here I want to have colored "SOMETEXT". I tried (wild guess) puts stdout "[color 3 SOMETEXT]" but it did not work. I think there is something to do with global and private environment. I came across these links 1, 2 but did not provided me what i am looking for.

I understand that i can put my text in proc color {} but my application prevents me doing that. So, to conclude, Is is possible to call proc color {} inside proc text {} ?

P.S. : I am using tclsh from linux terminal.

Darshan
  • 71
  • 11
  • Sorry, totally misread your question. I'd expect what you're trying to work, provided you used exactly what you wrote in the environment you said. It won't (normally) work on Windows for really complicated reasons (short version: no `tput`, terminal has coloured text handling disabled by default). – Donal Fellows Apr 21 '23 at 15:14
  • I am using that in linux and `tput` works fine there ! The conclussive question is that, how to use/call one `proc` that returns text in another `proc`. – Darshan Apr 21 '23 at 15:17
  • 1
    You'll have to be more explicit about "did not work". What actually happened? An error message? Uncoloured text printed to stdout? – glenn jackman Apr 21 '23 at 16:59

1 Answers1

2

(not an answer, but a formatted comment)

Can you try to reproduce this:

enter image description here

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Alright, it worked. I was not calling color proc as an input argument for Text (which seemed the problem). I will be mindful next time to mention error as well. Thanks ! – Darshan Apr 24 '23 at 09:02