Update to modern project structure
Also, move progress tool into tests.
This commit is contained in:
@ -1,51 +0,0 @@
|
||||
include ../premake.make
|
||||
LDLIBS += -lboost_unit_test_framework
|
||||
|
||||
BIN := $(shell basename $$(pwd))
|
||||
|
||||
SRCS := $(notdir $(wildcard src/*.cpp))
|
||||
SRCS += $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp)))
|
||||
OBJS := $(SRCS:.cpp=.o)
|
||||
DEPS := $(SRCS:.cpp=.d)
|
||||
|
||||
BUILDDIR := build/intermediates/
|
||||
|
||||
CXX ?= g++
|
||||
RM := /bin/rm -rf
|
||||
INSTALL := /usr/bin/install -c
|
||||
|
||||
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -I../src
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -D DEBUG -O0
|
||||
CONFIG := debug
|
||||
else
|
||||
CXXFLAGS += -D NDEBUG -O3
|
||||
CONFIG := release
|
||||
endif
|
||||
OUTDIR := build/$(CONFIG)/
|
||||
|
||||
vpath %.cpp src ../src
|
||||
vpath %.d $(BUILDDIR)
|
||||
vpath %.o $(BUILDDIR)
|
||||
|
||||
.PHONY: all clean prebuild
|
||||
|
||||
all: prebuild $(OUTDIR)$(BIN)
|
||||
|
||||
prebuild:
|
||||
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
||||
|
||||
$(OUTDIR)$(BIN): $(OBJS) $(DEPS)
|
||||
$(CXX) $(addprefix $(BUILDDIR),$(OBJS)) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN)
|
||||
@ln -sf $(OUTDIR)$(BIN) $(BIN)
|
||||
|
||||
%.o: %.cpp %.d
|
||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
||||
@mv $@ $*.d $(BUILDDIR)
|
||||
|
||||
-include $(BUILDDIR)*.d
|
||||
|
||||
%.d: ;
|
||||
|
||||
clean:
|
||||
$(RM) build $(BIN)
|
1
tests/Makefile
Symbolic link
1
tests/Makefile
Symbolic link
@ -0,0 +1 @@
|
||||
../Makefile
|
6
tests/postmake.make
Normal file
6
tests/postmake.make
Normal file
@ -0,0 +1,6 @@
|
||||
$(BUILDDIR)/%.o: ../src/%.cpp
|
||||
ifeq ($(PRECOMPILE), 1)
|
||||
$(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
|
||||
else
|
||||
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
|
||||
endif
|
5
tests/premake.make
Normal file
5
tests/premake.make
Normal file
@ -0,0 +1,5 @@
|
||||
include ../premake.make
|
||||
LDLIBS += -lboost_unit_test_framework -lsccolor
|
||||
CXXFLAGS += -I../src
|
||||
SRCS := $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp)))
|
||||
PRODUCT := tool
|
1
tests/src/commit.inc
Normal file
1
tests/src/commit.inc
Normal file
@ -0,0 +1 @@
|
||||
const char* commit = "85a398ff3e70ceb2fd735cf40a90e97bdd36badb";
|
@ -1,8 +1,160 @@
|
||||
#define BOOST_TEST_MODULE My Test
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
#include <libscterm.hpp>
|
||||
#include <libsccolor.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(first_test)
|
||||
{
|
||||
BOOST_TEST(1 == 1);
|
||||
void show_rows_cols(const sc::term& t) {
|
||||
std::cout << t.rows() << " rows, " << t.cols() << " cols\n";
|
||||
}
|
||||
|
||||
void show_progress(const sc::term& t) {
|
||||
struct timespec tm;
|
||||
tm.tv_nsec = 10000000;
|
||||
tm.tv_sec = 0;
|
||||
sc::cursor_hider ch {&std::cerr};
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
t.progress(12, "progress bar", i, 1000);
|
||||
nanosleep(&tm, nullptr);
|
||||
}
|
||||
std::cerr << sc::io::clear_line(t);
|
||||
std::cerr << "progress bar done.";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void show_hue_bar(int top) {
|
||||
int r = top;
|
||||
int g = 0;
|
||||
int b = 0;
|
||||
// red -> yellow
|
||||
while (g <= top) {
|
||||
std::cerr << sc::io::rgbb(r, g++, b) << ' ';
|
||||
}
|
||||
g = top;
|
||||
// yellow -> green
|
||||
while (r >= 0) {
|
||||
std::cerr << sc::io::rgbb(r--, g, b) << ' ';
|
||||
}
|
||||
r = 0;
|
||||
// green -> cyan
|
||||
while (b < top) {
|
||||
std::cerr << sc::io::rgbb(r, g, b++) << ' ';
|
||||
}
|
||||
b = top;
|
||||
// cyan -> blue
|
||||
while (g >= 0) {
|
||||
std::cerr << sc::io::rgbb(r, g--, b) << ' ';
|
||||
}
|
||||
g = 0;
|
||||
// blue -> magenta
|
||||
while (r <= top) {
|
||||
std::cerr << sc::io::rgbb(r++, g, b) << ' ';
|
||||
}
|
||||
r = top;
|
||||
// magenta -> red
|
||||
while (b >= 0) {
|
||||
std::cerr << sc::io::rgbb(r, g, b--) << ' ';
|
||||
}
|
||||
std::cerr << sc::io::reset << std::endl;
|
||||
}
|
||||
|
||||
void show_hue_bars() {
|
||||
for (int top = 1; top < 6; ++top) {
|
||||
show_hue_bar(top);
|
||||
}
|
||||
}
|
||||
|
||||
void show_grayscale_bar() {
|
||||
for (int i = 0; i < 23; ++i) {
|
||||
std::cerr << sc::io::grayb(i) << ' ';
|
||||
}
|
||||
std::cerr << sc::io::reset << std::endl;
|
||||
}
|
||||
|
||||
void show_words() {
|
||||
std::cout << sc::io::redf << " red ";
|
||||
std::cout << sc::io::greenf << " green ";
|
||||
std::cout << sc::io::bluef << " blue ";
|
||||
std::cout << sc::io::cyanf << " cyan ";
|
||||
std::cout << sc::io::magentaf << " magenta ";
|
||||
std::cout << sc::io::yellowf << " yellow ";
|
||||
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
||||
std::cout << sc::io::reset << std::endl;
|
||||
std::cout << sc::io::blackf;
|
||||
std::cout << sc::io::redb << " red ";
|
||||
std::cout << sc::io::greenb << " green ";
|
||||
std::cout << sc::io::blueb << " blue ";
|
||||
std::cout << sc::io::cyanb << " cyan ";
|
||||
std::cout << sc::io::magentab << " magenta ";
|
||||
std::cout << sc::io::yellowb << " yellow ";
|
||||
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
||||
std::cout << sc::io::reset << std::endl;
|
||||
std::cout << sc::io::bold;
|
||||
std::cout << sc::io::redf << " red ";
|
||||
std::cout << sc::io::greenf << " green ";
|
||||
std::cout << sc::io::bluef << " blue ";
|
||||
std::cout << sc::io::cyanf << " cyan ";
|
||||
std::cout << sc::io::magentaf << " magenta ";
|
||||
std::cout << sc::io::yellowf << " yellow ";
|
||||
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
||||
std::cout << sc::io::reset << std::endl;
|
||||
std::cout << sc::io::blackf << sc::io::bold;
|
||||
std::cout << sc::io::redb << " red ";
|
||||
std::cout << sc::io::greenb << " green ";
|
||||
std::cout << sc::io::blueb << " blue ";
|
||||
std::cout << sc::io::cyanb << " cyan ";
|
||||
std::cout << sc::io::magentab << " magenta ";
|
||||
std::cout << sc::io::yellowb << " yellow ";
|
||||
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
||||
std::cout << sc::io::reset << std::endl;
|
||||
std::cout << sc::io::bold << "bold " << sc::io::reset;
|
||||
std::cout << sc::io::italic << "italic " << sc::io::reset;
|
||||
std::cout << sc::io::underline << "underline" << sc::io::reset << ' ';
|
||||
std::cout << sc::io::strikethru << "strike thru" << sc::io::reset << ' ';
|
||||
std::cout << sc::io::overline << "overline" << sc::io::reset << ' ';
|
||||
std::cout << sc::io::reverse << "reverse" << sc::io::reset << ' ';
|
||||
std::cout << sc::io::blinkslow << "slow-blink" << sc::io::reset << ' ';
|
||||
std::cout << sc::io::blinkfast << "fast-blink" << sc::io::reset;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void show_truecolor(const sc::term& t) {
|
||||
// check for true color support
|
||||
char* support = getenv("COLORTERM");
|
||||
if (!support || support[0] == '\0') {
|
||||
std::cerr << "this terminal has no true color support\n";
|
||||
return;
|
||||
}
|
||||
const char* lhb = u8"\u2584"; // lower half block
|
||||
const double sat = 1.0;
|
||||
for (double bri = 0; bri < 1; bri += 0.2) {
|
||||
for (double hue = 0; hue < 359; hue += 360.0 / t.cols()) {
|
||||
HSB hsbb = {hue, sat, bri};
|
||||
Color bg {hsbb};
|
||||
RGB rgbb = RGB(bg);
|
||||
HSB hsbf = {hue, sat, bri + 0.1};
|
||||
Color fg {hsbf};
|
||||
RGB rgbf = RGB(fg);
|
||||
std::cerr << sc::io::truecolorb(rgbb.r * 255, rgbb.g * 255, rgbb.b * 255);
|
||||
std::cerr << sc::io::truecolorf(rgbf.r * 255, rgbf.g * 255, rgbf.b * 255);
|
||||
std::cerr << lhb;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
sc::term term {STDERR_FILENO};
|
||||
show_rows_cols(term);
|
||||
show_grayscale_bar();
|
||||
show_hue_bars();
|
||||
show_words();
|
||||
show_truecolor(term);
|
||||
show_progress(term);
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << sc::io::reset << ex.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
1
tests/src/precomp.hpp
Symbolic link
1
tests/src/precomp.hpp
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/precomp.hpp
|
1
tests/src/version.inc
Normal file
1
tests/src/version.inc
Normal file
@ -0,0 +1 @@
|
||||
const char* version = "1.3.0";
|
Reference in New Issue
Block a user