From 7b97e389a05e42a9f0b0897dffa0f4d1eeefbc60 Mon Sep 17 00:00:00 2001 From: Niklas Loeser Date: Mon, 27 Apr 2020 16:17:53 +0200 Subject: [PATCH] added default color support and updated the color example --- README.md | 1 + examples/colors.cr | 1 + shard.yml | 3 ++- src/lib_ncurses.cr | 2 ++ src/ncurses.cr | 12 ++++++++++++ src/ncurses/version.cr | 2 +- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d610615..27cf79e 100644 --- a/README.md +++ b/README.md @@ -79,3 +79,4 @@ $ crystal run examples/scroll.cr - (https://github.com/jreinert) Joakim Reinert - creator, maintainer - (https://github.com/SamualLB) Samual Black - maintainer +- (https://github.com/data-niklas) Niklas Loeser - contributor diff --git a/examples/colors.cr b/examples/colors.cr index ad10696..0dbf94f 100644 --- a/examples/colors.cr +++ b/examples/colors.cr @@ -10,6 +10,7 @@ unless NCurses.has_colors? exit(1) end +NCurses.default_colors NCurses.start_color NCurses.init_color_pair(1, NCurses::Color::Red, NCurses::Color::Green) diff --git a/shard.yml b/shard.yml index ffdb783..fb219f7 100644 --- a/shard.yml +++ b/shard.yml @@ -1,9 +1,10 @@ name: ncurses -version: 0.0.7 +version: 0.0.8 authors: - Joakim Reinert - Samual Black + - Niklas Loeser crystal: 0.31.1 diff --git a/src/lib_ncurses.cr b/src/lib_ncurses.cr index 80cb9ae..82bc65b 100644 --- a/src/lib_ncurses.cr +++ b/src/lib_ncurses.cr @@ -11,6 +11,7 @@ lib LibNCurses # Used to color output by creating color pairs enum Color : LibC::Short + Default = -1 Black = 0 Red = 1 Green = 2 @@ -109,6 +110,7 @@ lib LibNCurses fun can_change_color : Bool fun init_color(slot : LibC::Short, red : LibC::Short, green : LibC::Short, blue : LibC::Short) : LibC::Int fun init_pair(slot : LibC::Short, foreground : LibC::Short, background : LibC::Short) : LibC::Int + fun use_default_colors() # Output options fun clearok(window : Window, bf : Bool) : LibC::Int diff --git a/src/ncurses.cr b/src/ncurses.cr index dbb3b0d..4d933ae 100644 --- a/src/ncurses.cr +++ b/src/ncurses.cr @@ -232,6 +232,18 @@ module NCurses raise "init_pair error" if LibNCurses.init_pair(slot.to_i16, foreground.to_i16, background.to_i16) == ERR end + + # Use the default terminal colors + # Takes no arguments and has no result + def use_default_colors + LibNCurses.use_default_colors + end + + # Alias for use_default_colors + def default_colors + use_default_colors + end + # # ## Other # diff --git a/src/ncurses/version.cr b/src/ncurses/version.cr index 265f8d0..bb57ecb 100644 --- a/src/ncurses/version.cr +++ b/src/ncurses/version.cr @@ -1,3 +1,3 @@ module NCurses - VERSION = "0.0.7" + VERSION = "0.0.8" end