我需要帮助了解着色如何适用于urwid
color_palette = [
('banner', '', '', '', '#fff', 'g35'),
('streak', 'white', '', '', 'g0', 'g35'),
('inside', '', '', '', 'g0', 'g35'),
('outside', '', '', '', 'g0', 'g35'),
('bg', '', '', '', 'g35', '#fff'),]
从文档中: http://urwid.org/manual/displayattributes.html#id6
我想使用的颜色:
- #195c60
- #193638
- #232323
用法:http://urwid.org/tutorial/index.html#high-color-modes
import urwid
def exit_on_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
palette = [
('banner', '', '', '', '#ffa', '#60d'),
('streak', '', '', '', 'g50', '#60a'),
('inside', '', '', '', 'g38', '#808'),
('outside', '', '', '', 'g27', '#a06'),
('bg', '', '', '', 'g7', '#d06'),]
placeholder = urwid.SolidFill()
loop = urwid.MainLoop(placeholder, palette, unhandled_input=exit_on_q)
loop.screen.set_terminal_properties(colors=256)
loop.widget = urwid.AttrMap(placeholder, 'bg')
loop.widget.original_widget = urwid.Filler(urwid.Pile([]))
div = urwid.Divider()
outside = urwid.AttrMap(div, 'outside')
inside = urwid.AttrMap(div, 'inside')
txt = urwid.Text(('banner', u" Hello World "), align='center')
streak = urwid.AttrMap(txt, 'streak')
pile = loop.widget.base_widget # .base_widget skips the decorations
for item in [outside, inside, streak, inside, outside]:
pile.contents.append((item, pile.options()))
loop.run()
答案 0 :(得分:1)
听起来您想要使用自定义颜色的urwid高色示例。</ p>
在本教程的示例中,以下行告诉终端使用8位终端颜色模式(https://en.wikipedia.org/wiki/8-bit_color):
$ colortrans 195c60
RGB 195c60 -> xterm color approx 23 (005f5f)
$ colortrans 193638
RGB 193638 -> xterm color approx 23 (005f5f)
$ colortrans 232323
RGB 232323 -> xterm color approx 16 (000000)
要使用自定义颜色,您需要将(可能是RGB)颜色转换为最接近的相应8位终端颜色。请注意,您不一定能够获得完全匹配: way 比8位终端颜色代码更多RGB十六进制颜色代码。
我使用此工具查找颜色的近似匹配项:https://gist.github.com/MicahElliott/719710
palette = [
('color1', '', '', '', 'h23', 'h23'),
('color2', '', '', '', 'h16', 'h16'),]
使用现代urwid,您可以执行以下操作:
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
var router = express.Router();
//This Works
router.get('/', function(req, res, next) {
res.render('index');
});
//This Works
router.get('/about', function(req, res, next) {
res.render('about');
});
//This Does NOT Work, How do I get this to work?
router.get('/partials/navbar', function(req, res, next) {
res.render('/partials/navbar');
});