Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

Programming 1 (BI)
  ▸ exercises
  ▸ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ✦C++, ✦Clojure, ✦Scala


[ edit | logout ]
[ sandbox | passwd ]

Colors in the terminal #2

In a previous post we saw how to print colored texts manually. Now, let's see how to do it with the standard library.

See also std/terminal

import std/exitprocs

import std/terminal
addExitProc(resetAttributes)  # just to be sure

proc main() =
  styledEcho styleBright, "Hello, Bold!"    # resets at the end
  echo "normal text"
  stdout.styledWriteLine fgBlue, styleBright, "Hello, Bold and Blue!"
  stdout.styledWrite bgCyan, fgWhite, styleBright, "NimOS", resetStyle, "> "   # no newline
  echo "..."

when isMainModule:
  main()

bold is called bright here

"Procs like styledEcho, styledWrite, styledWriteLine have a temporary effect on text parameters. Style parameters only affect the text parameter right after them. After being called, these procs will reset the default style of the terminal. While setBackGroundColor, setForeGroundColor etc. have a lasting influence on the terminal, you can use resetAttributes to reset the default style of the terminal."

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 June 01, 22:47