Skip to content

Commit

Permalink
Merge pull request #16 from HsuanTingLu/release/v1.4.0
Browse files Browse the repository at this point in the history
Merge branch 'release/v1.4.0'
  • Loading branch information
moshiba authored Oct 7, 2020
2 parents af80793 + 93f0d1d commit 5a0f664
Show file tree
Hide file tree
Showing 24 changed files with 190 additions and 1,140 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Build system
.clangd/
## Buck
.buckd/
buck-out/
## CMake
build/

# Editors
## SourceTrail
.sourcetrail/
## vscode
.vscode/
## Clangd
.clangd/

# Prerequisites
*.d
Expand Down
19 changes: 0 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
#
# CMake configs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope tha it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

# Most widely used distributions have cmake 3.5 or greater available as of March
# 2019.

Expand Down
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions aesc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
#
# Wrap some CSI escape codes with string streams
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope tha it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

add_library(aesc) # Depends on option:BUILD_SHARED_LIBS

target_sources(aesc
Expand Down Expand Up @@ -80,7 +61,7 @@ if(ENABLE_UBSAN_SYMBOLIZED_OUTPUTS)
if(NOT llvm_symbolizer_path STREQUAL "llvm_symbolizer_path-NOTFOUND")
message(VERBOSE "\"llvm-symbolizer\"\t program path: ${llvm_symbolizer_path}")
set(ENV{UBSAN_SYMBOLIZER_PATH} "${llvm_symbolizer_path}")
set(ENV{UBSAN_OPTIONS} "print_stacktrace=1")
set(ENV{UBSAN_OPTIONS} "print_stacktrace=1")
else()
message(WARNING "llvm-symbolizer not found")
endif()
Expand All @@ -97,7 +78,7 @@ target_compile_options(aesc
$<$<BOOL:${ENABLE_UBSAN}>:-fsanitize=undefined;-g;-fno-omit-frame-pointer>
$<$<AND:$<BOOL:${ENABLE_UBSAN}>,$<CONFIG:RelWithDebInfo>>:-fsanitize=-fsanitize-minimal-runtime>

-march=native # FIXME: be cautious
# -march=native # FIXME: be cautious
-Wall
-Wextra
-pedantic
Expand Down
20 changes: 0 additions & 20 deletions aesc/aesc.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/*
* Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
*
* Wrap some terminal control sequences with string streams
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope tha it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#ifndef AESC_AESC_HPP_
#define AESC_AESC_HPP_

Expand Down
19 changes: 0 additions & 19 deletions aesc/control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
#
# Wrap some CSI escape codes with string streams
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope tha it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

target_sources(aesc
PRIVATE
${PROJECT_SOURCE_DIR}/aesc/control/cursor.hpp
Expand Down
108 changes: 33 additions & 75 deletions aesc/control/cursor.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
/*
* Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
*
* Wraps cursor control sequences
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope tha it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "aesc/control/cursor.hpp"

#include "aesc/internal/sequences.hpp"

namespace aesc { // Ansi Escape Terminal

inline namespace cursor {

namespace internal {

namespace {
constexpr const char* up_expr = "A";
constexpr const char* down_expr = "B";
Expand All @@ -38,76 +22,50 @@ constexpr const char* save_cursor_expr = "s";
constexpr const char* restore_cursor_expr = "u";
} // anonymous namespace

manipulator::smanip up(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << up_expr;
return s;
};
return {h, n};
auto up(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << up_expr;
return s;
}

manipulator::smanip down(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << down_expr;
return s;
};
return {h, n};
}
auto down(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << down_expr;
return s;
};

manipulator::smanip forward(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << forward_expr;
return s;
};
return {h, n};
}
auto forward(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << forward_expr;
return s;
};

manipulator::smanip back(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << back_expr;
return s;
};
return {h, n};
}
auto back(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << back_expr;
return s;
};

manipulator::smanip next_line(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << next_line_expr;
return s;
};
return {h, n};
}
auto next_line(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << next_line_expr;
return s;
};

manipulator::smanip prev_line(const int n) {
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << prev_line_expr;
return s;
};
return {h, n};
}
auto prev_line(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << prev_line_expr;
return s;
};

manipulator::smanip EL(clear n) {
/*
* n = 0: clear from cursor to end of screen
* n = 1: clear from cursor to beginning of the screen
* n = 2: clear entire line
*
* Cursor position does NOT change
*/
auto h = [](std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << erase_in_line_expr;
return s;
};
return {h, static_cast<int>(n)};
}
auto EL(std::ostream& s, const int x) -> std::ostream& {
s << CSI_expr << x << erase_in_line_expr;
return s;
};

} // namespace internal

