From 88522172152013a281590f2714f45adac6d2d679 Mon Sep 17 00:00:00 2001 From: agatan Date: Fri, 30 Nov 2018 10:30:12 +0900 Subject: [PATCH] Define ColorDefault and pass it to ColorPair#init --- src/ncurses/attribute.cr | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ncurses/attribute.cr b/src/ncurses/attribute.cr index c96fe20..8b5aa8e 100644 --- a/src/ncurses/attribute.cr +++ b/src/ncurses/attribute.cr @@ -2,15 +2,29 @@ require "./libncurses" module NCurses alias Attribute = LibNCurses::Attribute + + struct ColorDefault + end + alias Color = LibNCurses::Color struct ColorPair def initialize(@id : Int32) end - def init(fg : Color, bg : Color) - if LibNCurses.init_pair(@id, fg.value, bg.value) == LibNCurses::Result::ERR - raise "ncurses failure: init_pair" + def init(fg : Color | ColorDefault, bg : Color | ColorDefault) + fg = if fg.is_a?(Color) + fg.value + else + -1 + end + bg = if bg.is_a?(Color) + bg.value + else + -1 + end + if LibNCurses.init_pair(@id, fg, bg) == LibNCurses::Result::ERR + raise "ncurses failure: init_pair, #{@id}, #{fg}, #{bg}" end self end