Compare commits
14 Commits
bc881fcdbd
...
main
Author | SHA1 | Date | |
---|---|---|---|
80142e97b3 | |||
2e58983526 | |||
c90fcf68b5 | |||
bf48bc3565 | |||
aad373a5b5 | |||
d6ac23e5ae | |||
dd25a925c1 | |||
6af5a27f55 | |||
aaba558d00 | |||
c595095fbe | |||
65c8c9fc3a | |||
385e8fa772 | |||
c8f9efbb86 | |||
17017f1207 |
5
Makefile
5
Makefile
@ -53,7 +53,7 @@ BIN := $(OUTDIR)/$(PROJ)
|
|||||||
SRCS += $(notdir $(wildcard src/*.cpp))
|
SRCS += $(notdir $(wildcard src/*.cpp))
|
||||||
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
||||||
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
|
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
|
||||||
HDRS ?= $(wildcard src/*.hpp)
|
HDRS ?= $(filter-out src/precomp.hpp, $(wildcard src/*.hpp))
|
||||||
MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*))
|
MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*))
|
||||||
|
|
||||||
# if project supports plugins, link to libdl where needed
|
# if project supports plugins, link to libdl where needed
|
||||||
@ -126,7 +126,8 @@ else
|
|||||||
$(OUTDIR)/$(REALNAME): $(OBJS)
|
$(OUTDIR)/$(REALNAME): $(OBJS)
|
||||||
endif
|
endif
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -install_name $(LIBDIR)/$(REALNAME) \
|
||||||
|
-current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
else ifeq ($(UNAME_S),OpenBSD)
|
else ifeq ($(UNAME_S),OpenBSD)
|
||||||
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
else ifeq ($(UNAME_S),Linux)
|
else ifeq ($(UNAME_S),Linux)
|
||||||
|
@ -26,5 +26,9 @@ In progress. For now, please consult the library header at
|
|||||||
|
|
||||||
## Test
|
## Test
|
||||||
|
|
||||||
Clone, build, and run the [progress](https://git.bobpolis.com/bob/progress/)
|
`make test`
|
||||||
tool.
|
|
||||||
|
will run a tool showcasing most of the possibilities. This tool was formerly a
|
||||||
|
separate project: `progress`, still [available on this
|
||||||
|
server](https://git.bobpolis.com/bob/progress/) for its history.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ PRODUCT := lib
|
|||||||
|
|
||||||
# Single source of truth for version.
|
# Single source of truth for version.
|
||||||
MAJOR := 1
|
MAJOR := 1
|
||||||
MINOR := 3
|
MINOR := 6
|
||||||
PATCH := 0
|
PATCH := 0
|
||||||
|
|
||||||
# Specify desired C++ standard for this project.
|
# Specify desired C++ standard for this project.
|
||||||
|
@ -46,6 +46,12 @@ std::ostream& sc::io::show_cursor(std::ostream& out) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& sc::io::clear_screen(std::ostream& out) {
|
||||||
|
if (should_color(out))
|
||||||
|
out << "\x1b" << 'c';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& sc::io::reset(std::ostream& out) {
|
std::ostream& sc::io::reset(std::ostream& out) {
|
||||||
if (should_color(out))
|
if (should_color(out))
|
||||||
out << "\x1b[m";
|
out << "\x1b[m";
|
||||||
|
@ -11,6 +11,7 @@ namespace sc {
|
|||||||
std::ostream& hide_cursor(std::ostream& out);
|
std::ostream& hide_cursor(std::ostream& out);
|
||||||
std::ostream& show_cursor(std::ostream& out);
|
std::ostream& show_cursor(std::ostream& out);
|
||||||
|
|
||||||
|
std::ostream& clear_screen(std::ostream& out);
|
||||||
std::ostream& reset(std::ostream& out);
|
std::ostream& reset(std::ostream& out);
|
||||||
|
|
||||||
std::ostream& bold(std::ostream& out);
|
std::ostream& bold(std::ostream& out);
|
||||||
|
@ -34,6 +34,10 @@ void term::progress(int prefixlen,
|
|||||||
double cur,
|
double cur,
|
||||||
double total) const
|
double total) const
|
||||||
{
|
{
|
||||||
|
progress(prefixlen, prefix, cur / total);
|
||||||
|
}
|
||||||
|
|
||||||
|
void term::progress(int prefixlen, const std::string& prefix, double fraction) const {
|
||||||
if (!_isatty) return;
|
if (!_isatty) return;
|
||||||
|
|
||||||
// use unicode to make nice bar
|
// use unicode to make nice bar
|
||||||
@ -41,12 +45,12 @@ void term::progress(int prefixlen,
|
|||||||
u8"\u258F", u8"\u258E", u8"\u258D", u8"\u258C",
|
u8"\u258F", u8"\u258E", u8"\u258D", u8"\u258C",
|
||||||
u8"\u258B", u8"\u258A", u8"\u2589", u8"\u2588"
|
u8"\u258B", u8"\u258A", u8"\u2589", u8"\u2588"
|
||||||
};
|
};
|
||||||
if (cur > total) cur = total;
|
if (fraction > 1) fraction = 1.0;
|
||||||
int perclen = 5;
|
int perclen = 5;
|
||||||
int barwidth = cols() - perclen - prefixlen - 1;
|
int barwidth = cols() - perclen - prefixlen - 1;
|
||||||
int maxsteps = barwidth * 8;
|
int maxsteps = barwidth * 8;
|
||||||
int steps = round(cur * maxsteps / total);
|
int steps = round(fraction * maxsteps);
|
||||||
int perc = round(100 * cur / total);
|
int perc = round(100 * fraction);
|
||||||
int fill_len = barwidth - steps / 8;
|
int fill_len = barwidth - steps / 8;
|
||||||
*_out << '\r' << std::setw(prefixlen) << prefix.substr(0, prefixlen) << ' ' << io::grayf(8);
|
*_out << '\r' << std::setw(prefixlen) << prefix.substr(0, prefixlen) << ' ' << io::grayf(8);
|
||||||
for (int i = 0; i < steps / 8; ++i) {
|
for (int i = 0; i < steps / 8; ++i) {
|
||||||
|
@ -25,6 +25,10 @@ namespace sc {
|
|||||||
double cur,
|
double cur,
|
||||||
double total) const;
|
double total) const;
|
||||||
|
|
||||||
|
void progress(int prefixlen,
|
||||||
|
const std::string& prefix,
|
||||||
|
double fraction) const;
|
||||||
|
|
||||||
static bool has_truecolor();
|
static bool has_truecolor();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include "version.inc"
|
|
||||||
#include "commit.inc"
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
std::string libscterm_version() {
|
std::string libscterm_version() {
|
||||||
|
#include "version.inc"
|
||||||
|
#include "commit.inc"
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "libscterm version " << version;
|
oss << "libscterm version " << version;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef VERSION_H_
|
#ifndef _LIBSCTERM_VERSION_H_
|
||||||
#define VERSION_H_
|
#define _LIBSCTERM_VERSION_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string libscterm_version();
|
std::string libscterm_version();
|
||||||
|
|
||||||
#endif // VERSION_H_
|
#endif // _LIBSCTERM_VERSION_H_
|
||||||
|
@ -1 +0,0 @@
|
|||||||
const char* version = "1.3.0";
|
|
@ -145,6 +145,7 @@ void show_truecolor(const sc::term& t) {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
|
std::cout << "using " << libscterm_version() << '\n';
|
||||||
sc::term term {STDERR_FILENO};
|
sc::term term {STDERR_FILENO};
|
||||||
show_rows_cols(term);
|
show_rows_cols(term);
|
||||||
show_grayscale_bar();
|
show_grayscale_bar();
|
||||||
|
@ -1 +0,0 @@
|
|||||||
const char* version = "1.3.0";
|
|
Reference in New Issue
Block a user