---
title: "Lettuce在windows下没有颜色的解决方法"
author: "zealot2007"
date: "2010-07-24T01:37:56Z"
tags: ["Linux", "Python", "Ruby", "Windows", "框架"]
categories: ["编程语言"]
slug: "lettuce-windows"
draft: false
lastmod: "2010-07-24T01:37:56Z"
id: 720168
url: "https://zealot2007.iteye.com/blog/720168"
---

Lettuce 是python开发的BDD(Behavior-driven-development)的框架。熟悉Ruby的人都知道，ruby世界的经典BDD框架应属Cucumber。而Lettuce相当于Cucumber的python版。查看Lettuce详细信息请参见http://lettuce.it/或http://github.com/gabrielfalcao/lettuce。

    本着对新鲜事物的好奇（其实也不是新鲜事物，自己不懂就算新鲜咯![](/images/smiles/icon_smile.gif) ），便下了一个试玩。发现使用Lettuce在windows下做测试时，无法显示颜色。只是显示了一对代码。

写道

[1;37mFeature: Compute factorial [1;30m# \\featur  
[1;37m In order to play with Lettuce [1;30m# \\featur  
[1;37m As beginners [1;30m# \\featur  
[1;37m We'll implement factorial [1;30m# \\featur

\[1;37m Scenario Outline: Factorials of \[0-4] [1;30m# \\featur  
[0;36m Given I have the number &lt;number&gt; [1;30m# \\featur  
[0;36m When I compute its factorial [1;30m# \\featur  
[0;36m Then I see the number &lt;result&gt; [1;30m# \\featur

[1;37m Examples:[0m

   无奈上网查，无果。后来找了一个可以在控制台下显示颜色的python库colorama。安装之后，修改lettuce\\plugins\\colored\_shell\_output.py文件，在文件头上加一行from colorama import init; init() 搞定。

   看了一下init()的源码，发现只是给标准输出流，错误输出流加了一个包装器，对输出做了一些手脚。另外，在linux下不需要任何修改就可以显示颜色。

   解决方法虽有些猥琐，但尚可使用。希望有知道正确解决方法的大蟒们不吝赐教。