std::ostream& save_pos(std::ostream& stream) {
stream << CSI_expr << save_cursor_expr;
stream << CSI_expr << internal::save_cursor_expr;
return stream;
}

std::ostream& restore_pos(std::ostream& stream) {
stream << CSI_expr << restore_cursor_expr;
stream << CSI_expr << internal::restore_cursor_expr;
return stream;
}

Expand Down
78 changes: 55 additions & 23 deletions aesc/control/cursor.hpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,80 @@
/*
* Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
*
* Wraps cursor control sequences
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope tha it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#ifndef AESC_CONTROL_CURSOR_HPP_
#define AESC_CONTROL_CURSOR_HPP_

#include "aesc/internal/manipulator.hpp"
#include "aesc/internal/sequences.hpp"

namespace aesc { // Ansi Escape Terminal

inline namespace cursor { // Cursor controls

enum class clear : int { to_end = 0, to_beginning = 1, entire = 2 };

manipulator::smanip up(const int n = 1);
manipulator::smanip down(const int n = 1);
manipulator::smanip forward(const int n = 1);
manipulator::smanip back(const int n = 1);
namespace internal {

std::ostream& up(std::ostream& s, int x);

std::ostream& down(std::ostream& s, int x);

std::ostream& forward(std::ostream& s, int x);

std::ostream& back(std::ostream& s, int x);

std::ostream& next_line(std::ostream& s, int x);

std::ostream& prev_line(std::ostream& s, int x);

std::ostream& EL(std::ostream& s, int x);

} // namespace internal

constexpr manipulator::smanip up(int n = 1) {
return manipulator::smanip(internal::up, n);
}

constexpr manipulator::smanip down(int n = 1) {
return manipulator::smanip(internal::down, n);
}

constexpr manipulator::smanip forward(int n = 1) {
return manipulator::smanip(internal::forward, n);
}

constexpr manipulator::smanip back(int n = 1) {
return manipulator::smanip(internal::back, n);
}

// moves to beginning of next line
manipulator::smanip next_line(const int n = 1);
constexpr manipulator::smanip next_line(int n = 1) {
return manipulator::smanip(internal::next_line, n);
}

// moves to beginning of previous line
manipulator::smanip prev_line(const int n = 1);
constexpr manipulator::smanip prev_line(int n = 1) {
return manipulator::smanip(internal::prev_line, n);
}

// erases from cursor to EOL if 0
// clear from cursor to beginning if 1
// clears entire line if 2
manipulator::smanip EL(const clear n);
constexpr manipulator::smanip EL(clear n) {
/*
* n = 0: clear from cursor to end of screen
* n = 1: clear from cursor to beginning of the screen
* n = 2: clear entire line
*
* Cursor position does NOT change
*/
return manipulator::smanip(internal::EL, static_cast<int>(n));
}

// Saves cursor position and state
std::ostream& save_pos(std::ostream& stream);

// Restores cursor position and state
std::ostream& restore_pos(std::ostream& stream);

Expand Down
19 changes: 0 additions & 19 deletions aesc/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#
# Copyright (C) 2019 Hsuan-Ting Lu <[email protected]>
#
# Wrap some CSI escape codes with string streams
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope tha it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

target_sources(aesc
PRIVATE
${PROJECT_SOURCE_DIR}/aesc/internal/manipulator.hpp
Expand Down
Loading

0 comments on commit 5a0f664

Please sign in to comment.