summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-08-24 01:18:03 +0200
committerAraq <rumpf_a@web.de>2012-08-24 01:18:03 +0200
commitc7ba6f5eb6f555ae650417c6f3bf9cdc0bad1427 (patch)
treee76ddea5dc65e48b16854fa69905f5618998acc1 /lib/pure
parentbdf3bee05510718581510cb78fa70ca183039d55 (diff)
downloadNim-c7ba6f5eb6f555ae650417c6f3bf9cdc0bad1427.tar.gz
implemented 'bind' for macros
Diffstat (limited to 'lib/pure')
-rwxr-xr-xlib/pure/terminal.nim23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index e57cc2112..5a82586cb 100755
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -319,23 +319,22 @@ proc isatty*(f: TFile): bool =
   
   result = isatty(fileHandle(f)) != 0'i32
 

-# XXX: 

-# These should be private, but there is no yet 

-# facility for binding local symbols within macros

-proc styledEchoProcessArg*(s: string)               = write stdout, s

-proc styledEchoProcessArg*(style: TStyle)           = setStyle({style})

-proc styledEchoProcessArg*(style: set[TStyle])      = setStyle style

-proc styledEchoProcessArg*(color: TForegroundColor) = setForeGroundColor color

-proc styledEchoProcessArg*(color: TBackgroundColor) = setBackGroundColor color

+proc styledEchoProcessArg(s: string)               = write stdout, s

+proc styledEchoProcessArg(style: TStyle)           = setStyle({style})

+proc styledEchoProcessArg(style: set[TStyle])      = setStyle style

+proc styledEchoProcessArg(color: TForegroundColor) = setForeGroundColor color

+proc styledEchoProcessArg(color: TBackgroundColor) = setBackGroundColor color

 

 macro styledEcho*(m: stmt): stmt =
+  bind styledEchoProcessArg, write, resetAttributes, stdout
+  
   result = newNimNode(nnkStmtList)

 

   for i in countup(1, m.len - 1):

-    result.add(newCall(!"styledEchoProcessArg", m[i]))

+    result.add(newCall(bindSym"styledEchoProcessArg", m[i]))

 

-  result.add(newCall(!"write", newIdentNode("stdout"), newStrLitNode("\n")))

-  result.add(newCall(!"resetAttributes"))

+  result.add(newCall(bindSym"write", bindSym"stdout", newStrLitNode("\n")))

+  result.add(newCall(bindSym"resetAttributes"))

 

 when isMainModule:

   system.addQuitProc(resetAttributes)

@@ -347,3 +346,5 @@ when isMainModule:
   setForeGroundColor(fgBlue)

   writeln(stdout, "ordinary text")

 

+  styledEcho("styled text ", {styleBright, styleBlink, styleUnderscore}) 
+  
\ No newline at end of file